summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Mitchell <davem@fdisolutions.com>2003-10-16 20:03:44 +0000
committerDave Mitchell <davem@fdisolutions.com>2003-10-16 20:03:44 +0000
commit4e380990fe579cbec68c15cb8ee072f2d6644a71 (patch)
tree35f69a288294af32bc65c6fdbdfa759d4279d280
parent4c9cc5953a3992eecff824aeaacb5b7670e2db46 (diff)
downloadperl-4e380990fe579cbec68c15cb8ee072f2d6644a71.tar.gz
Ensure PL_comppad/curpad point to PL_main_cv's padlist when
PL_main_root is freed; this may not have been be the case if a thread other than the main one is the last to be destroyed p4raw-id: //depot/perl@21470
-rw-r--r--ext/threads/t/thread.t7
-rw-r--r--pad.h11
-rw-r--r--perl.c4
3 files changed, 19 insertions, 3 deletions
diff --git a/ext/threads/t/thread.t b/ext/threads/t/thread.t
index c58ce00a99..2935fc2517 100644
--- a/ext/threads/t/thread.t
+++ b/ext/threads/t/thread.t
@@ -12,7 +12,7 @@ BEGIN {
use ExtUtils::testlib;
use strict;
-BEGIN { $| = 1; print "1..25\n" };
+BEGIN { $| = 1; print "1..26\n" };
use threads;
use threads::shared;
@@ -153,5 +153,10 @@ package main;
ok((keys %rand == 25), "Check that rand works after a new thread");
}
+# bugid #24165
+
+run_perl(prog =>
+ 'use threads; sub a{threads->new(shift)} $t = a sub{}; $t->tid; $t->join; $t->tid');
+is($?, 0, 'coredump in global destruction');
diff --git a/pad.h b/pad.h
index cc31777912..e839042722 100644
--- a/pad.h
+++ b/pad.h
@@ -105,6 +105,9 @@ Get the value from slot C<po> in the base (DEPTH=1) pad of a padlist
Set the current pad to be pad C<n> in the padlist, saving
the previous current pad.
+=for apidoc m|void|PAD_SET_CUR_NOSAVE |PADLIST padlist|I32 n
+like PAD_SET_CUR, but without the save
+
=for apidoc m|void|PAD_SAVE_SETNULLPAD
Save the current pad then set it to null.
@@ -133,8 +136,7 @@ Restore the old pad saved into the local variable opad by PAD_SAVE_LOCAL()
? AvARRAY((AV*)(AvARRAY(padlist)[1]))[po] : Nullsv;
-#define PAD_SET_CUR(padlist,n) \
- SAVECOMPPAD(); \
+#define PAD_SET_CUR_NOSAVE(padlist,n) \
PL_comppad = (PAD*) (AvARRAY(padlist)[n]); \
PL_curpad = AvARRAY(PL_comppad); \
DEBUG_Xv(PerlIO_printf(Perl_debug_log, \
@@ -142,6 +144,11 @@ Restore the old pad saved into the local variable opad by PAD_SAVE_LOCAL()
PTR2UV(PL_comppad), PTR2UV(PL_curpad), (int)(n)));
+#define PAD_SET_CUR(padlist,n) \
+ SAVECOMPPAD(); \
+ PAD_SET_CUR_NOSAVE(padlist,n);
+
+
#define PAD_SAVE_SETNULLPAD() SAVECOMPPAD(); \
PL_comppad = Null(PAD*); PL_curpad = Null(SV**); \
DEBUG_Xv(PerlIO_printf(Perl_debug_log, "Pad set_null\n"));
diff --git a/perl.c b/perl.c
index c707900a54..889b49326e 100644
--- a/perl.c
+++ b/perl.c
@@ -354,6 +354,10 @@ perl_destruct(pTHXx)
/* Destroy the main CV and syntax tree */
if (PL_main_root) {
+ /* ensure comppad/curpad to refer to main's pad */
+ if (CvPADLIST(PL_main_cv)) {
+ PAD_SET_CUR_NOSAVE(CvPADLIST(PL_main_cv), 1);
+ }
op_free(PL_main_root);
PL_main_root = Nullop;
}