in reply to Re: XS: EXTEND/mPUSHi
in thread XS: EXTEND/mPUSHi
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.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: XS: EXTEND/mPUSHi
by syphilis (Archbishop) on Sep 26, 2011 at 22:51 UTC | |
by ikegami (Patriarch) on Sep 26, 2011 at 23:02 UTC | |
by syphilis (Archbishop) on Sep 27, 2011 at 01:19 UTC | |
by ikegami (Patriarch) on Sep 27, 2011 at 02:04 UTC | |
by BrowserUk (Patriarch) on Sep 26, 2011 at 23:43 UTC | |
by syphilis (Archbishop) on Sep 27, 2011 at 00:39 UTC | |
by BrowserUk (Patriarch) on Sep 27, 2011 at 07:21 UTC | |
by syphilis (Archbishop) on Sep 28, 2011 at 08:24 UTC | |
by ikegami (Patriarch) on Sep 27, 2011 at 01:33 UTC | |
by syphilis (Archbishop) on Sep 27, 2011 at 04:16 UTC | |
| |
by ikegami (Patriarch) on Sep 27, 2011 at 01:08 UTC | |
by BrowserUk (Patriarch) on Sep 27, 2011 at 01:44 UTC | |
by ikegami (Patriarch) on Sep 27, 2011 at 02:09 UTC |
In Section
Seekers of Perl Wisdom