Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

From Perl XS code, how do I recursively call myself?

Tags:

perl

xs

I have a complex encoding function in Pure Perl which I am converting to XS in the hope of gaining a performance boost.

The function I am converting to XS needs to recursively call itself. I can see how to use call_sv [thanks to "man perlcall"] to call Pure Perl functions.

But how the heck do I call myself (or any other XS function) from within XS?

(P.S. Efficiency is very desirable...)

Can somebody throw me a hint? Or an example? P-p-p-please!

UPDATE: First answer was absolutely correct. Calling out to recursive pure C functions works just fine.

like image 276
the.jxc Avatar asked Apr 19 '13 06:04

the.jxc


1 Answers

Don't. XS is a mechanism to provide a Perl interface to a C function. Don't call the XS function from the C function (for which you'd use call_sv or the like); call the C function from the XS function.

Write your recursive C function and keep it outside of the XS code (before the MODULE = line or in a separate .c). Call it from a thin XS wrapper.

like image 132
ikegami Avatar answered Oct 03 '22 21:10

ikegami