summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-10-07 11:43:17 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-10-07 11:43:17 (GMT)
commit2c31c3b45ed5ef3c2c0a2308957fb98334367cf4 (patch)
tree650931b359039b52c0e9f010957bf6ce21bea796 /string.c
parente2cabc22be830ac2a1871dc6c8107cbd759da7ab (diff)
string.c: fix non-embedded string
* string.c (rb_str_resurrect): fix resurrection of short enough to be embedded but not embedded string. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52073 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r--string.c27
1 files changed, 18 insertions, 9 deletions
diff --git a/string.c b/string.c
index a164c34..c2668d1 100644
--- a/string.c
+++ b/string.c
@@ -1250,27 +1250,36 @@ rb_str_dup(VALUE str)
VALUE
rb_str_resurrect(VALUE str)
{
+ enum {embed_size = RSTRING_EMBED_LEN_MAX + 1};
+ const VALUE flag_mask =
+ RSTRING_NOEMBED | RSTRING_EMBED_LEN_MASK |
+ ENC_CODERANGE_MASK | ENCODING_MASK |
+ FL_TAINT | FL_FREEZE
+ ;
+ VALUE flags = FL_TEST_RAW(str, flag_mask);
VALUE dup;
- VALUE flags = FL_TEST_RAW(str,
- RSTRING_NOEMBED |
- RSTRING_EMBED_LEN_MASK |
- ENC_CODERANGE_MASK |
- ENCODING_MASK |
- FL_TAINT | FL_FREEZE);
if (RUBY_DTRACE_STRING_CREATE_ENABLED()) {
RUBY_DTRACE_STRING_CREATE(RSTRING_LEN(str),
rb_sourcefile(), rb_sourceline());
}
dup = str_alloc(rb_cString);
- MEMCPY(RSTRING(dup)->as.ary, RSTRING(str)->as.ary, VALUE, 3);
+ MEMCPY(RSTRING(dup)->as.ary, RSTRING(str)->as.ary,
+ char, embed_size);
if (flags & STR_NOEMBED) {
if (UNLIKELY(!(flags & FL_FREEZE))) {
str = str_new_frozen(rb_cString, str);
FL_SET_RAW(str, flags & FL_TAINT);
+ flags = FL_TEST_RAW(str, flag_mask);
+ }
+ if (flags & STR_NOEMBED) {
+ RB_OBJ_WRITE(dup, &RSTRING(dup)->as.heap.aux.shared, str);
+ flags |= STR_SHARED;
+ }
+ else {
+ MEMCPY(RSTRING(dup)->as.ary, RSTRING(str)->as.ary,
+ char, embed_size);
}
- RB_OBJ_WRITE(dup, &RSTRING(dup)->as.heap.aux.shared, str);
- flags |= STR_SHARED;
}
FL_SET_RAW(dup, flags & ~FL_FREEZE);
return dup;