Steve Hay <[EMAIL PROTECTED]> writes: >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,
PUSHi et. al. are core perl utils and (most) perl ops have a TARG SV >and how was I supposed to know it? Well 'targ' : undeclared identifier seems to have pushed you in the direction. >Neither >dTARGET nor dXSTARG seem to be documented anywhere, dTARGET is an internals thing. dXSTARG didn't exist until "recently". >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(). It it doesn't leak or give "attempt to free ..." warnings it is probably okay. (Devel::Leak may help here.) >I seem to recall that the "targ" stuff has a different >"mortality" scheme relating to the OP tree, but I'm not sure. I haven't used them much myself. As I understand it the OP that does the XS call now has an SV associated with it (from the PAD?). This will be undef'ed on scope exit along with other my-ish SVs (I think). As such I think there may be issues if you recurse (that is obscure use of XS - but with Tk callbacks it happens a lot).