summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-02-12 10:42:36 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-02-12 10:42:36 +0000
commite52da919872f8cf71c90a27b470cef724204eece (patch)
tree2d425228fcba503e2f0a82726548f477cefc5da0 /string.c
parent48149dff328079a25b9f17d47999a513b14389c6 (diff)
downloadruby-e52da919872f8cf71c90a27b470cef724204eece.tar.gz
* compile.c (compile_array_, defined_expr, iseq_compile_each): hide
and freeze internal literal objects, to prevent from modifying. [ruby-dev:37959] * iseq.c (insn_operand_intern): copy internal literal objects. * insns.def (putstring, duparray): ditto. * string.c (rb_str_replace): exported. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22255 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r--string.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/string.c b/string.c
index 802e9379bf..8eb83efcec 100644
--- a/string.c
+++ b/string.c
@@ -815,14 +815,18 @@ rb_obj_as_string(VALUE obj)
return str;
}
-static VALUE rb_str_replace(VALUE, VALUE);
+static VALUE
+str_duplicate(VALUE klass, VALUE str)
+{
+ VALUE dup = str_alloc(klass);
+ rb_str_replace(dup, str);
+ return dup;
+}
VALUE
rb_str_dup(VALUE str)
{
- VALUE dup = str_alloc(rb_obj_class(str));
- rb_str_replace(dup, str);
- return dup;
+ return str_duplicate(rb_obj_class(str), str);
}
@@ -3722,7 +3726,7 @@ rb_str_gsub(int argc, VALUE *argv, VALUE str)
* s.replace "world" #=> "world"
*/
-static VALUE
+VALUE
rb_str_replace(VALUE str, VALUE str2)
{
long len;
@@ -4024,9 +4028,7 @@ static VALUE
rb_str_to_s(VALUE str)
{
if (rb_obj_class(str) != rb_cString) {
- VALUE dup = str_alloc(rb_cString);
- rb_str_replace(dup, str);
- return dup;
+ return str_duplicate(rb_cString, str);
}
return str;
}