summaryrefslogtreecommitdiff
path: root/hv.h
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2010-10-27 09:44:04 -0700
committerFather Chrysostomos <sprout@cpan.org>2010-10-27 09:45:26 -0700
commit78b79c7758384edd69ba966d2f0571855acb1117 (patch)
tree5804749f02e2f3d1440bc78bd3c684d31ff72202 /hv.h
parent13d356f324d3ac73ad7eb9e627a33e3fa89132ec (diff)
downloadperl-78b79c7758384edd69ba966d2f0571855acb1117.tar.gz
Renaming of stashes should not be visible from Perl
Change 35759254 made stashes get renamed when moved around. This had an unintended consequence: Typeglobs, ref() return values, stringifi- cation of blessed references and __PACKAGE__ are all affected by this. This commit makes a new distinction between stashes’ names and effect- ive names. Stash names are now unaffected when the stashes move around. Only the effective names are affected. (The apparent presence of any puns in the previous sentence is purely incidental and most likely the result of the reader’s inferential propensity.) To this end a new HvENAME_get macro is introduced, returning the first effective name (what HvNAME_get was returning). (Only one effective name needs to be in effect at a time.) hv_add_name and hv_delete_name have been renamed hv_add_ename and hv_delete_ename. hv_name_set is modified to leave the effective names in place unless the name is being set to NULL. These names are now stored in HvAUX as follows: When xhv_name_count is 0, xhv_name is a HEK pointer, containing the name which is also the effective name. When xhv_name_count is not zero, then xhv_name is a pointer to an array of HEK pointers. If xhv_name_count is positive, the first HEK is the name *and* one of the effective names. When xhv_name_count is negative, the first HEK is the name and subsequent HEKs are the effective names.
Diffstat (limited to 'hv.h')
-rw-r--r--hv.h32
1 files changed, 27 insertions, 5 deletions
diff --git a/hv.h b/hv.h
index 3e4040c168..655be9ae38 100644
--- a/hv.h
+++ b/hv.h
@@ -79,9 +79,14 @@ struct xpvhv_aux {
HE *xhv_eiter; /* current entry of iterator */
I32 xhv_riter; /* current root of iterator */
struct mro_meta *xhv_mro_meta;
- U32 xhv_name_count; /* When non-zero, xhv_name is actually */
- /* a pointer to an array of HEKs, this */
-}; /* being the length. */
+/* Concerning xhv_name_count: When non-zero, xhv_name is actually a pointer
+ * to an array of HEK pointers, this being the length. The first element is
+ * the name of the stash, which may be NULL. If xhv_name_count is positive,
+ * then *xhv_name is one of the effective names. If xhv_name_count is nega-
+ * tive, then xhv_name[1] is the first effective name.
+ */
+ I32 xhv_name_count;
+};
/* hash structure: */
/* This structure must match the beginning of struct xpvmg in sv.h. */
@@ -267,10 +272,27 @@ C<SV*>.
/* This macro may go away without notice. */
#define HvNAME_HEK(hv) \
(SvOOK(hv) && HvAUX(hv)->xhv_name ? HvNAME_HEK_NN(hv) : NULL)
-#define HvNAME_get(hv) ((SvOOK(hv) && (HvAUX(hv)->xhv_name)) \
+#define HvNAME_get(hv) \
+ ((SvOOK(hv) && (HvAUX(hv)->xhv_name) && HvNAME_HEK_NN(hv)) \
? HEK_KEY(HvNAME_HEK_NN(hv)) : NULL)
-#define HvNAMELEN_get(hv) ((SvOOK(hv) && (HvAUX(hv)->xhv_name)) \
+#define HvNAMELEN_get(hv) \
+ ((SvOOK(hv) && (HvAUX(hv)->xhv_name) && HvNAME_HEK_NN(hv)) \
? HEK_LEN(HvNAME_HEK_NN(hv)) : 0)
+#ifdef PERL_CORE
+# define HvENAME_HEK_NN(hv) \
+ ( \
+ HvAUX(hv)->xhv_name_count > 0 ? *(HEK **)HvAUX(hv)->xhv_name : \
+ HvAUX(hv)->xhv_name_count < -1 ? ((HEK **)HvAUX(hv)->xhv_name)[1] : \
+ HvAUX(hv)->xhv_name_count == -1 ? NULL : \
+ HvAUX(hv)->xhv_name \
+ )
+# define HvENAME_get(hv) \
+ ((SvOOK(hv) && (HvAUX(hv)->xhv_name) && HvENAME_HEK_NN(hv)) \
+ ? HEK_KEY(HvENAME_HEK_NN(hv)) : NULL)
+# define HvENAMELEN_get(hv) \
+ ((SvOOK(hv) && (HvAUX(hv)->xhv_name) && HvENAME_HEK_NN(hv)) \
+ ? HEK_LEN(HvENAME_HEK_NN(hv)) : 0)
+#endif
/* the number of keys (including any placeholers) */
#define XHvTOTALKEYS(xhv) ((xhv)->xhv_keys)