Jochen Stenzel <p...@jochen-stenzel.de> wrote:

> Hello,
>
> I am new to XS and started with an existing project. From what I read and
> understood in tutorials and perlapi so far, XPUSHs is a short way to put
> an SV on the stack and to make sure there is enough place for it - an
> alternative to use EXTEND and to assign the value directly to a stack
> position.
>
> So, when I found code like the following in a C function called as a
> callback by another C function which is invoked by an xsub:
>
>     dSP;
>     EXTEND (sp, result_nr);
>     sp[sp_pos] = sv_2mortal (sv);
>
> I thought it could be shortened to
>
>     dSP;
>     XPUSHs (sv_2mortal (sv));
>
> but was wrong.

I'm not very good at XS myself, but if you're trying to pass arguements
to a Perl subroutine, don't you need to brace the XPUSHs with PUSHMARK
and PUTBACK?

        PUSHMARK(SP);
        XPUSHs(sv_2mortal(sv));
        PUTBACK;

and you may also need to brace with SAVETMPS / FREETMPS so the mortals
are garbage collected.

  » http://perldoc.perl.org/perlcall.html#Passing-Parameters


-- 
Sébastien Aperghis-Tramoni

Close the world, txEn eht nepO.

Reply via email to