Integrate against change 9670 aka perl-5.7.1
[p5sagit/p5-mst-13.2.git] / scope.c
diff --git a/scope.c b/scope.c
index 5275935..31c6f01 100644 (file)
--- a/scope.c
+++ b/scope.c
@@ -196,7 +196,7 @@ S_save_scalar_at(pTHX_ SV **sptr)
        if (SvGMAGICAL(osv)) {
            MAGIC* mg;
            bool oldtainted = PL_tainted;
-           mg_get(osv);
+           mg_get(osv);                /* note, can croak! */
            if (PL_tainting && PL_tainted && (mg = mg_find(osv, 't'))) {
                SAVESPTR(mg->mg_obj);
                mg->mg_obj = osv;
@@ -207,6 +207,9 @@ S_save_scalar_at(pTHX_ SV **sptr)
        }
        SvMAGIC(sv) = SvMAGIC(osv);
        SvFLAGS(sv) |= SvMAGICAL(osv);
+       /* XXX SvMAGIC() is *shared* between osv and sv.  This can
+        * lead to coredumps when both SVs are destroyed without one
+        * of their SvMAGIC() slots being NULLed. */
        PL_localizing = 1;
        SvSETMAGIC(sv);
        PL_localizing = 0;
@@ -501,6 +504,14 @@ Perl_save_freesv(pTHX_ SV *sv)
 }
 
 void
+Perl_save_mortalizesv(pTHX_ SV *sv)
+{
+    SSCHECK(2);
+    SSPUSHPTR(sv);
+    SSPUSHINT(SAVEt_MORTALIZESV);
+}
+
+void
 Perl_save_freeop(pTHX_ OP *o)
 {
     SSCHECK(2);
@@ -678,12 +689,19 @@ Perl_leave_scope(pTHX_ I32 base)
                SvMAGICAL_off(sv);
                SvMAGIC(sv) = 0;
            }
+           /* XXX This branch is pretty bogus.  This code irretrievably
+            * clears(!) the magic on the SV (either to avoid further
+            * croaking that might ensue when the SvSETMAGIC() below is
+            * called, or to avoid two different SVs pointing at the same
+            * SvMAGIC()).  This needs a total rethink.  --GSAR */
            else if (SvTYPE(value) >= SVt_PVMG && SvMAGIC(value) &&
                     SvTYPE(value) != SVt_PVGV)
            {
                SvFLAGS(value) |= (SvFLAGS(value) &
                                   (SVp_IOK|SVp_NOK|SVp_POK)) >> PRIVSHIFT;
                SvMAGICAL_off(value);
+               /* XXX this is a leak when we get here because the
+                * mg_get() in save_scalar_at() croaked */
                SvMAGIC(value) = 0;
            }
             SvREFCNT_dec(sv);
@@ -793,6 +811,10 @@ Perl_leave_scope(pTHX_ I32 base)
            ptr = SSPOPPTR;
            SvREFCNT_dec((SV*)ptr);
            break;
+       case SAVEt_MORTALIZESV:
+           ptr = SSPOPPTR;
+           sv_2mortal((SV*)ptr);
+           break;
        case SAVEt_FREEOP:
            ptr = SSPOPPTR;
            if (PL_comppad)
@@ -912,10 +934,6 @@ Perl_leave_scope(pTHX_ I32 base)
            PL_op = (OP*)SSPOPPTR;
            break;
        case SAVEt_HINTS:
-           if (GvHV(PL_hintgv)) {
-               SvREFCNT_dec((SV*)GvHV(PL_hintgv));
-               GvHV(PL_hintgv) = NULL;
-           }
            *(I32*)&PL_hints = (I32)SSPOPINT;
            break;
        case SAVEt_COMPPAD: