How to emulate z
sub behavior within XS
sub?
package XS;
sub hello {
print "ARGS: >>@_<<\n";
my $lvl;
while( my @frame = caller( $lvl++ ) ) {
print ">>@frame[0..4]<<\n";
}
}
sub z {
&hello;
}
In my .xs
file I have:
void
call_perl() {
call_pv( "XS::hello", G_NOARGS );
}
void
test(...)
CODE:
call_perl();
But calling XS::test(1,2,3)
do not pass any arguments to hello
.
The output:
ARGS: >><<
>>main -e 1 XS::hello <<
Here we can see that $hasargs
flag is not set because of G_NOARG
flag, but why @_
is flushed? What did I miss?
UPD
Seems found an half of the answer.
G_NOARGS flag
has the effect of not creating the @_ array for the Perl subroutine.
When
XSUB
is called the perl do not create the frame for it (can not remember where this is described) and do not fill@_
for it (this described indirectly here)XSUBs refer to their stack arguments with the macro ST(x)
So the more precise question will be:
How to propagate XSUB
stack arguments to PP
subroutine?
NOTICE: I can not just use:
call_pv( "XS::hello", 0 );
Because this is ordinal PP sub call. And when it returns the XSUB
stack arguments will be replaced by a return value from XS::hello
sub
int count = call_pv( "XS::hello", 0 );
STAGAIN;
printf( "%s\n", SvPV_nolen( ST(0) ) );
So I supply G_NOARGS
flag to be able to access XSUB
stack arguments after call to PP
sub