Hi,

On Windows 11, perl-5.42.0 and later, a string assignment (in XS) to an SV's PV buffer using sv_setpv can drastically reduce the value of SvLEN.

Demo:
use strict; use warnings; use Devel::Peek; use Inline C =><<'EOC'; void foo(SV * buffer) { char *data = "Hello there"; sv_setpv(buffer, data); } EOC my $buffer = 'z' x 60; Dump $buffer; foo($buffer); Dump $buffer;
Output, running on perl-5.42.0 and perl-5.43.7:
SV = PV(0x2352069fd80) at 0x235206db678 REFCNT = 1 FLAGS = (POK,IsCOW,pPOK) PV = 0x2352275d050 "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz +zzzzzzzzzzzz"\0 CUR = 60 LEN = 64 COW_REFCNT = 1 SV = PV(0x2352069fd80) at 0x235206db678 REFCNT = 1 FLAGS = (POK,pPOK) PV = 0x2352279a8a0 "Hello there"\0 CUR = 11 LEN = 16
What, if anything, should I deduce from the fact that LEN has been reduced from 64 to 16.
Has the size of the PV buffer actually been reduced ?

On perl-5.40.0 and earlier, when running the same script, LEN retains its original value (which is the behaviour that I expected) :
SV = PV(0x2076e35a3b0) at 0x2076e41b338 REFCNT = 1 FLAGS = (POK,pPOK) PV = 0x2077084ae90 "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz +zzzzzzzzzzzz"\0 CUR = 60 LEN = 62 SV = PV(0x2076e35a3b0) at 0x2076e41b338 REFCNT = 1 FLAGS = (POK,pPOK) PV = 0x2077084ae90 "Hello there"\0 CUR = 11 LEN = 62
Cheers,
Rob

In reply to [XS] sv_setpv change in behaviour with perl-5.42.0 and later by syphilis

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.