+
+#define share_hek_hek(hek) \
+ (++(((struct shared_he *)(((char *)hek) \
+ - STRUCT_OFFSET(struct shared_he, \
+ shared_he_hek))) \
+ ->shared_he_he.he_valu.hent_refcount), \
+ hek)
+
+#define hv_store_ent(hv, keysv, val, hash) \
+ ((HE *) hv_common((hv), (keysv), NULL, 0, 0, HV_FETCH_ISSTORE, \
+ (val), (hash)))
+
+#define hv_exists_ent(hv, keysv, hash) \
+ (hv_common((hv), (keysv), NULL, 0, 0, HV_FETCH_ISEXISTS, 0, (hash)) \
+ ? TRUE : FALSE)
+#define hv_fetch_ent(hv, keysv, lval, hash) \
+ ((HE *) hv_common((hv), (keysv), NULL, 0, 0, \
+ ((lval) ? HV_FETCH_LVALUE : 0), NULL, (hash)))
+#define hv_delete_ent(hv, key, flags, hash) \
+ (MUTABLE_SV(hv_common((hv), (key), NULL, 0, 0, (flags) | HV_DELETE, \
+ NULL, (hash))))
+
+#define hv_store_flags(hv, key, klen, val, hash, flags) \
+ ((SV**) hv_common((hv), NULL, (key), (klen), (flags), \
+ (HV_FETCH_ISSTORE|HV_FETCH_JUST_SV), (val), \
+ (hash)))
+
+#define hv_store(hv, key, klen, val, hash) \
+ ((SV**) hv_common_key_len((hv), (key), (klen), \
+ (HV_FETCH_ISSTORE|HV_FETCH_JUST_SV), \
+ (val), (hash)))
+
+#define hv_exists(hv, key, klen) \
+ (hv_common_key_len((hv), (key), (klen), HV_FETCH_ISEXISTS, NULL, 0) \
+ ? TRUE : FALSE)
+
+#define hv_fetch(hv, key, klen, lval) \
+ ((SV**) hv_common_key_len((hv), (key), (klen), (lval) \
+ ? (HV_FETCH_JUST_SV | HV_FETCH_LVALUE) \
+ : HV_FETCH_JUST_SV, NULL, 0))
+
+#define hv_delete(hv, key, klen, flags) \
+ (MUTABLE_SV(hv_common_key_len((hv), (key), (klen), \
+ (flags) | HV_DELETE, NULL, 0)))
+
+/* This refcounted he structure is used for storing the hints used for lexical
+ pragmas. Without threads, it's basically struct he + refcount.
+ With threads, life gets more complex as the structure needs to be shared
+ between threads (because it hangs from OPs, which are shared), hence the
+ alternate definition and mutex. */
+
+struct refcounted_he;
+
+#ifdef PERL_CORE
+
+/* Gosh. This really isn't a good name any longer. */
+struct refcounted_he {
+ struct refcounted_he *refcounted_he_next; /* next entry in chain */
+#ifdef USE_ITHREADS
+ U32 refcounted_he_hash;
+ U32 refcounted_he_keylen;
+#else
+ HEK *refcounted_he_hek; /* hint key */
+#endif
+ union {
+ IV refcounted_he_u_iv;
+ UV refcounted_he_u_uv;
+ STRLEN refcounted_he_u_len;
+ void *refcounted_he_u_ptr; /* Might be useful in future */
+ } refcounted_he_val;
+ U32 refcounted_he_refcnt; /* reference count */
+ /* First byte is flags. Then NUL-terminated value. Then for ithreads,
+ non-NUL terminated key. */
+ char refcounted_he_data[1];
+};
+
+/* Flag bits are HVhek_UTF8, HVhek_WASUTF8, then */
+#define HVrhek_undef 0x00 /* Value is undef. */
+#define HVrhek_delete 0x10 /* Value is placeholder - signifies delete. */
+#define HVrhek_IV 0x20 /* Value is IV. */
+#define HVrhek_UV 0x30 /* Value is UV. */
+#define HVrhek_PV 0x40 /* Value is a (byte) string. */
+#define HVrhek_PV_UTF8 0x50 /* Value is a (utf8) string. */
+/* Two spare. As these have to live in the optree, you can't store anything
+ interpreter specific, such as SVs. :-( */
+#define HVrhek_typemask 0x70
+
+#ifdef USE_ITHREADS
+/* A big expression to find the key offset */
+#define REF_HE_KEY(chain) \
+ ((((chain->refcounted_he_data[0] & 0x60) == 0x40) \
+ ? chain->refcounted_he_val.refcounted_he_u_len + 1 : 0) \
+ + 1 + chain->refcounted_he_data)
+#endif
+
+# ifdef USE_ITHREADS
+# define HINTS_REFCNT_LOCK MUTEX_LOCK(&PL_hints_mutex)
+# define HINTS_REFCNT_UNLOCK MUTEX_UNLOCK(&PL_hints_mutex)
+# else
+# define HINTS_REFCNT_LOCK NOOP
+# define HINTS_REFCNT_UNLOCK NOOP
+# endif
+#endif
+
+#ifdef USE_ITHREADS
+# define HINTS_REFCNT_INIT MUTEX_INIT(&PL_hints_mutex)
+# define HINTS_REFCNT_TERM MUTEX_DESTROY(&PL_hints_mutex)
+#else
+# define HINTS_REFCNT_INIT NOOP
+# define HINTS_REFCNT_TERM NOOP
+#endif
+
+/* Hash actions
+ * Passed in PERL_MAGIC_uvar calls
+ */
+#define HV_DISABLE_UVAR_XKEY 0x01
+/* We need to ensure that these don't clash with G_DISCARD, which is 2, as it
+ is documented as being passed to hv_delete(). */
+#define HV_FETCH_ISSTORE 0x04
+#define HV_FETCH_ISEXISTS 0x08
+#define HV_FETCH_LVALUE 0x10
+#define HV_FETCH_JUST_SV 0x20
+#define HV_DELETE 0x40
+
+/*
+=for apidoc newHV
+
+Creates a new HV. The reference count is set to 1.
+
+=cut
+*/
+
+#define newHV() MUTABLE_HV(newSV_type(SVt_PVHV))
+
+/*
+ * Local variables:
+ * c-indentation-style: bsd
+ * c-basic-offset: 4
+ * indent-tabs-mode: t
+ * End:
+ *
+ * ex: set ts=8 sts=4 sw=4 noet:
+ */