Provide Perl_gv_name_set to replace LVALUE use of GvNAME and GvNAMESET.
Nicholas Clark [Sun, 5 Mar 2006 11:53:55 +0000 (11:53 +0000)]
p4raw-id: //depot/perl@27377

embed.fnc
embed.h
global.sym
gv.c
gv.h
proto.h
sv.c

index cdb03c7..6282514 100644 (file)
--- a/embed.fnc
+++ b/embed.fnc
@@ -278,6 +278,7 @@ Ap  |void   |gv_fullname    |NN SV* sv|NN const GV* gv
 Apmb   |void   |gv_fullname3   |NN SV* sv|NN const GV* gv|NULLOK const char* prefix
 Ap     |void   |gv_fullname4   |NN SV* sv|NN const GV* gv|NULLOK const char* prefix|bool keepmain
 Ap     |void   |gv_init        |NN GV* gv|NULLOK HV* stash|NN const char* name|STRLEN len|int multi
+Ap     |void   |gv_name_set    |NN GV* gv|NULLOK const char *name|U32 len|U32 flags
 Apd    |HV*    |gv_stashpv     |NN const char* name|I32 create
 Apd    |HV*    |gv_stashpvn    |NN const char* name|U32 namelen|I32 create
 Apd    |HV*    |gv_stashsv     |NULLOK SV* sv|I32 create
diff --git a/embed.h b/embed.h
index b1777d5..2a759e6 100644 (file)
--- a/embed.h
+++ b/embed.h
 #define gv_fullname            Perl_gv_fullname
 #define gv_fullname4           Perl_gv_fullname4
 #define gv_init                        Perl_gv_init
+#define gv_name_set            Perl_gv_name_set
 #define gv_stashpv             Perl_gv_stashpv
 #define gv_stashpvn            Perl_gv_stashpvn
 #define gv_stashsv             Perl_gv_stashsv
 #define gv_fullname(a,b)       Perl_gv_fullname(aTHX_ a,b)
 #define gv_fullname4(a,b,c,d)  Perl_gv_fullname4(aTHX_ a,b,c,d)
 #define gv_init(a,b,c,d,e)     Perl_gv_init(aTHX_ a,b,c,d,e)
+#define gv_name_set(a,b,c,d)   Perl_gv_name_set(aTHX_ a,b,c,d)
 #define gv_stashpv(a,b)                Perl_gv_stashpv(aTHX_ a,b)
 #define gv_stashpvn(a,b,c)     Perl_gv_stashpvn(aTHX_ a,b,c)
 #define gv_stashsv(a,b)                Perl_gv_stashsv(aTHX_ a,b)
index a0ad6b2..222af6d 100644 (file)
@@ -140,6 +140,7 @@ Perl_gv_fullname
 Perl_gv_fullname3
 Perl_gv_fullname4
 Perl_gv_init
+Perl_gv_name_set
 Perl_gv_stashpv
 Perl_gv_stashpvn
 Perl_gv_stashsv
diff --git a/gv.c b/gv.c
index 00fed57..f6c2087 100644 (file)
--- a/gv.c
+++ b/gv.c
@@ -215,8 +215,7 @@ Perl_gv_init(pTHX_ GV *gv, HV *stash, const char *name, STRLEN len, int multi)
     GvSTASH(gv) = stash;
     if (stash)
        Perl_sv_add_backref(aTHX_ (SV*)stash, (SV*)gv);
-    GvNAME(gv) = savepvn(name, len);
-    GvNAMELEN(gv) = len;
+    gv_name_set(gv, name, len, 0);
     if (multi || doproto)              /* doproto means it _was_ mentioned */
        GvMULTI_on(gv);
     if (doproto) {                     /* Replicate part of newSUB here. */
@@ -2104,6 +2103,17 @@ Perl_is_gv_magical(pTHX_ const char *name, STRLEN len, U32 flags)
     return FALSE;
 }
 
+void
+Perl_gv_name_set(pTHX_ GV *gv, const char *name, U32 len, U32 flags)
+{
+    dVAR;
+
+    PERL_UNUSED_ARG(flags);
+
+    GvXPVGV(gv)->xgv_name = name ? savepvn(name, len) : NULL;
+    GvXPVGV(gv)->xgv_namelen = len;
+}
+
 /*
  * Local variables:
  * c-indentation-style: bsd
diff --git a/gv.h b/gv.h
index 22916df..de8ec52 100644 (file)
--- a/gv.h
+++ b/gv.h
@@ -43,26 +43,29 @@ struct gp {
            assert(SvTYPE(_gv) == SVt_PVGV || SvTYPE(_gv) >= SVt_PVLV); \
            &(GvXPVGV(_gv)->xnv_u.xgv_stash);                           \
         }))
-#  define GvNAME(gv)                                                   \
-       (*({ GV * const zzzz = (GV *) (gv);                             \
-           assert(isGV_with_GP(zzzz));                                 \
-           assert(SvTYPE(zzzz) == SVt_PVGV || SvTYPE(zzzz) >= SVt_PVLV); \
-           &(GvXPVGV(zzzz)->xgv_name);                                 \
-        }))
-#  define GvNAMELEN(gv)                                                        \
-       (*({ GV * const glank = (GV *) (gv);                            \
-           assert(isGV_with_GP(glank));                                \
-           assert(SvTYPE(glank) == SVt_PVGV || SvTYPE(glank) >= SVt_PVLV); \
-           &(GvXPVGV(glank)->xgv_namelen);                             \
-        }))
+#  define GvNAME_get(gv)                                               \
+       ({ GV * const zzzz = (GV *) (gv);                               \
+          assert(isGV_with_GP(zzzz));                                  \
+          assert(SvTYPE(zzzz) == SVt_PVGV || SvTYPE(zzzz) >= SVt_PVLV); \
+          0 + (GvXPVGV(zzzz)->xgv_name);                               \
+        })
+#  define GvNAMELEN_get(gv)                                            \
+       ({ GV * const glank = (GV *) (gv);                              \
+          assert(isGV_with_GP(glank));                         \
+          assert(SvTYPE(glank) == SVt_PVGV || SvTYPE(glank) >= SVt_PVLV); \
+          0 + (GvXPVGV(glank)->xgv_namelen);                           \
+        })
 #else
 #  define GvGP(gv)     ((gv)->sv_u.svu_gp)
 #  define GvFLAGS(gv)  (GvXPVGV(gv)->xpv_cur)
 #  define GvSTASH(gv)  (GvXPVGV(gv)->xnv_u.xgv_stash)
-#  define GvNAME(gv)   (GvXPVGV(gv)->xgv_name)
-#  define GvNAMELEN(gv)        (GvXPVGV(gv)->xgv_namelen)
+#  define GvNAME_get(gv)       (0 + GvXPVGV(gv)->xgv_name)
+#  define GvNAMELEN_get(gv)    (0 + GvXPVGV(gv)->xgv_namelen)
 #endif
 
+#define GvNAME(gv)     GvNAME_get(gv)
+#define GvNAMELEN(gv)  GvNAMELEN_get(gv)
+
 #define        GvASSIGN_GENERATION(gv)         (0 + ((XPV*) SvANY(gv))->xpv_len)
 #define        GvASSIGN_GENERATION_set(gv,val)                 \
        STMT_START { assert(SvTYPE(gv) == SVt_PVGV);    \
diff --git a/proto.h b/proto.h
index c465601..94718f2 100644 (file)
--- a/proto.h
+++ b/proto.h
@@ -644,6 +644,9 @@ PERL_CALLCONV void  Perl_gv_init(pTHX_ GV* gv, HV* stash, const char* name, STRLE
                        __attribute__nonnull__(pTHX_1)
                        __attribute__nonnull__(pTHX_3);
 
+PERL_CALLCONV void     Perl_gv_name_set(pTHX_ GV* gv, const char *name, U32 len, U32 flags)
+                       __attribute__nonnull__(pTHX_1);
+
 PERL_CALLCONV HV*      Perl_gv_stashpv(pTHX_ const char* name, I32 create)
                        __attribute__nonnull__(pTHX_1);
 
diff --git a/sv.c b/sv.c
index 5f25704..74e6a8b 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -3216,8 +3216,7 @@ S_glob_assign_glob(pTHX_ SV *dstr, SV *sstr, const int dtype)
        GvSTASH(dstr) = GvSTASH(sstr);
        if (GvSTASH(dstr))
            Perl_sv_add_backref(aTHX_ (SV*)GvSTASH(dstr), dstr);
-       GvNAME(dstr) = savepvn(name, len);
-       GvNAMELEN(dstr) = len;
+       gv_name_set(dstr, name, len, 0);
        SvFAKE_on(dstr);        /* can coerce to non-glob */
     }
 
@@ -9837,7 +9836,8 @@ Perl_sv_dup(pTHX_ const SV *sstr, CLONE_PARAMS* param)
                    LvTARG(dstr) = sv_dup_inc(LvTARG(dstr), param);
                break;
            case SVt_PVGV:
-               GvNAME(dstr)    = SAVEPVN(GvNAME(dstr), GvNAMELEN(dstr));
+               GvXPVGV(dstr)->xgv_name = SAVEPVN(GvNAME(dstr), GvNAMELEN(dstr));
+
                /* Don't call sv_add_backref here as it's going to be created
                   as part of the magic cloning of the symbol table.  */
                GvSTASH(dstr)   = hv_dup(GvSTASH(dstr), param);