Use only one block of memory for both PL_psig_name and PL_psig_ptr.
Nicholas Clark [Thu, 21 May 2009 07:02:38 +0000 (09:02 +0200)]
gv.c
intrpvar.h
perl.c
sv.c

diff --git a/gv.c b/gv.c
index 291e2d1..703635c 100644 (file)
--- a/gv.c
+++ b/gv.c
@@ -1232,10 +1232,10 @@ Perl_gv_fetchpvn_flags(pTHX_ const char *nambeg, STRLEN full_len, I32 flags,
                if (strEQ(name2, "IG")) {
                    HV *hv;
                    I32 i;
-                   if (!PL_psig_ptr) {
-                       Newxz(PL_psig_ptr,  SIG_SIZE, SV*);
-                       Newxz(PL_psig_name, SIG_SIZE, SV*);
+                   if (!PL_psig_name) {
+                       Newxz(PL_psig_name, 2 * SIG_SIZE, SV*);
                        Newxz(PL_psig_pend, SIG_SIZE, int);
+                       PL_psig_ptr = PL_psig_name + SIG_SIZE;
                    } else {
                        /* I think that the only way to get here is to re-use an
                           embedded perl interpreter, where the previous
@@ -1246,8 +1246,7 @@ Perl_gv_fetchpvn_flags(pTHX_ const char *nambeg, STRLEN full_len, I32 flags,
                           interpreter structure that something else will crash
                           before we get here. I suspect that this is one of
                           those "doctor, it hurts when I do this" bugs.  */
-                       Zero(PL_psig_ptr,  SIG_SIZE, SV*);
-                       Zero(PL_psig_name, SIG_SIZE, SV*);
+                       Zero(PL_psig_name, 2 * SIG_SIZE, SV*);
                        Zero(PL_psig_pend, SIG_SIZE, int);
                    }
                    GvMULTI_on(gv);
index 3265ac2..7a05268 100644 (file)
@@ -537,7 +537,8 @@ PERLVAR(Iparser,    yy_parser *)    /* current parser state */
    signal handler dispatches.  */
 PERLVAR(Ipsig_ptr, SV**)
 /* Array of names of signals, indexed by signal number, for (re)use as the first
-   argument to a signal handler.   */
+   argument to a signal handler.   Only one block of memory is allocated for
+   both psig_name and psig_ptr.  */
 PERLVAR(Ipsig_name, SV**)              
 
 #if defined(PERL_IMPLICIT_SYS)
diff --git a/perl.c b/perl.c
index fa7a5e1..73082ba 100644 (file)
--- a/perl.c
+++ b/perl.c
@@ -1228,10 +1228,9 @@ perl_destruct(pTHXx)
     Safefree(PL_reg_poscache);
     free_tied_hv_pool();
     Safefree(PL_op_mask);
-    Safefree(PL_psig_ptr);
-    PL_psig_ptr = (SV**)NULL;
     Safefree(PL_psig_name);
     PL_psig_name = (SV**)NULL;
+    PL_psig_ptr = (SV**)NULL;
     Safefree(PL_psig_pend);
     PL_psig_pend = (int*)NULL;
     PL_formfeed = NULL;
diff --git a/sv.c b/sv.c
index b408485..1dad3cf 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -12185,13 +12185,11 @@ perl_clone_using(PerlInterpreter *proto_perl, UV flags,
        PL_psig_pend    = (int*)NULL;
     }
 
-    if (proto_perl->Ipsig_ptr) {
-       Newx(PL_psig_ptr,  SIG_SIZE, SV*);
-       Newx(PL_psig_name, SIG_SIZE, SV*);
-       sv_dup_inc_multiple(proto_perl->Ipsig_ptr, PL_psig_ptr, SIG_SIZE,
-                           param);
-       sv_dup_inc_multiple(proto_perl->Ipsig_name, PL_psig_name, SIG_SIZE,
+    if (proto_perl->Ipsig_name) {
+       Newx(PL_psig_name, 2 * SIG_SIZE, SV*);
+       sv_dup_inc_multiple(proto_perl->Ipsig_name, PL_psig_name, 2 * SIG_SIZE,
                            param);
+       PL_psig_ptr = PL_psig_name + SIG_SIZE;
     }
     else {
        PL_psig_ptr     = (SV**)NULL;