summaryrefslogtreecommitdiff
path: root/hv.h
diff options
context:
space:
mode:
authorNick Ing-Simmons <nik@tiuk.ti.com>2001-12-18 15:55:22 +0000
committerNick Ing-Simmons <nik@tiuk.ti.com>2001-12-18 15:55:22 +0000
commit8aacddc1ea3837f8f1a911d90c644451fc7cfc86 (patch)
tree6fd7ff4a46f0cbed519fe92c6244f38388482172 /hv.h
parent7b5d8bbce1bc254559797266031a88531cfece6b (diff)
downloadperl-8aacddc1ea3837f8f1a911d90c644451fc7cfc86.tar.gz
Tidied version of Jeffrey Friedl's <jfriedl@yahoo.com> restricted hashes
- added delete of READONLY value inhibit & test for same - re-tabbed p4raw-id: //depot/perlio@13760
Diffstat (limited to 'hv.h')
-rw-r--r--hv.h22
1 files changed, 21 insertions, 1 deletions
diff --git a/hv.h b/hv.h
index 3475c87238..f99bc7d1e8 100644
--- a/hv.h
+++ b/hv.h
@@ -33,6 +33,7 @@ struct xpvhv {
STRLEN xhv_max; /* subscript of last element of xhv_array */
IV xhv_keys; /* how many elements in the array */
NV xnv_nv; /* numeric value, if any */
+#define xhv_placeholders xnv_nv
MAGIC* xmg_magic; /* magic for scalar array */
HV* xmg_stash; /* class package */
@@ -126,12 +127,31 @@ C<SV*>.
#define HvARRAY(hv) (*(HE***)&((XPVHV*) SvANY(hv))->xhv_array)
#define HvFILL(hv) ((XPVHV*) SvANY(hv))->xhv_fill
#define HvMAX(hv) ((XPVHV*) SvANY(hv))->xhv_max
-#define HvKEYS(hv) ((XPVHV*) SvANY(hv))->xhv_keys
#define HvRITER(hv) ((XPVHV*) SvANY(hv))->xhv_riter
#define HvEITER(hv) ((XPVHV*) SvANY(hv))->xhv_eiter
#define HvPMROOT(hv) ((XPVHV*) SvANY(hv))->xhv_pmroot
#define HvNAME(hv) ((XPVHV*) SvANY(hv))->xhv_name
+/* the number of keys (including any placeholers) */
+#define XHvTOTALKEYS(xhv) ((xhv)->xhv_keys)
+
+/* The number of placeholders in the enumerated-keys hash */
+#define XHvPLACEHOLDERS(xhv) ((IV)((xhv)->xhv_placeholders))
+
+/* the number of keys that exist() (i.e. excluding placeholers) */
+#define XHvUSEDKEYS(xhv) (XHvTOTALKEYS(xhv) - XHvPLACEHOLDERS(xhv))
+
+/*
+ * HvKEYS gets the number of keys that actually exist(), and is provided
+ * for backwards compatibility with old XS code. The core uses HvUSEDKEYS
+ * (keys, excluding placeholdes) and HvTOTALKEYS (including placeholders)
+ */
+#define HvKEYS(hv) XHvUSEDKEYS((XPVHV*) SvANY(hv))
+#define HvUSEDKEYS(hv) XHvUSEDKEYS((XPVHV*) SvANY(hv))
+#define HvTOTALKEYS(hv) XHvTOTALKEYS((XPVHV*) SvANY(hv))
+#define HvPLACEHOLDERS(hv) XHvPLACEHOLDERS((XPVHV*) SvANY(hv))
+
+
#define HvSHAREKEYS(hv) (SvFLAGS(hv) & SVphv_SHAREKEYS)
#define HvSHAREKEYS_on(hv) (SvFLAGS(hv) |= SVphv_SHAREKEYS)
#define HvSHAREKEYS_off(hv) (SvFLAGS(hv) &= ~SVphv_SHAREKEYS)