My question: How from within XS do I recursively (and efficiently) call my own XS function?
I can see call_sv and it various variants, by which I can call a Perl function from XS. But how do I call myself?
I have a nasty little parser that I am migrating from PP to XS, and it needs to recurse... help please!
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
int foo(int x) {
if(x >= 20) return x;
x++;
x = foo(x);
}
MODULE = My::Mod PACKAGE = My::Mod
PROTOTYPES: DISABLE
int
foo (x)
int x
[download]
If you have several XS modules and want to call from one into other, you may like to use Module::CAPIMaker, that provides an efficient and portable way to expose a C API from a module.
PUSHMARK(SP);
PUSHs(somesv);
PUTBACK;
XS_Foo__Bar_Func(aTHX_ cv);
SPAGAIN;
retval = POPs; /* did we get 1 elem? this code just assumes*/
/* ?????? */
.