On Tue, Mar 31, 2009 at 02:46:48PM -0400, David F. Skoll wrote:
> Perl 5.10.0 seems not to be able to create, destroy, then recreate an
> embedded Perl interpreter the way Perl 5.8.8 could under etch.
>
> Please see attached test case. Untar, then:
>
> ./configure && make && ./embperl
>
> On Etch / Perl 5.8.8, it prints "I'm very happy!" twice.
>
> On Lenny / Perl 5.10.0, it prints "I'm very happy!" the first time
> and then:
>
> panic: MUTEX_LOCK (22) [op.c:453] at script.pl line 1.
> BEGIN failed--compilation aborted at script.pl line 1.
> panic: MUTEX_LOCK (22) [op.c:453] at script.pl line 1.
I think you're supposed to call PERL_SYS_INIT3 on the real
main() argv and argc, not the ones you provide perl_parse().
Quoting perlembed.pod:
The macros PERL_SYS_INIT3() and PERL_SYS_TERM() provide system-specific
tune up of the C runtime environment necessary to run Perl interpreters
Also, the example under "Maintaining multiple interpreter instances"
initializes the main() arguments and then proceeds to call perl_parse
with completely other arguments.
The attached patch to your testcase makes it work for me with 5.10.0.
--
Niko Tyni [email protected]
diff --git a/embperl.c b/embperl.c
index 0a0c62c..77eec51 100644
--- a/embperl.c
+++ b/embperl.c
@@ -16,9 +16,6 @@ make_embedded_interpreter(char **env)
PL_perl_destruct_level = 1;
perl_destruct(my_perl);
perl_free(my_perl);
-#ifdef PERL_SYS_TERM
- PERL_SYS_TERM();
-#endif
my_perl = NULL;
#ifdef PERL_SET_CONTEXT
PERL_SET_CONTEXT(NULL);
@@ -31,10 +28,6 @@ make_embedded_interpreter(char **env)
argc = 2;
-#ifdef PERL_SYS_INIT3
- PERL_SYS_INIT3(&argc, &argv, &env);
-#endif
-
my_perl = perl_alloc();
if (!my_perl) {
errno = ENOMEM;
@@ -53,7 +46,13 @@ make_embedded_interpreter(char **env)
int
main(int argc, char **argv, char **env)
{
+#ifdef PERL_SYS_INIT3
+ PERL_SYS_INIT3(&argc, &argv, &env);
+#endif
make_embedded_interpreter(env);
make_embedded_interpreter(env);
+#ifdef PERL_SYS_TERM
+ PERL_SYS_TERM();
+#endif
exit(0);
}