summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2014-12-23 22:28:33 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2014-12-23 22:28:33 +0900
commitbb3447173b52f6a24b2df1dba9fb93ddb48426bb (patch)
treebbec4d8771cc71c0f42f56675814ea84fea97614 /include
parent7f630d41ab7341daec4cf5c8eaabc1e1cc31bcc5 (diff)
downloadmruby-bb3447173b52f6a24b2df1dba9fb93ddb48426bb.tar.gz
mruby-bb3447173b52f6a24b2df1dba9fb93ddb48426bb.zip
khash.h: keep key/value table accessible from original hashtable during resize; fix #2682
Diffstat (limited to 'include')
-rw-r--r--include/mruby/khash.h11
1 files changed, 7 insertions, 4 deletions
diff --git a/include/mruby/khash.h b/include/mruby/khash.h
index 8a62e3ee6..6a4861bda 100644
--- a/include/mruby/khash.h
+++ b/include/mruby/khash.h
@@ -148,20 +148,23 @@ kh_fill_flags(uint8_t *p, uint8_t c, size_t len)
new_n_buckets = KHASH_MIN_SIZE; \
khash_power2(new_n_buckets); \
{ \
+ kh_##name##_t hh; \
uint8_t *old_ed_flags = h->ed_flags; \
khkey_t *old_keys = h->keys; \
khval_t *old_vals = h->vals; \
khint_t old_n_buckets = h->n_buckets; \
khint_t i; \
- h->n_buckets = new_n_buckets; \
- kh_alloc_##name(mrb, h); \
+ hh.n_buckets = new_n_buckets; \
+ kh_alloc_##name(mrb, &hh); \
/* relocate */ \
for (i=0 ; i<old_n_buckets ; i++) { \
if (!__ac_iseither(old_ed_flags, i)) { \
- khint_t k = kh_put_##name(mrb, h, old_keys[i], NULL); \
- if (kh_is_map) kh_value(h,k) = old_vals[i]; \
+ khint_t k = kh_put_##name(mrb, &hh, old_keys[i], NULL); \
+ if (kh_is_map) kh_value(&hh,k) = old_vals[i]; \
} \
} \
+ /* copy hh to h */ \
+ *h = hh; \
mrb_free(mrb, old_keys); \
} \
} \