in reply to Embedded perl: allowing 'exit' in eval_pv without exiting C program

Use return(0); instead of exit(0); for "exiting" Perl's main.

The problem remaining is to be able to exit the Perl script from a Perl sub whose exit() calls you do not control (as opposed from Perl main). Perhaps with a signal trap? or redefining exit() if at all possible?

Here is a simple test perl-embed program to harness:

/* harness for embedding Perl into C modified by Bliako from Compile: $(perl -MConfig -e 'print $Config{cc}') perl_embed_simple.c $(perl + -MExtUtils::Embed -e ccopts -e ldopts) -o perl_embed_simple 30/01/2019 */ #include <stdio.h> #include <signal.h> #include <EXTERN.h> /* from the Perl distribution */ #include <perl.h> /* from the Perl distribution */ static PerlInterpreter *my_perl; /*** The Perl interpreter ***/ void cleanup(void); //let perl handle it void signal_handler(int signum){ printf("got signal %d\n", signum); } int main(int argc, char **argv, char **env){ signal(SIGINT, signal_handler); PERL_SYS_INIT3(&argc,&argv,&env); my_perl = perl_alloc(); printf("%s : perl_alloc()\n", argv[0]); perl_construct(my_perl); printf("%s : perl_construct()\n", argv[0]); PL_exit_flags |= PERL_EXIT_DESTRUCT_END; char *embedding[] = { "", "-e", "0" }; perl_parse(my_perl, NULL, 3, embedding, NULL); printf("%s : perl_parse()\n", argv[0]); const char perlcode[] = "print \"hello world\\n\";" "return(0);" "print \"still here\";" ; printf("%s : executing :\n%s\n", argv[0], perlcode); SV *ret = eval_pv(perlcode, FALSE); if( SvTRUE(ERRSV) ){ fprintf(stderr, "%s : eval_sv() has failed wi +th:\n%s\nfor the code:\n%s\n", argv[0], SvPVx_nolen(ERRSV), perlcode) +; cleanup(); exit(1); } printf("%s : done.\n", argv[0]); exit(EXIT_SUCCESS); } void cleanup(void){ perl_destruct(my_perl); perl_free(my_perl); PERL_SYS_TERM(); }

bw, bliako