This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
UTF-8 related macros in hv.h and gv.h
authorBrian Fraser <fraserbn@gmail.com>
Tue, 5 Jul 2011 03:12:02 +0000 (00:12 -0300)
committerFather Chrysostomos <sprout@cpan.org>
Thu, 6 Oct 2011 20:00:56 +0000 (13:00 -0700)
Groundwork for the following commits.

gv.h
hv.h

diff --git a/gv.h b/gv.h
index 6ef1c2b..6134ba4 100644 (file)
--- a/gv.h
+++ b/gv.h
@@ -56,6 +56,7 @@ struct gp {
         }))
 #  define GvNAME_get(gv)       ({ assert(GvNAME_HEK(gv)); (char *)HEK_KEY(GvNAME_HEK(gv)); })
 #  define GvNAMELEN_get(gv)    ({ assert(GvNAME_HEK(gv)); HEK_LEN(GvNAME_HEK(gv)); })
+#  define GvNAMEUTF8_get(gv)   ({ assert(GvNAME_HEK(gv)); HEK_UTF8(GvNAME_HEK(gv)); })
 #else
 #  define GvGP(gv)     (0+(gv)->sv_u.svu_gp)
 #  define GvGP_set(gv,gp)      ((gv)->sv_u.svu_gp = (gp))
@@ -64,10 +65,12 @@ struct gp {
 #  define GvNAME_HEK(gv)       (GvXPVGV(gv)->xiv_u.xivu_namehek)
 #  define GvNAME_get(gv)       HEK_KEY(GvNAME_HEK(gv))
 #  define GvNAMELEN_get(gv)    HEK_LEN(GvNAME_HEK(gv))
+#  define GvNAMEUTF8_get(gv)   HEK_UTF8(GvNAME_HEK(gv))
 #endif
 
 #define GvNAME(gv)     GvNAME_get(gv)
 #define GvNAMELEN(gv)  GvNAMELEN_get(gv)
+#define GvNAMEUTF8(gv) GvNAMEUTF8_get(gv)
 
 #define        GvASSIGN_GENERATION(gv)         (0 + ((XPV*) SvANY(gv))->xpv_len)
 #define        GvASSIGN_GENERATION_set(gv,val)                 \
@@ -133,6 +136,9 @@ Return the SV from the GV.
 #define GvEGV(gv)      (GvGP(gv)->gp_egv)
 #define GvEGVx(gv)     (isGV_with_GP(gv) ? GvEGV(gv) : NULL)
 #define GvENAME(gv)    GvNAME(GvEGV(gv) ? GvEGV(gv) : gv)
+#define GvENAMELEN(gv)  GvNAMELEN(GvEGV(gv) ? GvEGV(gv) : gv)
+#define GvENAMEUTF8(gv) GvNAMEUTF8(GvEGV(gv) ? GvEGV(gv) : gv)
+#define GvENAME_HEK(gv) GvNAME_HEK(GvEGV(gv) ? GvEGV(gv) : gv)
 #define GvESTASH(gv)   GvSTASH(GvEGV(gv) ? GvEGV(gv) : gv)
 
 #define GVf_INTRO      0x01
diff --git a/hv.h b/hv.h
index 358c8d8..f97f159 100644 (file)
--- a/hv.h
+++ b/hv.h
@@ -258,7 +258,11 @@ C<SV*>.
 #define HvRITER_get(hv)        (SvOOK(hv) ? HvAUX(hv)->xhv_riter : -1)
 #define HvEITER_get(hv)        (SvOOK(hv) ? HvAUX(hv)->xhv_eiter : NULL)
 #define HvNAME(hv)     HvNAME_get(hv)
+#define HvNAMELEN(hv)   HvNAMELEN_get(hv)
+#define HvNAMEUTF8(hv)  HvNAMEUTF8_get(hv)
 #define HvENAME(hv)    HvENAME_get(hv)
+#define HvENAMELEN(hv)  HvENAMELEN_get(hv)
+#define HvENAMEUTF8(hv) HvENAMEUTF8_get(hv)
 
 /* Checking that hv is a valid package stash is the
    caller's responsibility */
@@ -283,6 +287,9 @@ C<SV*>.
 #define HvNAMELEN_get(hv) \
        ((SvOOK(hv) && HvAUX(hv)->xhv_name_u.xhvnameu_name && HvNAME_HEK_NN(hv)) \
                                 ? HEK_LEN(HvNAME_HEK_NN(hv)) : 0)
+#define HvNAMEUTF8_get(hv) \
+       ((SvOOK(hv) && HvAUX(hv)->xhv_name_u.xhvnameu_name && HvNAME_HEK_NN(hv)) \
+                                ? HEK_UTF8(HvNAME_HEK_NN(hv)) : 0)
 #define HvENAME_HEK_NN(hv)                                             \
  (                                                                      \
   HvAUX(hv)->xhv_name_count > 0   ? HvAUX(hv)->xhv_name_u.xhvnameu_names[0] : \
@@ -298,6 +305,9 @@ C<SV*>.
 #define HvENAMELEN_get(hv) \
        ((SvOOK(hv) && HvAUX(hv)->xhv_name_u.xhvnameu_name && HvENAME_HEK_NN(hv)) \
                                 ? HEK_LEN(HvENAME_HEK_NN(hv)) : 0)
+#define HvENAMEUTF8_get(hv) \
+       ((SvOOK(hv) && HvAUX(hv)->xhv_name_u.xhvnameu_name && HvENAME_HEK_NN(hv)) \
+                                ? HEK_UTF8(HvENAME_HEK_NN(hv)) : 0)
 
 /* the number of keys (including any placeholders) */
 #define XHvTOTALKEYS(xhv)      ((xhv)->xhv_keys)