This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Move generation of ExtUtils::Miniperl to ext/ExtUtils-Miniperl from minimod.pl
[perl5.git] / scope.c
diff --git a/scope.c b/scope.c
index f9d94c3..3ac3990 100644 (file)
--- a/scope.c
+++ b/scope.c
@@ -166,7 +166,7 @@ Perl_free_tmps(pTHX)
 #endif
        if (sv && sv != &PL_sv_undef) {
            SvTEMP_off(sv);
-           SvREFCNT_dec(sv);           /* note, can modify tmps_ix!!! */
+           SvREFCNT_dec_NN(sv);                /* note, can modify tmps_ix!!! */
        }
     }
 }
@@ -214,9 +214,11 @@ Perl_save_scalar(pTHX_ GV *gv)
 
     PERL_ARGS_ASSERT_SAVE_SCALAR;
 
-    PL_localizing = 1;
-    SvGETMAGIC(*sptr);
-    PL_localizing = 0;
+    if (SvGMAGICAL(*sptr)) {
+        PL_localizing = 1;
+        (void)mg_get(*sptr);
+        PL_localizing = 0;
+    }
     save_pushptrptr(SvREFCNT_inc_simple(gv), SvREFCNT_inc(*sptr), SAVEt_SV);
     return save_scalar_at(sptr, SAVEf_SETMAGIC); /* XXX - FIXME - see #60360 */
 }
@@ -392,7 +394,7 @@ Perl_save_int(pTHX_ int *intp)
 {
     dVAR;
     const int i = *intp;
-    UV type = ((UV)(i << SAVE_TIGHT_SHIFT) | SAVEt_INT_SMALL);
+    UV type = ((UV)((UV)i << SAVE_TIGHT_SHIFT) | SAVEt_INT_SMALL);
     int size = 2;
     dSS_ADD;
 
@@ -439,7 +441,7 @@ Perl_save_I32(pTHX_ I32 *intp)
 {
     dVAR;
     const I32 i = *intp;
-    UV type = ((I32)(i << SAVE_TIGHT_SHIFT) | SAVEt_I32_SMALL);
+    UV type = ((I32)((U32)i << SAVE_TIGHT_SHIFT) | SAVEt_I32_SMALL);
     int size = 2;
     dSS_ADD;
 
@@ -722,8 +724,9 @@ Perl_save_alloc(pTHX_ I32 size, I32 pad)
     const UV elems_shifted = elems << SAVE_TIGHT_SHIFT;
 
     if ((elems_shifted >> SAVE_TIGHT_SHIFT) != elems)
-       Perl_croak(aTHX_ "panic: save_alloc elems %"UVuf" out of range (%ld-%ld)",
-                  elems, size, pad);
+       Perl_croak(aTHX_
+            "panic: save_alloc elems %"UVuf" out of range (%"IVdf"-%"IVdf")",
+                  elems, (IV)size, (IV)pad);
 
     SSGROW(elems + 1);
 
@@ -808,9 +811,11 @@ Perl_leave_scope(pTHX_ I32 base)
        switch (type) {
        case SAVEt_ITEM:                        /* normal string */
            sv_replace(ARG1_SV, ARG0_SV);
-           PL_localizing = 2;
-           SvSETMAGIC(ARG1_SV);
-           PL_localizing = 0;
+            if (SvSMAGICAL(ARG1_SV)) {
+                PL_localizing = 2;
+                mg_set(ARG1_SV);
+                PL_localizing = 0;
+            }
            break;
 
            /* This would be a mathom, but Perl_save_svref() calls a static
@@ -828,10 +833,12 @@ Perl_leave_scope(pTHX_ I32 base)
            SV * const sv = *svp;
            *svp = ARG0_SV;
            SvREFCNT_dec(sv);
-           PL_localizing = 2;
-           SvSETMAGIC(ARG0_SV);
-           PL_localizing = 0;
-           SvREFCNT_dec(ARG0_SV);
+            if (SvSMAGICAL(ARG0_SV)) {
+                PL_localizing = 2;
+                mg_set(ARG0_SV);
+                PL_localizing = 0;
+            }
+           SvREFCNT_dec_NN(ARG0_SV);
            SvREFCNT_dec(refsv);
            break;
         }
@@ -884,22 +891,22 @@ Perl_leave_scope(pTHX_ I32 base)
        case SAVEt_AV:                          /* array reference */
            SvREFCNT_dec(GvAV(ARG1_GV));
            GvAV(ARG1_GV) = ARG0_AV;
-           if (SvMAGICAL(ARG0_AV)) {
-               PL_localizing = 2;
-               SvSETMAGIC(MUTABLE_SV(ARG0_AV));
-               PL_localizing = 0;
-           }
-           SvREFCNT_dec(ARG1_GV);
+            if (SvSMAGICAL(ARG0_SV)) {
+                PL_localizing = 2;
+                mg_set(ARG0_SV);
+                PL_localizing = 0;
+            }
+           SvREFCNT_dec_NN(ARG1_GV);
            break;
        case SAVEt_HV:                          /* hash reference */
            SvREFCNT_dec(GvHV(ARG1_GV));
            GvHV(ARG1_GV) = ARG0_HV;
-           if (SvMAGICAL(ARG0_HV)) {
-               PL_localizing = 2;
-               SvSETMAGIC(MUTABLE_SV(ARG0_HV));
-               PL_localizing = 0;
-           }
-           SvREFCNT_dec(ARG1_GV);
+            if (SvSMAGICAL(ARG0_SV)) {
+                PL_localizing = 2;
+                mg_set(ARG0_SV);
+                PL_localizing = 0;
+            }
+           SvREFCNT_dec_NN(ARG1_GV);
            break;
        case SAVEt_INT_SMALL:
            *(int*)ARG0_PTR = (int)(uv >> SAVE_TIGHT_SHIFT);
@@ -909,7 +916,9 @@ Perl_leave_scope(pTHX_ I32 base)
            break;
        case SAVEt_BOOL:                        /* bool reference */
            *(bool*)ARG0_PTR = cBOOL(uv >> 8);
-#if !NO_TAINT_SUPPORT
+#ifdef NO_TAINT_SUPPORT
+            PERL_UNUSED_VAR(was);
+#else
            if (ARG0_PTR == &(TAINT_get)) {
                /* If we don't update <was>, to reflect what was saved on the
                 * stack for PL_tainted, then we will overwrite this attempt to
@@ -958,7 +967,7 @@ Perl_leave_scope(pTHX_ I32 base)
                     /* putting a method back into circulation ("local")*/      
                     gv_method_changed(ARG1_GV);
            }
-           SvREFCNT_dec(ARG1_GV);
+           SvREFCNT_dec_NN(ARG1_GV);
            break;
         }
        case SAVEt_FREESV:
@@ -1067,7 +1076,7 @@ Perl_leave_scope(pTHX_ I32 base)
                     }
                     default:   *svp = newSV(0);                break;
                     }
-                    SvREFCNT_dec(sv);  /* Cast current value to the winds. */
+                    SvREFCNT_dec_NN(sv); /* Cast current value to the winds. */
                     /* preserve pad nature, but also mark as not live
                      * for any closure capturing */
                     SvFLAGS(*svp) |= (SVs_PADMY|SVs_PADSTALE);
@@ -1216,31 +1225,18 @@ Perl_leave_scope(pTHX_ I32 base)
 
            PL_compiling.cop_warnings = (STRLEN*)ARG0_PTR;
            break;
-       case SAVEt_RE_STATE:
-           {
-               const struct re_save_state *const state
-                   = (struct re_save_state *)
-                   (PL_savestack + PL_savestack_ix
-                    - SAVESTACK_ALLOC_FOR_RE_SAVE_STATE);
-               PL_savestack_ix -= SAVESTACK_ALLOC_FOR_RE_SAVE_STATE;
-
-               if (PL_reg_poscache != state->re_state_reg_poscache) {
-                   Safefree(PL_reg_poscache);
-               }
-               Copy(state, &PL_reg_state, 1, struct re_save_state);
-           }
-           break;
        case SAVEt_PARSER:
            parser_free((yy_parser *) ARG0_PTR);
            break;
+       case SAVEt_READONLY_OFF:
+           SvREADONLY_off(ARG0_SV);
+           break;
        default:
            Perl_croak(aTHX_ "panic: leave_scope inconsistency %u", type);
        }
     }
 
     TAINT_set(was);
-
-    PERL_ASYNC_CHECK();
 }
 
 void