aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKazuki Yamaguchi <k@rhe.jp>2017-06-27 10:11:29 +0900
committerKazuki Yamaguchi <k@rhe.jp>2017-06-27 16:32:15 +0900
commita4d6d4c83b34f3967cffc6d25313f9d3156aa7b7 (patch)
treec97e188872462de2a36a7029462c53292ea85966
parent4376437c378e6a9f8a64cfa095dcedae1542cb4b (diff)
downloadruby-topic/string-expand-improvements.tar.gz
string.c: unset STR_SHARED and STR_NOFREE flags in #initializetopic/string-expand-improvements
-rw-r--r--string.c1
-rw-r--r--test/ruby/test_string.rb3
2 files changed, 4 insertions, 0 deletions
diff --git a/string.c b/string.c
index c5ef67a..994e52d 100644
--- a/string.c
+++ b/string.c
@@ -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 c3fd2b7..c83ea2a 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