[patch] refcount re ops
Doug MacEachern [Fri, 3 Aug 2001 18:17:41 +0000 (11:17 -0700)]
Message-ID: <Pine.LNX.4.21.0108031814240.23972-100000@mako.covalent.net>

p4raw-id: //depot/perl@11568

regcomp.c
sv.c

index cdf42f5..fb6b9c5 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -2138,6 +2138,9 @@ S_reg(pTHX_ RExC_state_t *pRExC_state, I32 paren, I32 *flagp)
                    ENTER;
                    Perl_save_re_context(aTHX);
                    rop = sv_compile_2op(sv, &sop, "re", &av);
+                   sop->op_private |= OPpREFCOUNTED;
+                   /* re_dup will OpREFCNT_inc */
+                   OpREFCNT_set(sop, 1);
                    LEAVE;
 
                    n = add_data(pRExC_state, 3, "nop");
@@ -4609,7 +4612,11 @@ Perl_pregfree(pTHX_ struct regexp *r)
                }
                else
                    PL_curpad = NULL;
-               op_free((OP_4tree*)r->data->data[n]);
+
+               if (!OpREFCNT_dec((OP_4tree*)r->data->data[n])) {
+                    op_free((OP_4tree*)r->data->data[n]);
+               }
+
                PL_comppad = old_comppad;
                PL_curpad = old_curpad;
                SvREFCNT_dec((SV*)new_comppad);
diff --git a/sv.c b/sv.c
index 33a87b8..1194657 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -8403,6 +8403,9 @@ Perl_re_dup(pTHX_ REGEXP *r, clone_params *param)
                ret->regstclass = (regnode*)d->data[i];
                break;
            case 'o':
+               /* XXX: can this really be shared? */
+               d->data[i] = (void*)OpREFCNT_inc((OP*)r->data->data[i]);
+               break;
            case 'n':
                d->data[i] = r->data->data[i];
                break;