Confirmed, the library I am wrapping runs in a separate thread and runs its callbacks from there. "context" is a good keyword and led me to dTHX and PERL_SET_CONTEXT. I haven't found a good example of using these yet. Adding dTHX did get me past dSP, but I die consistently in ENTER now.

On 2/10/2010 10:48 PM, muppet wrote:

On Feb 10, 2010, at 7:32 PM, Private and Confidential wrote:

I've written a callback function for an XS module designed to call a perl 
function when invoked.

If I call the function directly, from within the C code, it runs through 
completely as expected.

If its invoked as a callback from the library I am wrapping, it does immediately at 
"dSP;" i.e. SV **sp = PL_stack_sp;

Specifically PL_stack_sp seems to cause SEGV when touched - I can't even see 
the value, printf dies also.

I can't find anything similar discussed anywhere, does anyone have an idea what 
might be happening?

Are there multiple threads involved?

If you're cold-calling from C code, you probably need to set up the context 
properly.  This should be mentioned in the perlguts, perlxs, and perlxstut 
manpages.

If you're coming from another thread, then you have considerably more work to 
do to get the context set up safely for invoking code in the interpreter.



--
If the monkey could type one keystroke every nanosecond, the expected waiting 
time until the monkey types out Hamlet is so long that the estimated age of the 
universe is insignificant by comparison ... this is not a practical method for 
writing plays.
   -- Gian-Carlo Rota



Reply via email to