http://www.perlmonks.org?node_id=927986


in reply to Re^4: XS: EXTEND/mPUSHi
in thread XS: EXTEND/mPUSHi

but that still leaves me with the question of whether I should be resetting the stack to account for the single input parameter, or whether the EXTEND() takes care for that for me

No - as it stands, the first value that gets returned should be the supplied argument - at least that's what I'm finding. If you want to avoid that, then you need to reset the stack pointer or take some alternative measure.
Ike questions the validity of doing sp = mark though it's something that has been in the Inline test suite for the last few years, and has not produced any problems with the cpan-testers. Is there a better way of resetting the stack pointer ?
I think that, in this instance you could also just sp--; (update: or, more generally, sp -= items) before you EXTEND.

I can't actually find any code of mine that resets the stack pointer - I usually take a different approach such as just assigning to ST(0), ST(1), etc.

I also wonder if I shouldn't be passing in a reference to the an array and populating it directly, rather than assigning the returned stack to it?

I've benchmarked that for some huge arrays in the past ... and not detected any advantage in passing by reference (with Inline::C).

Cheers,
Rob