Abstract the specific use of SvCUR in GVs for detecting variables on
Nicholas Clark [Sat, 25 Feb 2006 16:48:46 +0000 (16:48 +0000)]
both sides of an assignment using GvASSIGN_GENERATION() and
GvASSIGN_GENERATION_set().

p4raw-id: //depot/perl@27327

gv.h
op.c

diff --git a/gv.h b/gv.h
index 3e2bc90..81a42cf 100644 (file)
--- a/gv.h
+++ b/gv.h
@@ -63,6 +63,11 @@ struct gp {
 #  define GvNAMELEN(gv)        (GvXPVGV(gv)->xgv_namelen)
 #endif
 
+#define        GvASSIGN_GENERATION(gv)         (0 + ((XPV*) SvANY(gv))->xpv_cur)
+#define        GvASSIGN_GENERATION_set(gv,val)                 \
+       STMT_START { assert(SvTYPE(gv) == SVt_PVGV);    \
+               (((XPV*) SvANY(gv))->xpv_cur = (val)); } STMT_END
+
 /*
 =head1 GV Functions
 
diff --git a/op.c b/op.c
index d65bf16..70a2acf 100644 (file)
--- a/op.c
+++ b/op.c
@@ -3362,9 +3362,10 @@ Perl_newASSIGNOP(pTHX_ I32 flags, OP *left, I32 optype, OP *right)
                if (PL_opargs[curop->op_type] & OA_DANGEROUS) {
                    if (curop->op_type == OP_GV) {
                        GV *gv = cGVOPx_gv(curop);
-                       if (gv == PL_defgv || (int)SvCUR(gv) == PL_generation)
+                       if (gv == PL_defgv
+                           || (int)GvASSIGN_GENERATION(gv) == PL_generation)
                            break;
-                       SvCUR_set(gv, PL_generation);
+                       GvASSIGN_GENERATION_set(gv, PL_generation);
                    }
                    else if (curop->op_type == OP_PADSV ||
                             curop->op_type == OP_PADAV ||
@@ -3394,9 +3395,11 @@ Perl_newASSIGNOP(pTHX_ I32 flags, OP *left, I32 optype, OP *right)
 #else
                            GV *gv = (GV*)((PMOP*)curop)->op_pmreplroot;
 #endif
-                           if (gv == PL_defgv || (int)SvCUR(gv) == PL_generation)
+                           if (gv == PL_defgv
+                               || (int)GvASSIGN_GENERATION(gv) == PL_generation)
                                break;
-                           SvCUR_set(gv, PL_generation);
+                           GvASSIGN_GENERATION_set(gv, PL_generation);
+                           GvASSIGN_GENERATION_set(gv, PL_generation);
                        }
                    }
                    else