[前][次][番号順一覧][スレッド一覧]

ruby-changes:43051

From: nobu <ko1@a...>
Date: Mon, 23 May 2016 13:19:52 +0900 (JST)
Subject: [ruby-changes:43051] nobu:r55125 (trunk): make compile error if possible

nobu	2016-05-23 13:19:43 +0900 (Mon, 23 May 2016)

  New Revision: 55125

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=55125

  Log:
    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.

  Modified files:
    trunk/ChangeLog
    trunk/include/ruby/ruby.h
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 55124)
+++ ChangeLog	(revision 55125)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Mon May 23 13:19:41 2016  Nobuyoshi Nakada  <nobu@r...>
+
+	* 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.
+
 Mon May 23 12:47:09 2016  Nobuyoshi Nakada  <nobu@r...>
 
 	* include/ruby/ruby.h (rb_scan_args0): raise fatal error if
Index: include/ruby/ruby.h
===================================================================
--- include/ruby/ruby.h	(revision 55124)
+++ include/ruby/ruby.h	(revision 55125)
@@ -2155,6 +2155,14 @@ int ruby_vsnprintf(char *str, size_t n, https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L2155
     __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 *arg https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L2207
 	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;
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]