in reply to Re^4: SvPV Segmentation Fault
in thread SvPV Segmentation Fault
The idea is that on threaded perls, these macros typically expand as follows:
while on unthreaded perls they expand to null strings.aTHX my_perl aTHX_ my_perl, pTHX PerlInterpreter* my_perl pTHX_ PerlInterpreter* my_perl, dTHX PerlInterpreter* my_perl = something_that_retrieves_the_current_perl();
You typically declare any function as expecting an interpreter as the first arg:
and invoke it asvoid foo(pTHX_ SV * sv) { ... }
foo(aTHX_ some_sv);
Normally your XS sub will have been passed a my_perl arg, and you can pass this on down the chain of called subs using aTHX/pTHX. In those cases where this isn't possible, dTHX can be used within the declaration section of a function to recreate my_perl 'on the fly', but it's expensive:
void foo(SV * sv) { dTHX; ... }
All the above assumes that PERL_NO_GET_CONTEXT is defined in your source. If it isn't then aTHX is redefined to directly compute the interpreter address, like dTHX. This means everything 'just works' without messing with aTHX/pTHX, but is slow. Since you were getting compilation errors about missing my_perl, I'm assuming you must have had PERL_NO_GET_CONTEXT defined.
Dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: SvPV Segmentation Fault
by adler187 (Initiate) on Apr 25, 2012 at 23:20 UTC |