Revert "Revert "8c34e50dc slowed down detruction with no DESTROY""
authorFather Chrysostomos <sprout@cpan.org>
Tue, 20 Nov 2012 21:47:27 +0000 (13:47 -0800)
committerFather Chrysostomos <sprout@cpan.org>
Wed, 21 Nov 2012 01:58:57 +0000 (17:58 -0800)
This reverts commit 95f9781bc2fad025553db0160ef9c2c5363312a1.

Now that the crash has been fixed by the preceding commit, we can
reinstate 7cc6787e9db.

mro.c
sv.c

diff --git a/mro.c b/mro.c
index 2d1d887..be2038f 100644 (file)
--- a/mro.c
+++ b/mro.c
@@ -578,6 +578,7 @@ Perl_mro_isa_changed_in(pTHX_ HV* stash)
                 revmeta->cache_gen++;
             if(revmeta->mro_nextmethod)
                 hv_clear(revmeta->mro_nextmethod);
+           if (!SvOBJECT(revstash)) SvSTASH(revstash) = NULL;
 
            (void)
              hv_store(
@@ -1356,6 +1357,7 @@ Perl_mro_method_changed_in(pTHX_ HV *stash)
             mrometa->cache_gen++;
             if(mrometa->mro_nextmethod)
                 hv_clear(mrometa->mro_nextmethod);
+            if (!SvOBJECT(revstash)) SvSTASH(revstash) = NULL;
         }
     }
 
diff --git a/sv.c b/sv.c
index 9f5c157..a791498 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -6338,12 +6338,12 @@ S_curse(pTHX_ SV * const sv, const bool check_refcnt) {
            if (!destructor) {
                GV * const gv =
                    gv_fetchmeth_autoload(stash, "DESTROY", 7, 0);
-               if (gv && (destructor = GvCV(gv))) {
-                   if (!SvOBJECT(stash))
-                       SvSTASH(stash) = (HV *)destructor;
-               }
+               if (gv) destructor = GvCV(gv);
+               if (!SvOBJECT(stash))
+                   SvSTASH(stash) =
+                       destructor ? (HV *)destructor : ((HV *)0)+1;
            }
-           if (destructor
+           if (destructor && destructor != ((CV *)0)+1
                /* A constant subroutine can have no side effects, so
                   don't bother calling it.  */
                && !CvCONST(destructor)
@@ -12000,7 +12000,7 @@ S_sv_dup_common(pTHX_ const SV *const sstr, CLONE_PARAMS *const param)
                    SvOURSTASH_set(dstr, hv_dup_inc(SvOURSTASH(dstr), param));
                } else if (SvMAGIC(dstr))
                    SvMAGIC_set(dstr, mg_dup(SvMAGIC(dstr), param));
-               if (SvSTASH(dstr))
+               if (SvOBJECT(dstr) && SvSTASH(dstr))
                    SvSTASH_set(dstr, hv_dup_inc(SvSTASH(dstr), param));
                else SvSTASH_set(dstr, 0); /* don't copy DESTROY cache */
            }