From 5f5bc068ed7358be7975d0887d48d2c26e7f9847 Mon Sep 17 00:00:00 2001 From: ko1 Date: Fri, 21 Apr 2017 15:00:30 +0000 Subject: [PATCH] insert WB correctly. * hash.c (hash_insert_raw): should insert WB. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58435 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- hash.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/hash.c b/hash.c index b11b382bf1..6f983e6ee9 100644 --- a/hash.c +++ b/hash.c @@ -634,15 +634,19 @@ hash_alloc_from_st(VALUE klass, st_table *ntbl) return h; } -static inline int -hash_insert_raw(st_table *tbl, VALUE key, VALUE val) +static inline void +hash_insert_raw(VALUE hash, st_table *tbl, VALUE key, VALUE val) { st_data_t v = (st_data_t)val; st_data_t k = (rb_obj_class(key) == rb_cString) ? (st_data_t)rb_str_new_frozen(key) : (st_data_t)key; - return st_insert(tbl, k, v); + st_insert(tbl, k, v); + if (hash != Qfalse) { + RB_OBJ_WRITTEN(hash, Qundef, key); + RB_OBJ_WRITTEN(hash, Qundef, val); + } } static VALUE @@ -663,7 +667,7 @@ rb_hash_new_from_values_with_klass(long argc, const VALUE *argv, VALUE klass) VALUE key = argv[i++]; VALUE val = argv[i++]; - hash_insert_raw(t, key, val); + hash_insert_raw(v, t, key, val); } return v; } @@ -717,7 +721,7 @@ rb_hash_new_from_object(VALUE klass, VALUE obj) val = RARRAY_AREF(v, 1); case 1: key = RARRAY_AREF(v, 0); - hash_insert_raw(tbl, key, val); + hash_insert_raw(Qfalse, tbl, key, val); } } return hash_alloc_from_st(klass, tbl);