Actually, SvPV_nolen() is safer than SvPVX(); SvPVX() gives you a pointer to the "PV" (the scalar's string value) even if the scalar doesn't have a string value while SvPV_nolen() will force the scalar to get a string value if it doesn't have one already.
The problem is that the size of the buffer is specified but the length of the string stored in that buffer is never set. I'd change your XS-code-for-cargo-culting, (:, to:
int bufsize= 83; SV* svBuf= newSV( bufsize ); char* pBuf= SvPV_nolen( svBuf ); ...( ..., pBuf, bufsize, ... ); SvCUR_set( svBuf, length_of_data_written );
where "length_of_data_written" might be variable, such as the return value from the function that stuffs characters into pBuf.
- tye
In reply to Re^3: XS efficient copy (SvCUR_set)
by tye
in thread XS efficient copy
by TheDauthi
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |