* string.c (rb_str_each_char): return original string.

[ruby-core:23499]

* string.c (rb_str_each_codepoint): protect string from
  modification.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23552 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2009-05-23 15:59:09 +00:00
parent 34cf45ab19
commit 0fd3bdac6a
2 changed files with 13 additions and 2 deletions

View File

@ -1,3 +1,11 @@
Sat May 23 23:52:33 2009 Yukihiro Matsumoto <matz@ruby-lang.org>
* string.c (rb_str_each_char): return original string.
[ruby-core:23499]
* string.c (rb_str_each_codepoint): protect string from
modification.
Sat May 23 21:48:58 2009 Nobuyoshi Nakada <nobu@ruby-lang.org> Sat May 23 21:48:58 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/dl/handle.c (rb_dlhandle_s_sym): added a method to access * ext/dl/handle.c (rb_dlhandle_s_sym): added a method to access

View File

@ -5925,6 +5925,7 @@ rb_str_each_byte(VALUE str)
static VALUE static VALUE
rb_str_each_char(VALUE str) rb_str_each_char(VALUE str)
{ {
VALUE orig = str;
int i, len, n; int i, len, n;
const char *ptr; const char *ptr;
rb_encoding *enc; rb_encoding *enc;
@ -5948,7 +5949,7 @@ rb_str_each_char(VALUE str)
rb_yield(rb_str_subseq(str, i, n)); rb_yield(rb_str_subseq(str, i, n));
} }
} }
return str; return orig;
} }
/* /*
@ -5984,6 +5985,7 @@ rb_str_each_char(VALUE str)
static VALUE static VALUE
rb_str_each_codepoint(VALUE str) rb_str_each_codepoint(VALUE str)
{ {
VALUE orig = str;
int len, n; int len, n;
unsigned int c; unsigned int c;
const char *ptr, *end; const char *ptr, *end;
@ -5991,6 +5993,7 @@ rb_str_each_codepoint(VALUE str)
if (single_byte_optimizable(str)) return rb_str_each_byte(str); if (single_byte_optimizable(str)) return rb_str_each_byte(str);
RETURN_ENUMERATOR(str, 0, 0); RETURN_ENUMERATOR(str, 0, 0);
str = rb_str_new4(str);
ptr = RSTRING_PTR(str); ptr = RSTRING_PTR(str);
len = RSTRING_LEN(str); len = RSTRING_LEN(str);
end = RSTRING_END(str); end = RSTRING_END(str);
@ -6000,7 +6003,7 @@ rb_str_each_codepoint(VALUE str)
rb_yield(UINT2NUM(c)); rb_yield(UINT2NUM(c));
ptr += n; ptr += n;
} }
return str; return orig;
} }
static long static long