Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi there!

Is it possible to generate a PerlInterpreter instance, delete it and then build a new PerlInterpreter instance if you didn't compile your perl with -DMULTIPLICITY?

We've written a segfaulting sample prog:

extern "C" { #include <EXTERN.h> #include <perl.h> #include <XSUB.h> } #include <iostream> PerlInterpreter *perlInt; void start() { perlInt = perl_alloc(); perl_construct(perlInt); char *embedding[] = { "", "-w", "-e", "use diagnostics;" }; perl_parse(perlInt, NULL, 4, embedding, NULL); perl_run(perlInt); PL_perl_destruct_level = 1; cout << "destructing..." << flush; perl_destruct(perlInt); cout << "done" << endl; perl_free(perlInt); } int main() { start(); start(); return 0; }

The output is:

cordelia:~/stuff/xpertmud/xpertmud 201> ./perl_problem
destructing...done
destructing...Segmentation fault

backtrace:

Starting program: 
/home/tmp/klimek/shadow/xpertmud/xpertmud/xpertmud/./perl_problem
destructing...done
destructing...
Program received signal SIGSEGV, Segmentation fault.
0x4015ae8e in free () from /lib/libc.so.6
(gdb) back
#0  0x4015ae8e in free () from /lib/libc.so.6
#1  0x4015ae19 in free () from /lib/libc.so.6
#2  0x0805a523 in perl_destruct () at eval.c:41
#3  0x08059922 in start () at perl_problem.cc:21
#4  0x08059964 in main () at perl_problem.cc:29
#5  0x400f7237 in __libc_start_main () from /lib/libc.so.6

The question: Is this some general problem or did we do something wrong?

Thanks for any help,
        Manuel