Issac Goldstand wrote:

>[snip]
>
>  
>
>>>However, it seems that I've taken my eye off the ball with all these
>>>compilation problems and concerns over memory leaks:  the
>>>PUSHi()/PUSHp() version of the XSUB above doesn't actually work properly!
>>>
>>>Instead of returning (42, "Forty-two"), it returns ("Forty-two",
>>>"Forty-two").  In general, if I use PUSHi() or PUSHp() to push N things
>>>onto the stack and then XSRETURN(N) then I seem to get N copies of the
>>>last return value that I pushed.
>>>      
>>>
>>Only one TARG SV for the op. If you look at macros in pp.h
>>you will see
>>
>>PUSHi(i)   STMT_START { sv_setiv(TARG, (IV)(i)); PUSHTARG; } STMT_END
>>
>>So it sets the one SV to the value, and then pushes the one SV.
>>
>>So it seems that PUSHi() et. al. are not suitable for list returns.
>>
>>    
>>
>
>Could you clarify that a bit?  Why not?
>
Well, if you call PUSHi() twice then all you're doing is setting the 
value of TARG, pushing a pointer to it onto the stack, then changing the 
value of TARG and pushing another pointer to it onto the stack.  You end 
up with two pointers to the same SV (TARG) on the stack, so of course 
both return values are the same, namely, the last value that you set 
TARG to.

This is (as I belatedly discovered) documented in perlguts -- see the 
section entitled "Putting a C value on the Perl stack".

- 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