change when to make CvGV refcounted
authorDavid Mitchell <davem@iabyn.com>
Sun, 18 Jul 2010 15:21:03 +0000 (16:21 +0100)
committerDavid Mitchell <davem@iabyn.com>
Sun, 18 Jul 2010 17:39:18 +0000 (18:39 +0100)
Rather than making CvGV refcounted if the CV is anon, decide based on
whether the GV pointed to by CvGV holds a reference back to us. Normally
these two will be equivalent, but this way is more robust if people are
doing weird things.

Also spotted an error with cv_clone not clearing the CVf_CVGV_RC flag on
the newly cloned cv. This shouldn't normally matter as it will get set
shortly anyway, but best to keep things logically correct.

gv.c
pad.c

diff --git a/gv.c b/gv.c
index 9eaf76c..917cfb7 100644 (file)
--- a/gv.c
+++ b/gv.c
@@ -216,17 +216,17 @@ Perl_cvgv_set(pTHX_ CV* cv, GV* gv)
     }
 
     CvGV(cv) = gv;
+    assert(!CvCVGV_RC(cv));
 
     if (!gv)
        return;
 
-    if (CvANON(cv)) {
+    if (isGV_with_GP(gv) && GvGP(gv) && (GvCV(gv) == cv || GvFORM(gv) == cv))
+       Perl_sv_add_backref(aTHX_ MUTABLE_SV(gv), MUTABLE_SV(cv));
+    else {
        CvCVGV_RC_on(cv);
        SvREFCNT_inc_simple_void_NN(gv);
     }
-    else {
-       Perl_sv_add_backref(aTHX_ MUTABLE_SV(gv), MUTABLE_SV(cv));
-    }
 }
 
 
diff --git a/pad.c b/pad.c
index fa9f55a..3582544 100644 (file)
--- a/pad.c
+++ b/pad.c
@@ -1562,7 +1562,7 @@ Perl_cv_clone(pTHX_ CV *proto)
     SAVESPTR(PL_compcv);
 
     cv = PL_compcv = MUTABLE_CV(newSV_type(SvTYPE(proto)));
-    CvFLAGS(cv) = CvFLAGS(proto) & ~(CVf_CLONE|CVf_WEAKOUTSIDE);
+    CvFLAGS(cv) = CvFLAGS(proto) & ~(CVf_CLONE|CVf_WEAKOUTSIDE|CVf_CVGV_RC);
     CvCLONED_on(cv);
 
 #ifdef USE_ITHREADS