diff options
author | Kazuki Yamaguchi <k@rhe.jp> | 2017-06-27 10:11:29 +0900 |
---|---|---|
committer | Kazuki Yamaguchi <k@rhe.jp> | 2017-06-27 16:32:15 +0900 |
commit | a4d6d4c83b34f3967cffc6d25313f9d3156aa7b7 (patch) | |
tree | c97e188872462de2a36a7029462c53292ea85966 | |
parent | 4376437c378e6a9f8a64cfa095dcedae1542cb4b (diff) | |
download | ruby-a4d6d4c83b34f3967cffc6d25313f9d3156aa7b7.tar.gz |
string.c: unset STR_SHARED and STR_NOFREE flags in #initializetopic/string-expand-improvements
-rw-r--r-- | string.c | 1 | ||||
-rw-r--r-- | test/ruby/test_string.rb | 3 |
2 files changed, 4 insertions, 0 deletions
@@ -1551,6 +1551,7 @@ rb_str_init(int argc, VALUE *argv, VALUE str) if (n == 1) { memcpy(RSTRING(str)->as.heap.ptr, RSTRING_PTR(orig), len); rb_enc_cr_str_exact_copy(str, orig); + FL_UNSET(str, STR_SHARED|STR_NOFREE); } FL_SET(str, STR_NOEMBED); RSTRING(str)->as.heap.aux.capa = capa; diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb index c3fd2b7d94..c83ea2a8b9 100644 --- a/test/ruby/test_string.rb +++ b/test/ruby/test_string.rb @@ -68,6 +68,9 @@ class TestString < Test::Unit::TestCase assert_raise(RuntimeError){ str.__send__(:initialize, encoding: 'euc-jp') } assert_raise(RuntimeError){ str.__send__(:initialize, 'abc', encoding: 'euc-jp') } assert_raise(RuntimeError){ str.__send__(:initialize, 'abc', capacity: 1000, encoding: 'euc-jp') } + + str = S("x"*40).freeze.dup # shared string + assert_equal("a", str.send(:initialize, "a", capacity: 1000).dup) end def test_initialize_nonstring |