### 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);
####
#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 */
##
##
void
foo (x, ...)
SV * x
CODE:
PL_markstack_ptr++;
foo(x);
XSRETURN_EMPTY;