You don't need to '\0'-terminate the buffer. Perl doesn't care about the '\0' when reading a string value since you specified a length and Perl will append a '\0' onto the end "just in case" after it copies it.
You could probably simplify the code slightly by using CODE: instead of PPCODE: (you are only ever returning one value) so that you just deal with RETVAL instead of manipulating the stack.
So it looks fine.
- tyeIn reply to Re^2: Perl XS: garbage-collecting my malloc'd buffer (fine)
by tye
in thread Perl XS: garbage-collecting my malloc'd buffer
by edan
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |