summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-12-25 22:31:16 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-12-25 22:31:16 +0000
commitc8484fb3228eeac72497cd1003c2e601b767f785 (patch)
treee135de3ed28a8ab3555b6e388b4e870e75f52cb1 /string.c
parent5a7347a7bd6a7ee31f3a6d8b90e38e8bf3ac8421 (diff)
string.c: GC guard
* string.c (rb_str_enumerate_chars): prevent shared copy from GC. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38615 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r--string.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/string.c b/string.c
index 1e5dab37f1..e312c883e0 100644
--- a/string.c
+++ b/string.c
@@ -6389,6 +6389,7 @@ static VALUE
rb_str_enumerate_chars(VALUE str, int wantarray)
{
VALUE orig = str;
+ VALUE substr;
long i, len, n;
const char *ptr;
rb_encoding *enc;
@@ -6421,21 +6422,24 @@ rb_str_enumerate_chars(VALUE str, int wantarray)
case ENC_CODERANGE_7BIT:
for (i = 0; i < len; i += n) {
n = rb_enc_fast_mbclen(ptr + i, ptr + len, enc);
+ substr = rb_str_subseq(str, i, n);
if (wantarray)
- rb_ary_push(ary, rb_str_subseq(str, i, n));
+ rb_ary_push(ary, substr);
else
- rb_yield(rb_str_subseq(str, i, n));
+ rb_yield(substr);
}
break;
default:
for (i = 0; i < len; i += n) {
n = rb_enc_mbclen(ptr + i, ptr + len, enc);
+ substr = rb_str_subseq(str, i, n);
if (wantarray)
- rb_ary_push(ary, rb_str_subseq(str, i, n));
+ rb_ary_push(ary, substr);
else
- rb_yield(rb_str_subseq(str, i, n));
+ rb_yield(substr);
}
}
+ RB_GC_GUARD(str);
if (wantarray)
return ary;
else