when removing magic, fix SvMAGICAL flags (unless save_magic is active)
Chip Salzenberg [Tue, 27 Oct 2009 02:39:20 +0000 (19:39 -0700)]
sv.c

diff --git a/sv.c b/sv.c
index 95ad106..811d8ce 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -5209,12 +5209,14 @@ Perl_sv_unmagic(pTHX_ SV *const sv, const int type)
        else
            mgp = &mg->mg_moremagic;
     }
-    if (!SvMAGIC(sv)) {
+    if (SvMAGIC(sv)) {
+       if (SvMAGICAL(sv))      /* if we're under save_magic, wait for restore_magic; */
+           mg_magical(sv);     /*    else fix the flags now */
+    }
+    else {
        SvMAGICAL_off(sv);
        SvFLAGS(sv) |= (SvFLAGS(sv) & (SVp_IOK|SVp_NOK|SVp_POK)) >> PRIVSHIFT;
-       SvMAGIC_set(sv, NULL);
     }
-
     return 0;
 }