ruby-changes:46247
From: nobu <ko1@a...>
Date: Sat, 15 Apr 2017 11:09:31 +0900 (JST)
Subject: [ruby-changes:46247] nobu:r58362 (trunk): ruby.h: check argc to rb_funcall
nobu 2017-04-15 11:09:27 +0900 (Sat, 15 Apr 2017) New Revision: 58362 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=58362 Log: ruby.h: check argc to rb_funcall * include/ruby/ruby.h (rb_funcall): check if argc matches the number of variadic arguments, and replace with rb_funcallv. Modified files: trunk/error.c trunk/include/ruby/ruby.h trunk/numeric.c trunk/parse.y trunk/vm_eval.c Index: numeric.c =================================================================== --- numeric.c (revision 58361) +++ numeric.c (revision 58362) @@ -362,7 +362,7 @@ num_funcall_op_0(VALUE x, VALUE arg, int https://github.com/ruby/ruby/blob/trunk/numeric.c#L362 ID2SYM(func), x); } } - return rb_funcall(x, func, 0, 0); + return rb_funcallv(x, func, 0, 0); } static VALUE Index: parse.y =================================================================== --- parse.y (revision 58361) +++ parse.y (revision 58362) @@ -831,10 +831,18 @@ static ID id_warn, id_warning, id_gets; https://github.com/ruby/ruby/blob/trunk/parse.y#L831 # define PRIsWARN "s" # define WARN_ARGS(fmt,n) parser->value, id_warn, n, rb_usascii_str_new_lit(fmt) # define WARN_ARGS_L(l,fmt,n) WARN_ARGS(fmt,n) +# ifdef HAVE_VA_ARGS_MACRO +# define WARN_CALL(args,...) rb_funcall(args,__VA_ARGS__) +# else # define WARN_CALL rb_funcall +# endif # define WARNING_ARGS(fmt,n) parser->value, id_warning, n, rb_usascii_str_new_lit(fmt) # define WARNING_ARGS_L(l, fmt,n) WARNING_ARGS(fmt,n) +# ifdef HAVE_VA_ARGS_MACRO +# define WARNING_CALL(args,...) rb_funcall(args,__VA_ARGS__) +# else # define WARNING_CALL rb_funcall +# endif static void ripper_compile_error(struct parser_params*, const char *fmt, ...); # define compile_error ripper_compile_error # define PARSER_ARG parser, Index: error.c =================================================================== --- error.c (revision 58361) +++ error.c (revision 58362) @@ -963,7 +963,7 @@ rb_get_backtrace(VALUE exc) https://github.com/ruby/ruby/blob/trunk/error.c#L963 return Qnil; return rb_check_backtrace(info); } - return rb_funcall(exc, mid, 0, 0); + return rb_funcallv(exc, mid, 0, 0); } /* Index: vm_eval.c =================================================================== --- vm_eval.c (revision 58361) +++ vm_eval.c (revision 58362) @@ -804,6 +804,7 @@ rb_apply(VALUE recv, ID mid, VALUE args) https://github.com/ruby/ruby/blob/trunk/vm_eval.c#L804 return rb_call(recv, mid, argc, argv, CALL_FCALL); } +#undef rb_funcall /*! * Calls a method * \param recv receiver of the method Index: include/ruby/ruby.h =================================================================== --- include/ruby/ruby.h (revision 58361) +++ include/ruby/ruby.h (revision 58362) @@ -2450,6 +2450,17 @@ __extension__({ \ https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L2450 rb_varargs_argc_check(rb_yield_values_argc, rb_yield_values_nargs), \ rb_yield_values_args); \ }) + +# define rb_funcall(recv, mid, argc, ...) \ +__extension__({ \ + const int rb_funcall_argc = (argc); \ + const VALUE rb_funcall_args[] = {__VA_ARGS__}; \ + const int rb_funcall_nargs = \ + (int)(sizeof(rb_funcall_args) / sizeof(VALUE)); \ + rb_funcallv(recv, mid, \ + rb_varargs_argc_check(rb_funcall_argc, rb_funcall_nargs), \ + rb_funcall_args); \ + }) #endif #ifndef RUBY_DONT_SUBST -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/