in reply to Re^2: XS efficient copy
in thread XS efficient copy
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: XS efficient copy (SvCUR_set)
by creamygoodness (Curate) on Apr 07, 2006 at 03:31 UTC | |
by tye (Sage) on Apr 07, 2006 at 06:46 UTC | |
by creamygoodness (Curate) on Apr 07, 2006 at 18:36 UTC | |
by TheDauthi (Sexton) on Apr 07, 2006 at 20:36 UTC | |
by creamygoodness (Curate) on Apr 09, 2006 at 15:35 UTC |