BUU has asked for the wisdom of the Perl Monks concerning the following question:
The problem is when I run it, I see no sign of my XS function ("say") in either main:: or Module::. It occurred to me that perhaps I need to call "boot_Module", which apparently takes two arguments: a perl_interpreter, which I have, and a CV*, which I don't. I've tried various combinations of arguments to boot_Module, but it constantly segfaults. What is the right thing to pass?#include <EXTERN.h> /* from the Perl distribution */ #include <perl.h> /* from the Perl distribution */ #include <XSUB.h> #include <stdlib.h> static PerlInterpreter *my_perl; /*** The Perl interpreter ***/ void say( char *m ) { printf("I am say: %s", m ); } XS(XS_Module_say); /* prototype to pass -Wmissing-prototypes */ XS(XS_Module_say) { dXSARGS; if (items != 1) Perl_croak(aTHX_ "Usage: Module::say(message)"); { char * message = (char *)SvPV_nolen(ST(0)); say(message); } XSRETURN_EMPTY; } #ifdef __cplusplus extern "C" #endif XS(boot_Module); /* prototype to pass -Wmissing-prototypes */ XS(boot_Module) { dXSARGS; char* file = __FILE__; XS_VERSION_BOOTCHECK ; newXS("Module::say", XS_Module_say, file); XSRETURN_YES; } int main(int argc, char **argv, char **env) { char *embedding = { "", "-e", "0" }; PERL_SYS_INIT3(&argc,&argv,&env); my_perl = perl_alloc(); perl_construct(my_perl); PL_exit_flags |= PERL_EXIT_DESTRUCT_END; perl_parse(my_perl, NULL, argc, argv, (char **)NULL); perl_run(my_perl); perl_destruct(my_perl); perl_free(my_perl); PERL_SYS_TERM(); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Embedding perl and exposing xs functions
by PodMaster (Abbot) on Dec 19, 2005 at 09:37 UTC | |
by BUU (Prior) on Dec 19, 2005 at 19:34 UTC |