Ok ... I'll just make it a blanket "#define PERL_NO_GET_CONTEXT" ... no ifs and buts ;-)
I mainly use Inline::C to autogenerate my XS files.
The appealing aspect of using dTHX is that Inline::C already accommodates that approach. That is, this simple Inline::C demo works fine:
use strict;
use warnings;
use Inline C => Config =>
BUILD_NOISY => 1,
PRE_HEAD => "#define PERL_NO_GET_CONTEXT",
;
use Inline C => <<'EOC';
SV * dubble(SV * in) {
dTHX;
return newSViv(SvIV(in) * 2);
}
EOC
my $x = dubble(23);
print $x; # 46
But handling pTHX_ and aTHX_ is way beyond Inline's current capabilities, and the XS file therefore needs to be written by hand.
I'm not even sure what the XS file should look like when we use pTHX_ and aTHX_.
The following seems to work:
#define PERL_NO_GET_CONTEXT
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
SV * dubble(pTHX_ SV * in) {
return newSViv(SvIV(in) * 2);
}
MODULE = FOO PACKAGE = FOO
SV *
dubble (in)
SV * in
CODE:
RETVAL = dubble(aTHX_ in);
OUTPUT:
RETVAL
But I wouldn't like to guarantee that it's not doing something wrong and/or unnecessary.
The example in the docs to which you linked, invokes a wrapper function called my_xsub - but I've written it so that dubble() wraps itself.
Is that a valid technique ? Is there something better ?
Thanks
Dave. Good question
halfcountplus.
Cheers,
Rob
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.