This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Use xpv_len rather than xpv_cur in GVs to store GvASSIGN_GENERATION.
authorNicholas Clark <nick@ccl4.org>
Sat, 25 Feb 2006 16:50:15 +0000 (16:50 +0000)
committerNicholas Clark <nick@ccl4.org>
Sat, 25 Feb 2006 16:50:15 +0000 (16:50 +0000)
Assert that GVs do not access SvCUR or SvLEN.

p4raw-id: //depot/perl@27328

gv.h
sv.h

diff --git a/gv.h b/gv.h
index 81a42cf..27bef6c 100644 (file)
--- a/gv.h
+++ b/gv.h
@@ -63,10 +63,10 @@ struct gp {
 #  define GvNAMELEN(gv)        (GvXPVGV(gv)->xgv_namelen)
 #endif
 
-#define        GvASSIGN_GENERATION(gv)         (0 + ((XPV*) SvANY(gv))->xpv_cur)
+#define        GvASSIGN_GENERATION(gv)         (0 + ((XPV*) SvANY(gv))->xpv_len)
 #define        GvASSIGN_GENERATION_set(gv,val)                 \
        STMT_START { assert(SvTYPE(gv) == SVt_PVGV);    \
-               (((XPV*) SvANY(gv))->xpv_cur = (val)); } STMT_END
+               (((XPV*) SvANY(gv))->xpv_len = (val)); } STMT_END
 
 /*
 =head1 GV Functions
diff --git a/sv.h b/sv.h
index 7c098be..7445c76 100644 (file)
--- a/sv.h
+++ b/sv.h
@@ -1027,7 +1027,6 @@ in gv.h: */
 #    define SvSTASH(sv)        (0 + ((XPVMG*)  SvANY(sv))->xmg_stash)
 #  endif
 #else
-#  define SvCUR(sv) ((XPV*) SvANY(sv))->xpv_cur
 #  define SvLEN(sv) ((XPV*) SvANY(sv))->xpv_len
 #  define SvEND(sv) ((sv)->sv_u.svu_pv + ((XPV*)SvANY(sv))->xpv_cur)
 
@@ -1041,6 +1040,14 @@ in gv.h: */
            assert(!isGV_with_GP(_svi));                                \
            &((_svi)->sv_u.svu_pv);                                     \
         }))
+#    define SvCUR(sv)                                                  \
+       (*({ SV *const _svi = (SV *) sv;                                \
+           assert(SvTYPE(_svi) >= SVt_PV);                             \
+           assert(SvTYPE(_svi) != SVt_PVAV);                           \
+           assert(SvTYPE(_svi) != SVt_PVHV);                           \
+           assert(!isGV_with_GP(_svi));                                \
+           &(((XPV*) SvANY(_svi))->xpv_cur);                           \
+        }))
 #    define SvIVX(sv)                                                  \
        (*({ SV *const _svi = (SV *) sv;                                \
            assert(SvTYPE(_svi) == SVt_IV || SvTYPE(_svi) >= SVt_PVIV); \
@@ -1079,7 +1086,8 @@ in gv.h: */
            &(((XPVMG*) SvANY(_svi))->xmg_stash);                       \
          }))
 #  else
-#   define SvPVX(sv) ((sv)->sv_u.svu_pv)
+#    define SvPVX(sv) ((sv)->sv_u.svu_pv)
+#    define SvCUR(sv) ((XPV*) SvANY(sv))->xpv_cur
 #    define SvIVX(sv) ((XPVIV*) SvANY(sv))->xiv_iv
 #    define SvUVX(sv) ((XPVUV*) SvANY(sv))->xuv_uv
 #    define SvNVX(sv) ((XPVNV*) SvANY(sv))->xnv_u.xnv_nv
@@ -1116,19 +1124,24 @@ in gv.h: */
                (void) SvIV(sv); } STMT_END
 #define SvIV_set(sv, val) \
        STMT_START { assert(SvTYPE(sv) == SVt_IV || SvTYPE(sv) >= SVt_PVIV); \
+               assert(!isGV_with_GP(sv));              \
                (((XPVIV*)  SvANY(sv))->xiv_iv = (val)); } STMT_END
 #define SvNV_set(sv, val) \
        STMT_START { assert(SvTYPE(sv) == SVt_NV || SvTYPE(sv) >= SVt_PVNV); \
            assert(SvTYPE(sv) != SVt_PVAV); assert(SvTYPE(sv) != SVt_PVHV); \
+               assert(!isGV_with_GP(sv));              \
                (((XPVNV*)SvANY(sv))->xnv_u.xnv_nv = (val)); } STMT_END
 #define SvPV_set(sv, val) \
        STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
+               assert(!isGV_with_GP(sv));              \
                ((sv)->sv_u.svu_pv = (val)); } STMT_END
 #define SvUV_set(sv, val) \
        STMT_START { assert(SvTYPE(sv) == SVt_IV || SvTYPE(sv) >= SVt_PVIV); \
+               assert(!isGV_with_GP(sv));              \
                (((XPVUV*)SvANY(sv))->xuv_uv = (val)); } STMT_END
 #define SvRV_set(sv, val) \
         STMT_START { assert(SvTYPE(sv) >=  SVt_RV); \
+               assert(!isGV_with_GP(sv));              \
                 ((sv)->sv_u.svu_rv = (val)); } STMT_END
 #define SvMAGIC_set(sv, val) \
         STMT_START { assert(SvTYPE(sv) >= SVt_PVMG); \
@@ -1138,6 +1151,7 @@ in gv.h: */
                 (((XPVMG*)  SvANY(sv))->xmg_stash = (val)); } STMT_END
 #define SvCUR_set(sv, val) \
        STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
+               assert(!isGV_with_GP(sv));              \
                (((XPV*)  SvANY(sv))->xpv_cur = (val)); } STMT_END
 #define SvLEN_set(sv, val) \
        STMT_START { assert(SvTYPE(sv) >= SVt_PV); \