зеркало из https://github.com/github/ruby.git
* enum.c (enum_join): deals with self recursive objects to get rid
of infinite recursion. [ruby-core:24150] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23966 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
e86d1ce77e
Коммит
def66ceca3
|
@ -1,3 +1,8 @@
|
|||
Mon Jul 6 09:04:45 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* enum.c (enum_join): deals with self recursive objects to get rid
|
||||
of infinite recursion. [ruby-core:24150]
|
||||
|
||||
Mon Jul 6 00:41:41 2009 Tadayoshi Funaba <tadf@dotrb.org>
|
||||
|
||||
* rational.c: edited rdoc.
|
||||
|
|
26
enum.c
26
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);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Загрузка…
Ссылка в новой задаче