Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
See perlguts.pod for more details about the [adp]THX_? macros, but basically, you're using a perl compiled for multiplicility/threading, and in those perls, most perl functions (including SvPV()) expect to take an extra first argument, called my_perl, which is a pointer to the current perl interpreter.

The idea is that on threaded perls, these macros typically expand as follows:

aTHX my_perl aTHX_ my_perl, pTHX PerlInterpreter* my_perl pTHX_ PerlInterpreter* my_perl, dTHX PerlInterpreter* my_perl = something_that_retrieves_the_current_perl();
while on unthreaded perls they expand to null strings.

You typically declare any function as expecting an interpreter as the first arg:

void foo(pTHX_ SV * sv) { ... }
and invoke it as
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


In reply to Re^5: SvPV Segmentation Fault by dave_the_m
in thread SvPV Segmentation Fault by adler187

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2024-04-23 12:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found