I have an XSUB that returns a list of things like this:

void
foo()
    PPCODE:
    {
        EXTEND(SP, 2);
        PUSHs(sv_2mortal(newSViv(42)));
        PUSHs(sv_2mortal(newSVpvn("Forty-two", 9)));
        XSRETURN(2);
    }

It works fine as it is, but I though that the following might be a 
little easier on the eye:

void
foo()
    PPCODE:
    {
        EXTEND(SP, 2);
        PUSHi(42);
        PUSHp("Forty-two", 9);
        XSRETURN(2);
    }

However, when I try to build the latter I get this compiler error:

'targ' : undeclared identifier

Having hunted around a bit for examples of other things using PUSHi() 
and PUSHp(), I found that the constant() XSUB in a typical 
"const-xs.inc" file produed by ExtUtils::Constants contains a PREINIT: 
section like this:

    PREINIT:
#ifdef dXSTARG
    dXSTARG; /* Faster if we have it.  */
#else
    dTARGET;
#endif

and sure enough, if I add that to my XSUB then it builds and works OK 
once more.

Why is this necessary, and how was I supposed to know it?  Neither 
dTARGET nor dXSTARG seem to be documented anywhere, and there is no 
mention of the need for such things in the documentation of PUSHi() etc.

Aside from all that, is the PUSHi()/PUSHp() example above OK?  It 
doesn't appear to leak, but I'm always wary of removing calls to 
sv_2mortal().  I seem to recall that the "targ" stuff has a different 
"mortality" scheme relating to the OP tree, but I'm not sure.

- Steve



------------------------------------------------
Radan Computational Ltd.

The information contained in this message and any files transmitted with it are 
confidential and intended for the addressee(s) only.  If you have received this 
message in error or there are any problems, please notify the sender immediately.  The 
unauthorized use, disclosure, copying or alteration of this message is strictly 
forbidden.  Note that any views or opinions presented in this email are solely those 
of the author and do not necessarily represent those of Radan Computational Ltd.  The 
recipient(s) of this message should check it and any attached files for viruses: Radan 
Computational will accept no liability for any damage caused by any virus transmitted 
by this email.

Reply via email to