ikegami has asked for the wisdom of the Perl Monks concerning the following question:

I have the following cargo-culted code:

STATIC void croak_for_this_reason(pTHX_ ...) { dVAR; ... Perl_croak(aTHX_ ...); } croak_for_this_reason(aTHX_ ...);

Is Perl_croak(aTHX_ ...) the same as croak(...)?

Is dVAR; needed by aTHX?

I'm using a threaded build of Perl. I thought the whole "THX mess" was to support that, yet aTHX appears to be empty (no error if I omit it). What is THX for?


Update: I think I need this:

STATIC void croak_for_this_reason(pTHX_ ...) { ... Perl_croak(aTHX_ ...); } croak_for_this_reason(aTHX_ ...);

(but not dVAR;), and it which can be written as:

STATIC void croak_for_this_reason(pTHX_ ...) { #define croak_for_this_reason(...) croak_for_this_reason(aTHX_ ...) ... croak(...); } croak_for_this_reason(...);

Replies are listed 'Best First'.
Re: XS: THX questions
by ikegami (Patriarch) on Sep 16, 2011 at 21:20 UTC

    aha! The macro system doesn't work well for vararg functions, so Perl_croak(aTHX_ ...) is more efficient than croak(...).

    #define PERL_NO_GET_CONTEXT should avoid some accidental inefficiencies (by failing to compile on some configs, I believe).

    I had forgotten about perlguts (or rather, I was confusing it with perlhack).