in reply to Re^2: XS Prepending space to an SVs PV
in thread XS Prepending space to an SVs PV
I suspect you get traps because you substitute Perl's allocated memory with your own?
Allocating more place than needed for an SV is why SvGROW exists:
Then, reading further in perlguts gives all your required manipulations:Although Perl will automatically grow strings for you, if you need +to force Perl to allocate more memory for your SV, you can use the mac +ro SvGROW(SV*, STRLEN newlen)
Offsets Perl provides the function "sv_chop" to efficiently remove charact +ers from the beginning of a string; you give it an SV and a pointer to somewhere inside the PV, and it discards everything before the poi +nter. The efficiency comes by means of a little hack: instead of actuall +y removing the characters, "sv_chop" sets the flag "OOK" (offset OK) + to signal to other functions that the offset hack is in effect, and i +t puts the number of bytes chopped off into the IV field of the SV. It th +en moves the PV pointer (called "SvPVX") forward that many bytes, and adjusts "SvCUR" and "SvLEN".
|
|---|