On Thu, Oct 30, 2003 at 08:21:38AM +0000 Nick Ing-Simmons wrote:

> Steve Hay <[EMAIL PROTECTED]> writes:
> >What's the best way to have an XSUB return a string (char *) when the 
> >caller doesn't know how big that string will be?
> 
> At a mortal string SV:
> 
> void
> my_xsub()
> CODE:
>  {
>   ST(0) = sv_2mortal(newSVpv(string,strlen(string));
>   XSRETURN(1);
>  }
> 
> I like that style because as soon as you have created the SV
> you know perl has a copy and can cleanup. 
> 
> You should get the same effect via
> 
> char *
> my_xsub()
> CODE:
> {
>  RETVAL = string;
> }
> OUTPUT:
>  RETVAL

Is this certain that my_xsub() returns a mortal? When looking into the
generated C code, I see:

    {
    char *RETVAL;
    RETVAL = string;
    sv_setpv(TARG, RETVAL); XSprePUSH; PUSHTARG;
    }
    XSRETURN(1);

Is TARG treated as a mortal? I wasn't able to figure that out with a few
greps through the Perl source.

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval

Reply via email to