diff options
-rw-r--r-- | hv.c | 3 | ||||
-rw-r--r-- | hv.h | 5 | ||||
-rw-r--r-- | perl.c | 12 |
3 files changed, 15 insertions, 5 deletions
@@ -80,8 +80,7 @@ S_save_hek_flags(const char *str, I32 len, U32 hash, int flags) HEK *hek; PERL_ARGS_ASSERT_SAVE_HEK_FLAGS; - - Newx(k, HEK_BASESIZE + len + 2, char); + Newx(k, HEK_BASESIZE + len + 1, char); hek = (HEK*)k; Copy(str, HEK_KEY(hek), len, char); HEK_KEY(hek)[len] = 0; @@ -45,10 +45,9 @@ struct he { 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 */ /* the hash-key is \0-terminated */ - /* after the \0 there is a byte for flags, such as whether the key - is UTF-8 */ }; struct shared_he { @@ -397,7 +396,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) (*((unsigned char *)(HEK_KEY(hek))+HEK_LEN(hek)+1)) +#define HEK_FLAGS(hek) (hek)->hek_flags #define HVhek_UTF8 0x01 /* Key is utf8 encoded. */ #define HVhek_WASUTF8 0x02 /* Key is bytes here, but was supplied as utf8. */ @@ -322,6 +322,18 @@ perl_construct(pTHXx) } #endif /* #if defined(USE_HASH_SEED) || defined(USE_HASH_SEED_EXPLICIT) */ + /* Afaik, this is good as anywhere else to assert + * that our HEK structure is properly sized. + * We expect that the char used for the flags is + * not padded and the bytes for the key continue right + * after. (For now, perhaps we should just make the flags + * a U32, and leave the beginning of key buffer aligned) + * - Yves + */ + STATIC_ASSERT_STMT( sizeof(((struct hek *)0)->hek_flags) == + (offsetof(struct hek, hek_key) + - offsetof(struct hek, hek_flags))); + /* Note that strtab is a rather special HV. Assumptions are made about not iterating on it, and not adding tie magic to it. It is properly deallocated in perl_destruct() */ |