From a7db63208833d69ba02ef5ad21d32017f148bc46 Mon Sep 17 00:00:00 2001 From: ko1 Date: Fri, 21 Apr 2017 11:02:10 +0000 Subject: [PATCH] mark created frozen strings. * hash.c (rb_hash_new_from_values_with_klass): before this fix, only a st table are filled with passed values. However, newly created frozen strings are not marked correctly only reference from st table. This patch marks such created frozen strings by Hash object which refers to the st table. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58434 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- hash.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/hash.c b/hash.c index 45abacc861..b11b382bf1 100644 --- a/hash.c +++ b/hash.c @@ -639,8 +639,8 @@ hash_insert_raw(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; + (st_data_t)rb_str_new_frozen(key) : + (st_data_t)key; return st_insert(tbl, k, v); } @@ -650,19 +650,22 @@ rb_hash_new_from_values_with_klass(long argc, const VALUE *argv, VALUE klass) { long i; st_table *t; + VALUE v; if (argc % 2) { rb_raise(rb_eArgError, "odd number of arguments for Hash"); } t = st_init_table_with_size(&objhash, argc / 2); + v = hash_alloc_from_st(klass, t); + for (i = 0; i < argc; /* */) { VALUE key = argv[i++]; VALUE val = argv[i++]; hash_insert_raw(t, key, val); } - return hash_alloc_from_st(klass, t); + return v; } VALUE