diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-05-23 04:19:43 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-05-23 04:19:43 +0000 |
commit | a6144809eb6a71e31392b08cf75fd543bc85f5c7 (patch) | |
tree | f11684bfe9379e19ac091f58acc1ce770dcd761d /include/ruby | |
parent | 14c43e2be6d356fa49ebd39885786bf6d3c6e4c1 (diff) | |
download | ruby-a6144809eb6a71e31392b08cf75fd543bc85f5c7.tar.gz |
make compile error if possible
* include/ruby/ruby.h (rb_scan_args0): make compile error if the
format is wrong or does not match with the variable argument
length if possible.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55125 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'include/ruby')
-rw-r--r-- | include/ruby/ruby.h | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h index 10c220d3a2..7e8532485e 100644 --- a/include/ruby/ruby.h +++ b/include/ruby/ruby.h @@ -2155,6 +2155,14 @@ int ruby_vsnprintf(char *str, size_t n, char const *fmt, va_list ap); __builtin_choose_expr(__builtin_constant_p(fmt), \ rb_scan_args0(argc,argv,fmt,(sizeof((VALUE*[]){__VA_ARGS__})/sizeof(VALUE*)),(VALUE*[]){__VA_ARGS__}), \ rb_scan_args(argc,argvp,fmt,__VA_ARGS__)) +# if GCC_VERSION_SINCE(4, 4, 0) +void rb_scan_args_bad_format(const char*) __attribute__((error("bad scan arg format"))); +void rb_scan_args_length_mismatch(int, int) __attribute__((error("variable argument length doesn't match"))); +# else +# define rb_scan_args_bad_format(fmt) rb_fatal("bad scan arg format: %s", fmt) +# define rb_scan_args_length_mismatch(vari, varc) rb_fatal("variable argument length doesn't match: %d %d", vari, varc) +# endif + ALWAYS_INLINE(static int rb_scan_args0(int argc, const VALUE *argv, const char *fmt, int varc, VALUE *vars[])); inline int @@ -2199,13 +2207,13 @@ rb_scan_args0(int argc, const VALUE *argv, const char *fmt, int varc, VALUE *var p++; } if (*p != '\0') { - rb_fatal("bad scan arg format: %s", fmt); + rb_scan_args_bad_format(fmt); } n_mand = n_lead + n_trail; vari = n_mand + n_opt + f_var + f_hash + f_block; if (vari != varc) { - rb_fatal("variable argument length doesn't match* %d %d", vari, varc); + rb_scan_args_length_mismatch(vari, varc); } vari = 0; |