This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
ExtUtils-Constant is synced with version 0.25
[perl5.git] / hv.h
diff --git a/hv.h b/hv.h
index 16634b7..dcc6eb1 100644 (file)
--- a/hv.h
+++ b/hv.h
@@ -43,11 +43,17 @@ struct he {
 
 /* hash key -- defined separately for use as shared pointer */
 struct hek {
-    U32                hek_hash;       /* hash of key */
-    I32                hek_len;        /* length of hash key */
-    char        hek_flags;      /* The flags associated with this key */
-    char       hek_key[1];     /* variable-length hash key */
+    U32         hek_hash;        /* computed hash of key */
+    I32         hek_len;        /* length of the hash key */
+    /* Be careful! Sometimes we store a pointer in the hek_key
+     * buffer, which means it must be 8 byte aligned or things
+     * dont work on aligned platforms like HPUX
+     * Also beware, the last byte of the hek_key buffer is a
+     * hidden flags byte about the key. */
+     char       hek_key[1];        /* variable-length hash key */
     /* the hash-key is \0-terminated */
+    /* after the \0 there is a byte for flags, such as whether the key
+       is UTF-8 or WAS-UTF-8, or an SV */
 };
 
 struct shared_he {
@@ -319,7 +325,7 @@ C<SV*>.
    ((SvOOK(hv) && HvAUX(hv)->xhv_name_u.xhvnameu_name && HvAUX(hv)->xhv_name_count != -1) \
                                 ? HEK_UTF8(HvENAME_HEK_NN(hv)) : 0)
 
-/* the number of keys (including any placeholders) */
+/* the number of keys (including any placeholders) - NOT PART OF THE API */
 #define XHvTOTALKEYS(xhv)      ((xhv)->xhv_keys)
 
 /*
@@ -396,7 +402,7 @@ C<SV*>.
 #define HEK_HASH(hek)          (hek)->hek_hash
 #define HEK_LEN(hek)           (hek)->hek_len
 #define HEK_KEY(hek)           (hek)->hek_key
-#define HEK_FLAGS(hek)                (hek)->hek_flags
+#define HEK_FLAGS(hek) (*((unsigned char *)(HEK_KEY(hek))+HEK_LEN(hek)+1))
 
 #define HVhek_UTF8     0x01 /* Key is utf8 encoded. */
 #define HVhek_WASUTF8  0x02 /* Key is bytes here, but was supplied as utf8. */
@@ -455,8 +461,7 @@ C<SV*>.
                      (val), (hash)))
 
 #define hv_exists_ent(hv, keysv, hash)                                 \
-    (hv_common((hv), (keysv), NULL, 0, 0, HV_FETCH_ISEXISTS, 0, (hash))        \
-     ? TRUE : FALSE)
+    cBOOL(hv_common((hv), (keysv), NULL, 0, 0, HV_FETCH_ISEXISTS, 0, (hash)))
 #define hv_fetch_ent(hv, keysv, lval, hash)                            \
     ((HE *) hv_common((hv), (keysv), NULL, 0, 0,                       \
                      ((lval) ? HV_FETCH_LVALUE : 0), NULL, (hash)))
@@ -477,8 +482,7 @@ C<SV*>.
 
 
 #define hv_exists(hv, key, klen)                                       \
-    (hv_common_key_len((hv), (key), (klen), HV_FETCH_ISEXISTS, NULL, 0) \
-     ? TRUE : FALSE)
+    cBOOL(hv_common_key_len((hv), (key), (klen), HV_FETCH_ISEXISTS, NULL, 0))
 
 #define hv_fetch(hv, key, klen, lval)                                  \
     ((SV**) hv_common_key_len((hv), (key), (klen), (lval)              \
@@ -561,9 +565,9 @@ struct refcounted_he {
 };
 
 /*
-=for apidoc m|SV *|refcounted_he_fetch_pvs|const struct refcounted_he *chain|const char *key|U32 flags
+=for apidoc m|SV *|refcounted_he_fetch_pvs|const struct refcounted_he *chain|"literal string" key|U32 flags
 
-Like L</refcounted_he_fetch_pvn>, but takes a C<NUL>-terminated literal string
+Like L</refcounted_he_fetch_pvn>, but takes a literal string
 instead of a string/length pair, and no precomputed hash.
 
 =cut
@@ -573,9 +577,9 @@ instead of a string/length pair, and no precomputed hash.
     Perl_refcounted_he_fetch_pvn(aTHX_ chain, STR_WITH_LEN(key), 0, flags)
 
 /*
-=for apidoc m|struct refcounted_he *|refcounted_he_new_pvs|struct refcounted_he *parent|const char *key|SV *value|U32 flags
+=for apidoc m|struct refcounted_he *|refcounted_he_new_pvs|struct refcounted_he *parent|"literal string" key|SV *value|U32 flags
 
-Like L</refcounted_he_new_pvn>, but takes a C<NUL>-terminated literal string
+Like L</refcounted_he_new_pvn>, but takes a literal string
 instead of a string/length pair, and no precomputed hash.
 
 =cut