add verbose stack display option, -Dvs
[p5sagit/p5-mst-13.2.git] / mg.c
diff --git a/mg.c b/mg.c
index 6176034..1c7d239 100644 (file)
--- a/mg.c
+++ b/mg.c
@@ -359,17 +359,8 @@ Perl_mg_free(pTHX_ SV *sv)
            else if (mg->mg_len == HEf_SVKEY)
                SvREFCNT_dec((SV*)mg->mg_ptr);
        }
-       if (mg->mg_flags & MGf_REFCOUNTED) {
-           SV *obj = mg->mg_obj;
-           if (mg->mg_type == PERL_MAGIC_tiedscalar && SvROK(obj) &&
-               (SvRV(obj) == sv || GvIO(SvRV(obj)) == (IO *) sv)) {
-               /* We are already free'ing the self-tied thing
-                  so must not SvREFCNT_dec.
-                */
-               SvROK_off(obj);
-           } else
-               SvREFCNT_dec(obj);
-       }
+       if (mg->mg_flags & MGf_REFCOUNTED)
+           SvREFCNT_dec(mg->mg_obj);
        Safefree(mg);
     }
     SvMAGIC(sv) = 0;
@@ -702,18 +693,25 @@ Perl_magic_get(pTHX_ SV *sv, MAGIC *mg)
 
              getrx:
                if (i >= 0) {
-                   bool was_tainted = FALSE;
-                   if (PL_tainting) {
-                       was_tainted = PL_tainted;
-                       PL_tainted = FALSE;
-                   }
                    sv_setpvn(sv, s, i);
-                   if (PL_reg_match_utf8 && is_utf8_string((U8*)s, i))
+                   if (PL_reg_match_utf8 && is_utf8_string((U8*)s, i))
                        SvUTF8_on(sv);
                    else
                        SvUTF8_off(sv);
-                   if (PL_tainting)
-                       PL_tainted = (was_tainted || RX_MATCH_TAINTED(rx));
+                   if (PL_tainting) {
+                       if (RX_MATCH_TAINTED(rx)) {
+                           MAGIC* mg = SvMAGIC(sv);
+                           MAGIC* mgt;
+                           PL_tainted = 1;
+                           SvMAGIC(sv) = mg->mg_moremagic;
+                           SvTAINT(sv);
+                           if ((mgt = SvMAGIC(sv))) {
+                               mg->mg_moremagic = mgt;
+                               SvMAGIC(sv) = mg;
+                           }
+                       } else
+                           SvTAINTED_off(sv);
+                   }
                    break;
                }
            }