diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-04-14 08:33:08 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-04-14 08:33:08 +0000 |
commit | cb52dda1469a81d9be2538b727137358f41b60f7 (patch) | |
tree | 726ddcbae6f424a857a086f0ecfe129152375d39 /include | |
parent | c50afaa1c94c150222d684fbc7fc8b79aa62e0c2 (diff) | |
download | ruby-cb52dda1469a81d9be2538b727137358f41b60f7.tar.gz |
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.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58350 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'include')
-rw-r--r-- | include/ruby/ruby.h | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h index d770c30735..01ab9e55cd 100644 --- a/include/ruby/ruby.h +++ b/include/ruby/ruby.h @@ -1742,6 +1742,27 @@ VALUE rb_check_symbol(volatile VALUE *namep); (__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 *argv, } #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 |