



I'm trying to use multiple perl interpreters within a single thread (embedding perl in C). I've tried to follow the instructions in the perlembed document (under the section Maintaining multiple interpreter instances), but I get a crash with the message "Free to wrong pool XX not YY". I'm trying to figure out if I'm doing something wrong here.
My C program and perl scripts are quite simple:
#include
#include
void main()
{
PerlInterpreter *my_perl;
PerlInterpreter *my_perl2;
static char *embedding[] = { "", "-e", "0" };
static char *embedding2[] = { "", "-e", "0" };
my_perl = perl_alloc();
my_perl2 = perl_alloc();
PERL_SET_CONTEXT(my_perl);
PL_perl_destruct_level = 1;
perl_construct(my_perl);
PERL_SET_CONTEXT(my_perl2);
PL_perl_destruct_level = 1;
perl_construct(my_perl2);
PERL_SET_CONTEXT(my_perl);
perl_parse(my_perl, NULL, 3, embedding, (char **)NULL);
PERL_SET_CONTEXT(my_perl2);
perl_parse(my_perl2, NULL, 3, embedding2, (char **)NULL);
PERL_SET_CONTEXT(my_perl);
perl_run(my_perl);
PERL_SET_CONTEXT(my_perl2);
perl_run(my_perl2);
PERL_SET_CONTEXT(my_perl);
eval_pv("do 'C:\\temp\\test.pl'", TRUE);
printf("a = %d\n", SvIV(get_sv("a", FALSE)));
eval_pv("do 'C:\\temp\\test.pl'", TRUE);
printf("a = %d\n", SvIV(get_sv("a", FALSE)));
PERL_SET_CONTEXT(my_perl2);
eval_pv("do 'C:\\temp\\test.pl'", TRUE); //Crash here
printf("b = %d\n", SvIV(get_sv("b", FALSE)));
PERL_SET_CONTEXT(my_perl2);
PL_perl_destruct_level = 1;
perl_destruct(my_perl2);
PERL_SET_CONTEXT(my_perl);
PL_perl_destruct_level = 1;
perl_destruct(my_perl);
PERL_SET_CONTEXT(my_perl);
perl_free(my_perl);
PERL_SET_CONTEXT(my_perl2);
perl_free(my_perl2);
}test.pl:
$a += 1;
Is there something I'm doing wrong/not understanding, or have I enountered a bug?
Thanks for the help.