summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--hv.c3
-rw-r--r--hv.h5
-rw-r--r--perl.c12
3 files changed, 5 insertions, 15 deletions
diff --git a/hv.c b/hv.c
index de06148107..7659a6d945 100644
--- a/hv.c
+++ b/hv.c
@@ -80,7 +80,8 @@ 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 + 1, char);
+
+ Newx(k, HEK_BASESIZE + len + 2, char);
hek = (HEK*)k;
Copy(str, HEK_KEY(hek), len, char);
HEK_KEY(hek)[len] = 0;
diff --git a/hv.h b/hv.h
index 16634b7e44..ee536f08c8 100644
--- a/hv.h
+++ b/hv.h
@@ -45,9 +45,10 @@ 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 {
@@ -396,7 +397,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. */
diff --git a/perl.c b/perl.c
index 8fca566605..aa7d8b6080 100644
--- a/perl.c
+++ b/perl.c
@@ -322,18 +322,6 @@ 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() */