This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Revert "Fix failing autodie test with new smartmatch semantics."
[perl5.git] / scope.c
diff --git a/scope.c b/scope.c
index 78d796b..20e027f 100644 (file)
--- a/scope.c
+++ b/scope.c
@@ -509,6 +509,17 @@ Perl_save_delete(pTHX_ HV *hv, char *key, I32 klen)
 }
 
 void
+Perl_save_adelete(pTHX_ AV *av, I32 key)
+{
+    dVAR;
+
+    PERL_ARGS_ASSERT_SAVE_ADELETE;
+
+    SvREFCNT_inc_void(av);
+    save_pushi32ptr(key, av, SAVEt_ADELETE);
+}
+
+void
 Perl_save_destructor(pTHX_ DESTRUCTORFUNC_NOCONTEXT_t f, void* p)
 {
     dVAR;
@@ -648,6 +659,8 @@ Perl_leave_scope(pTHX_ I32 base)
     void* ptr;
     register char* str;
     I32 i;
+    /* Localise the effects of the TAINT_NOT inside the loop.  */
+    const bool was = PL_tainted;
 
     if (base < -1)
        Perl_croak(aTHX_ "panic: corrupt saved stack index");
@@ -862,6 +875,13 @@ Perl_leave_scope(pTHX_ I32 base)
            SvREFCNT_dec(hv);
            Safefree(ptr);
            break;
+       case SAVEt_ADELETE:
+           ptr = SSPOPPTR;
+           av = MUTABLE_AV(ptr);
+           i = SSPOPINT;
+           (void)av_delete(av, i, G_DISCARD);
+           SvREFCNT_dec(av);
+           break;
        case SAVEt_DESTRUCTOR_X:
            ptr = SSPOPPTR;
            (*SSPOPDXPTR)(aTHX_ ptr);
@@ -902,19 +922,18 @@ Perl_leave_scope(pTHX_ I32 base)
            sv = MUTABLE_SV(SSPOPPTR);
            hv = MUTABLE_HV(SSPOPPTR);
            ptr = hv_fetch_ent(hv, sv, 1, 0);
+           SvREFCNT_dec(sv);
            if (ptr) {
                const SV * const oval = HeVAL((HE*)ptr);
                if (oval && oval != &PL_sv_undef) {
                    ptr = &HeVAL((HE*)ptr);
                    if (SvTIED_mg((const SV *)hv, PERL_MAGIC_tied))
                        SvREFCNT_inc_void(*(SV**)ptr);
-                   SvREFCNT_dec(sv);
                    av = MUTABLE_AV(hv); /* what to refcnt_dec */
                    goto restore_sv;
                }
            }
            SvREFCNT_dec(hv);
-           SvREFCNT_dec(sv);
            SvREFCNT_dec(value);
            break;
        case SAVEt_OP:
@@ -1066,6 +1085,8 @@ Perl_leave_scope(pTHX_ I32 base)
            Perl_croak(aTHX_ "panic: leave_scope inconsistency");
        }
     }
+
+    PL_tainted = was;
 }
 
 void