|P is for Practical|
Re^10: XS: EXTEND/mPUSHiby BrowserUk (Pope)
|on Sep 29, 2011 at 10:46 UTC||Need Help??|
The the XS wrappers generated by I::C:
Prior to calling the C-func, the stack is adjusted to account for the number of input parameters passed:
But this never has any affect because SP is a local copy of the real stack pointer. In order to 'remove' the passed parameters from the stack (inside the C-func) you have to call Inline_Stack_Reset; which translates to sp = mark;
Then after you've pushed your return parameters onto the stack, you have to remember to call Inline_Stack_Done; which translates to PUTBACK;, which translates to PL_stack_sp = sp;. Which updates the real stack pointer from tha local copy to account for the net effect of removing the input parameters and adding the output parameters.
But the generated XS wrapper already has code to take care of this, except it has been disabled by having been preceded with a(nother) return:
What we discussed above is that if PUTBACK was called after SP -= items: and before the C-sub is invoked, there would be no need to call Inline_Stack_Reset; within the C-sub, because that stack would have already been adjusted to account for the input parameters. And the Stack access (ST(0); xPUSHy() & Inline_Stack_Push() etc.) macros would still operate correctly.
And then, if the first return statement was removed from the wrapper sub, so that the currently unreached PUTBACK; was reached, then the real stack would again be updated this time reflecting whatever output parameters had been push onto the stack (if any), thereby removing the need for the Inline_Stack_done; macro.
In summary: The theory went that if the wrapper sub were generated as (discarding the extraneous stuff for clarity) :
Then Inline_Stack_Reset; & Inline_Stack_Done; become redundant for new code, and could be made noops for backward compatibility.
The fly in this ointment is that there are the XS macros POPx, which would no longer operate correctly if mixed into I::C.
I wouldn't consider this a loss as there are alternative and better ways of accessing the input stack, but I've no doubt that some of those p5p for who backward compatibility is sacrosanct would be up in arms.
Bottom line: Your 'do nothing' was probably the right call. Sorry for having suggested otherwise.
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.