aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog8
-rw-r--r--string.c7
2 files changed, 13 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 1e1b75b3fd..784c174ff2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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>
* ext/dl/handle.c (rb_dlhandle_s_sym): added a method to access
diff --git a/string.c b/string.c
index b714864474..3d864e54b5 100644
--- a/string.c
+++ b/string.c
@@ -5925,6 +5925,7 @@ rb_str_each_byte(VALUE str)
static VALUE
rb_str_each_char(VALUE str)
{
+ VALUE orig = str;
int i, len, n;
const char *ptr;
rb_encoding *enc;
@@ -5948,7 +5949,7 @@ rb_str_each_char(VALUE str)
rb_yield(rb_str_subseq(str, i, n));
}
}
- return str;
+ return orig;
}
/*
@@ -5984,6 +5985,7 @@ rb_str_each_char(VALUE str)
static VALUE
rb_str_each_codepoint(VALUE str)
{
+ VALUE orig = str;
int len, n;
unsigned int c;
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);
RETURN_ENUMERATOR(str, 0, 0);
+ str = rb_str_new4(str);
ptr = RSTRING_PTR(str);
len = RSTRING_LEN(str);
end = RSTRING_END(str);
@@ -6000,7 +6003,7 @@ rb_str_each_codepoint(VALUE str)
rb_yield(UINT2NUM(c));
ptr += n;
}
- return str;
+ return orig;
}
static long