ruby-changes:46235
From: nobu <ko1@a...>
Date: Fri, 14 Apr 2017 17:33:14 +0900 (JST)
Subject: [ruby-changes:46235] nobu:r58350 (trunk): ruby.h: check argc to rb_yield_values
nobu 2017-04-14 17:33:08 +0900 (Fri, 14 Apr 2017) New Revision: 58350 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=58350 Log: ruby.h: check argc to rb_yield_values * include/ruby/ruby.h (rb_yield_values): check if argc matches the number of variadic arguments, and replace with rb_yield_values2. Modified files: trunk/include/ruby/ruby.h trunk/vm_eval.c Index: vm_eval.c =================================================================== --- vm_eval.c (revision 58349) +++ vm_eval.c (revision 58350) @@ -1023,6 +1023,7 @@ rb_yield(VALUE val) https://github.com/ruby/ruby/blob/trunk/vm_eval.c#L1023 } } +#undef rb_yield_values VALUE rb_yield_values(int n, ...) { Index: include/ruby/ruby.h =================================================================== --- include/ruby/ruby.h (revision 58349) +++ include/ruby/ruby.h (revision 58350) @@ -1742,6 +1742,27 @@ VALUE rb_check_symbol(volatile VALUE *na https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L1742 (__builtin_constant_p(str) ? \ __extension__ (rb_intern2((str), (long)strlen(str))) : \ (rb_intern)(str)) + +# define rb_varargs_argc_check_runtime(argc, vargc) \ + (((argc) <= (vargc)) ? (argc) : \ + (rb_fatal("argc(%d) exceeds actual arguments(%d)", \ + argc, vargc), 0)) +# if defined(HAVE_BUILTIN___BUILTIN_CHOOSE_EXPR_CONSTANT_P) +# if HAVE_ATTRIBUTE_ERRORFUNC +ERRORFUNC((" argument length doesn't match"), int rb_varargs_bad_length(int,int)); +# else +# define rb_varargs_bad_length(argc, vargc) ((argc)/((argc) == (vargc))) +# endif +# define rb_varargs_argc_check(argc, vargc) \ + __builtin_choose_expr(__builtin_constant_p(argc), \ + (((argc) == (vargc)) ? (argc) : \ + rb_varargs_bad_length(argc, vargc)), \ + rb_varargs_argc_check_runtime(argc, vargc)) +# else +# define rb_varargs_argc_check(argc, vargc) \ + rb_varargs_argc_check_runtime(argc, vargc) +# endif + #else #define rb_intern_const(str) rb_intern2((str), (long)strlen(str)) #endif @@ -2418,6 +2439,19 @@ rb_scan_args_set(int argc, const VALUE * https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L2439 } #endif +#if defined(__GNUC__) && defined(__OPTIMIZE__) +# define rb_yield_values(argc, ...) \ +__extension__({ \ + const int rb_yield_values_argc = (argc); \ + const VALUE rb_yield_values_args[] = {__VA_ARGS__}; \ + const int rb_yield_values_nargs = \ + (int)(sizeof(rb_yield_values_args) / sizeof(VALUE)); \ + rb_yield_values2( \ + rb_varargs_argc_check(rb_yield_values_argc, rb_yield_values_nargs), \ + rb_yield_values_args); \ + }) +#endif + #ifndef RUBY_DONT_SUBST #include "ruby/subst.h" #endif -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/