1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* enum.c (DEFINE_ENUMFUNCS): included function signature.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23980 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2009-07-07 04:36:50 +00:00
parent e895bc3cdb
commit 0f2d1527ab
2 changed files with 19 additions and 22 deletions

View file

@ -1,4 +1,6 @@
Tue Jul 7 13:34:30 2009 Nobuyoshi Nakada <nobu@ruby-lang.org> Tue Jul 7 13:36:46 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
* enum.c (DEFINE_ENUMFUNCS): included function signature.
* enum.c (rb_enum_join): non-nil separator must be convertible to * enum.c (rb_enum_join): non-nil separator must be convertible to
String. [ruby-core:24172] String. [ruby-core:24172]

37
enum.c
View file

@ -823,7 +823,11 @@ enum_sort_by(VALUE obj)
return ary; return ary;
} }
#define ENUMFUNC(name) rb_block_given_p() ? name##_iter_i : name##_i
#define DEFINE_ENUMFUNCS(name) \ #define DEFINE_ENUMFUNCS(name) \
static VALUE enum_##name##_func(VALUE result, VALUE *memo); \
\
static VALUE \ static VALUE \
name##_i(VALUE i, VALUE *memo, int argc, VALUE *argv) \ name##_i(VALUE i, VALUE *memo, int argc, VALUE *argv) \
{ \ { \
@ -834,10 +838,12 @@ static VALUE \
name##_iter_i(VALUE i, VALUE *memo, int argc, VALUE *argv) \ name##_iter_i(VALUE i, VALUE *memo, int argc, VALUE *argv) \
{ \ { \
return enum_##name##_func(enum_yield(argc, argv), memo); \ return enum_##name##_func(enum_yield(argc, argv), memo); \
} } \
\
static VALUE \
enum_##name##_func(VALUE result, VALUE *memo)
static VALUE DEFINE_ENUMFUNCS(all)
enum_all_func(VALUE result, VALUE *memo)
{ {
if (!RTEST(result)) { if (!RTEST(result)) {
*memo = Qfalse; *memo = Qfalse;
@ -846,8 +852,6 @@ enum_all_func(VALUE result, VALUE *memo)
return Qnil; return Qnil;
} }
DEFINE_ENUMFUNCS(all)
/* /*
* call-seq: * call-seq:
* enum.all? [{|obj| block } ] => true or false * enum.all? [{|obj| block } ] => true or false
@ -870,12 +874,11 @@ enum_all(VALUE obj)
{ {
VALUE result = Qtrue; VALUE result = Qtrue;
rb_block_call(obj, id_each, 0, 0, rb_block_given_p() ? all_iter_i : all_i, (VALUE)&result); rb_block_call(obj, id_each, 0, 0, ENUMFUNC(all), (VALUE)&result);
return result; return result;
} }
static VALUE DEFINE_ENUMFUNCS(any)
enum_any_func(VALUE result, VALUE *memo)
{ {
if (RTEST(result)) { if (RTEST(result)) {
*memo = Qtrue; *memo = Qtrue;
@ -884,8 +887,6 @@ enum_any_func(VALUE result, VALUE *memo)
return Qnil; return Qnil;
} }
DEFINE_ENUMFUNCS(any)
/* /*
* call-seq: * call-seq:
* enum.any? [{|obj| block } ] => true or false * enum.any? [{|obj| block } ] => true or false
@ -909,12 +910,11 @@ enum_any(VALUE obj)
{ {
VALUE result = Qfalse; VALUE result = Qfalse;
rb_block_call(obj, id_each, 0, 0, rb_block_given_p() ? any_iter_i : any_i, (VALUE)&result); rb_block_call(obj, id_each, 0, 0, ENUMFUNC(any), (VALUE)&result);
return result; return result;
} }
static VALUE DEFINE_ENUMFUNCS(one)
enum_one_func(VALUE result, VALUE *memo)
{ {
if (RTEST(result)) { if (RTEST(result)) {
if (*memo == Qundef) { if (*memo == Qundef) {
@ -928,8 +928,6 @@ enum_one_func(VALUE result, VALUE *memo)
return Qnil; return Qnil;
} }
DEFINE_ENUMFUNCS(one)
/* /*
* call-seq: * call-seq:
* enum.one? [{|obj| block }] => true or false * enum.one? [{|obj| block }] => true or false
@ -953,13 +951,12 @@ enum_one(VALUE obj)
{ {
VALUE result = Qundef; VALUE result = Qundef;
rb_block_call(obj, id_each, 0, 0, rb_block_given_p() ? one_iter_i : one_i, (VALUE)&result); rb_block_call(obj, id_each, 0, 0, ENUMFUNC(one), (VALUE)&result);
if (result == Qundef) return Qfalse; if (result == Qundef) return Qfalse;
return result; return result;
} }
static VALUE DEFINE_ENUMFUNCS(none)
enum_none_func(VALUE result, VALUE *memo)
{ {
if (RTEST(result)) { if (RTEST(result)) {
*memo = Qfalse; *memo = Qfalse;
@ -968,8 +965,6 @@ enum_none_func(VALUE result, VALUE *memo)
return Qnil; return Qnil;
} }
DEFINE_ENUMFUNCS(none)
/* /*
* call-seq: * call-seq:
* enum.none? [{|obj| block }] => true or false * enum.none? [{|obj| block }] => true or false
@ -990,7 +985,7 @@ enum_none(VALUE obj)
{ {
VALUE result = Qtrue; VALUE result = Qtrue;
rb_block_call(obj, id_each, 0, 0, rb_block_given_p() ? none_iter_i : none_i, (VALUE)&result); rb_block_call(obj, id_each, 0, 0, ENUMFUNC(none), (VALUE)&result);
return result; return result;
} }