in reply to Re: [XS] sv_setpv change in behaviour with perl-5.42.0 and later
in thread [XS] sv_setpv change in behaviour with perl-5.42.0 and later
On perl 5.40.0 I could re-use that PV that I created in the demo and pass it to bar(), because its SvLEN is still guaranteed to be at least 60.void bar(unsigned char * buffer) { buffer[49] = 65; }
On perl-5.40.0 and earlier, the final Devel::Peek::Dump reveals exactly what I expect:use strict; use warnings; use Devel::Peek; use Inline C =><<'EOC'; void foo(SV * buffer) { char *data = "Hello there"; sv_setpv(buffer, data); } void bar(unsigned char * buffer) { buffer[49] = 65; } void _set_CUR(SV * buffer, int bytes) { SvCUR_set(buffer, bytes); } EOC my $buffer = 'z' x 60; Dump $buffer; foo($buffer); Dump $buffer; bar($buffer); _set_CUR($buffer, 60); # Ensure that Devel::Peek::Dump will display al +l 60 bytes. Dump $buffer;
On perl-5.42.0, the final Dump appears as:SV = PV(0x254ba8dbf08) at 0x254ba920660 REFCNT = 1 FLAGS = (POK,pPOK) PV = 0x254bce10dc8 "Hello there\x00zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz +zzzzAzzzzzzzzzz"\0 CUR = 60 LEN = 62
(The 'A' at index 49 can be seen if you look closely.)SV = PV(0x224fe4c0aa0) at 0x224fe4f4cd0 REFCNT = 1 FLAGS = (POK,pPOK) PV = 0x22480c0e170 "Hello there\x00\x00\x00\x00\x00\x00\x00\x00\x00\ +x00\x00\x00\x00\r\x8B7\xBC\x00\xF8\x00\x88\xC0\x82\x9F\x80$\x02\x00\x +00\x00\x00\x00\x00\x00\x00\x00\x00\x10A\x8D\x80$\x02\x00\x00\x00\xB5K +\xFE" CUR = 60 LEN = 16
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: [XS] sv_setpv change in behaviour with perl-5.42.0 and later
by ikegami (Patriarch) on Jan 29, 2026 at 02:53 UTC | |
by syphilis (Archbishop) on Jan 29, 2026 at 06:59 UTC | |
by dave_the_m (Monsignor) on Jan 29, 2026 at 13:23 UTC | |
by syphilis (Archbishop) on Jan 30, 2026 at 05:23 UTC | |
by ikegami (Patriarch) on Jan 30, 2026 at 20:36 UTC | |
by ikegami (Patriarch) on Jan 29, 2026 at 15:45 UTC | |
by Anonymous Monk on Jan 29, 2026 at 22:30 UTC | |
by ikegami (Patriarch) on Jan 30, 2026 at 19:04 UTC |