good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
Re: Perl XS: garbage-collecting my malloc'd bufferby Elian (Parson) |
on Mar 03, 2003 at 17:07 UTC ( [id://240073]=note: print w/replies, xml ) | Need Help?? |
This is almost the right way to do it. Altering parameters isn't a particularly perlish thing to do--it's a habit many people have because it's the only way to return multiple values from languages with more limited return semantics, such as C.
What you should do instead is switch from CODE to PPCODE and XPUSH() both the status and the return SV (which you built almost correctly--calling sv_2mortal on a value in the input list is dicey, but works correctly for return values) so that your function returns two values rather than one. In general, you're on the right track--if you need to return a string, return an SV. (I'd go so far as to say always return an SV, but many folks would disagree) Anyway, the code probably ought to look like:
In Section
Seekers of Perl Wisdom
|
|