Thanks.
Yes. I know it can be done using the ludicrously verbose, Camel_Case_And_Underscores inline stack macros. I was trying to understand why I can't use the neater and more concise XS macros from Inline C. I've found I can reduce the requirements to:
#! perl -slw
use strict;
use Inline C => Config => BUILD_NOISY => 1;
use Inline C => <<'END_C', NAME => 'monkeys', CLEAN_AFTER_BUILD => 0;
void rnd64( int n ) {
Inline_Stack_Vars;
static unsigned __int64 y = 88172645463325252i64;
EXTEND( SP, n );
while( n-- ) {
y ^= y << 13;
y ^= y >> 7;
y ^= y << 17;
mPUSHu( y );
}
Inline_Stack_Done;
return;
}
But looking at the C produced by the above, it looks like there is a path through the generated wrapper function that avoids both the XSRETURN_EMPTY and the PUTBACK, thus returning whatever has been pushed:
XS(XS_main_rnd64); /* prototype to pass -Wmissing-prototypes */
XS(XS_main_rnd64)
{
#ifdef dVAR
dVAR; dXSARGS;
#else
dXSARGS;
#endif
if (items != 1)
croak_xs_usage(cv, "n");
PERL_UNUSED_VAR(ax); /* -Wall */
SP -= items;
{
int n = (int)SvIV(ST(0));
#line 46 "monkeys.xs"
I32* temp;
#line 117 "monkeys.c"
#line 48 "monkeys.xs"
temp = PL_markstack_ptr++;
rnd64(n);
if (PL_markstack_ptr != temp) {
/* truly void, because dXSARGS not invoked */
PL_markstack_ptr = temp;
XSRETURN_EMPTY; /* return empty stack */
}
/* must have used dXSARGS; list context implied */
return; /* assume stack size is correct */ ### Her
+e
#line 128 "monkeys.c"
PUTBACK;
return;
}
}
But I'm obviously missing something in the OP code that would cause (or allow) it to follow that path?
-
-
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
-
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.