syphilis has asked for the wisdom of the Perl Monks concerning the following question:
Inline::C will generate the following XS file:### try.pl ### use strict; use warnings; use Inline C => Config => FORCE_BUILD => 1, BUILD_NOISY => 1, CLEAN_AFTER_BUILD => 0, ; use Inline C => <<'EOC'; void foo(SV * x, ...) { dXSARGS; int i, ret = 0; for(i = 0; i < items; i++) { ret += (int)SvIV(ST(i)); } printf("%d\n", ret); XSRETURN(0); } EOC # Apart from the building output, this script # finally outputs -5 (== 1 + 2 + 3 - 11) foo(1,2,3,-11);
(That Inline.h file is automatically included. It's not used or needed in this case, and can be ignored.)#include "EXTERN.h" #include "perl.h" #include "XSUB.h" #include "INLINE.h" void foo(SV * x, ...) { dXSARGS; int i, ret = 0; for(i = 0; i < items; i++) { ret += (int)SvIV(ST(i)); } printf("%d\n", ret); XSRETURN(0); } MODULE = try_pl_22db PACKAGE = main PROTOTYPES: DISABLE void foo (x, ...) SV * x PREINIT: I32* temp; PPCODE: temp = PL_markstack_ptr++; foo(x); 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 */
However, in this instance, PL_markstack_ptr has not been reset to the value it held prior to its incrementation.void foo (x, ...) SV * x CODE: PL_markstack_ptr++; foo(x); XSRETURN_EMPTY;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: [XS] Manipulating the Stack
by NERDVANA (Priest) on Oct 17, 2023 at 00:52 UTC | |
by syphilis (Archbishop) on Oct 17, 2023 at 05:37 UTC |