summaryrefslogtreecommitdiffstats
path: root/enum.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-07-06 00:04:56 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-07-06 00:04:56 +0000
commit79e4999e648d15c6d64dee41dda17ee159ceb578 (patch)
tree7eb015702ddc11782652806d83263edd325e0b17 /enum.c
parent88b0c8c8bc85d785289e1d4e3dd3147d416ab6d7 (diff)
downloadruby-79e4999e648d15c6d64dee41dda17ee159ceb578.tar.gz
ruby-79e4999e648d15c6d64dee41dda17ee159ceb578.tar.xz
ruby-79e4999e648d15c6d64dee41dda17ee159ceb578.zip
* enum.c (enum_join): deals with self recursive objects to get rid
of infinite recursion. [ruby-core:24150] git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@23966 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'enum.c')
-rw-r--r--enum.c26
1 files changed, 25 insertions, 1 deletions
diff --git a/enum.c b/enum.c
index cc0883942..e5122903b 100644
--- a/enum.c
+++ b/enum.c
@@ -1803,6 +1803,30 @@ enum_cycle(int argc, VALUE *argv, VALUE obj)
return Qnil; /* not reached */
}
+static VALUE
+join_i(VALUE i, VALUE args, int argc, VALUE *argv)
+{
+ VALUE *arg = (VALUE *)args;
+ ENUM_WANT_SVALUE();
+ if (!arg[0]) {
+ arg[0] = rb_usascii_str_new(0, 0);
+ }
+ else if (!NIL_P(arg[1])) {
+ rb_str_buf_append(arg[0], arg[1]);
+ }
+ return rb_str_buf_append(arg[0], rb_obj_as_string(i));
+}
+
+VALUE
+rb_enum_join(VALUE obj, VALUE sep)
+{
+ VALUE args[2];
+ args[0] = 0;
+ args[1] = sep;
+ rb_block_call(obj, id_each, 0, 0, join_i, (VALUE)args);
+ return args[0] ? args[0] : rb_str_new(0, 0);
+}
+
/*
* call-seq:
* enum.join(sep=$,) -> str
@@ -1819,7 +1843,7 @@ enum_join(int argc, VALUE *argv, VALUE obj)
rb_scan_args(argc, argv, "01", &sep);
if (NIL_P(sep)) sep = rb_output_fs;
- return rb_ary_join(enum_to_a(0, 0, obj), sep);
+ return rb_enum_join(obj, sep);
}
/*