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

ruby-changes:34576

From: nobu <ko1@a...>
Date: Wed, 2 Jul 2014 17:04:09 +0900 (JST)
Subject: [ruby-changes:34576] nobu:r46658 (trunk): sprintf.c: check_pos_arg

nobu	2014-07-02 17:03:53 +0900 (Wed, 02 Jul 2014)

  New Revision: 46658

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

  Log:
    sprintf.c: check_pos_arg
    
    * sprintf.c (check_pos_arg): utility function for GETPOSARG().

  Modified files:
    trunk/sprintf.c
Index: sprintf.c
===================================================================
--- sprintf.c	(revision 46657)
+++ sprintf.c	(revision 46658)
@@ -85,12 +85,9 @@ sign_bits(int base, const char *p) https://github.com/ruby/ruby/blob/trunk/sprintf.c#L85
     check_next_arg(posarg, nextarg), \
     (posarg = nextarg++, GETNTHARG(posarg)))
 
-#define GETPOSARG(n) (posarg > 0 ? \
-    (rb_raise(rb_eArgError, "numbered(%d) after unnumbered(%d)", (n), posarg), 0) : \
-    posarg == -2 ? \
-    (rb_raise(rb_eArgError, "numbered(%d) after named", (n)), 0) : \
-    (((n) < 1) ? (rb_raise(rb_eArgError, "invalid index - %d$", (n)), 0) : \
-	       (posarg = -1, GETNTHARG(n))))
+#define GETPOSARG(n) ( \
+    check_pos_arg(posarg, (n)), \
+    (posarg = -1, GETNTHARG(n)))
 
 #define GETNTHARG(nth) \
     (((nth) >= argc) ? (rb_raise(rb_eArgError, "too few arguments"), 0) : argv[(nth)])
@@ -150,6 +147,20 @@ check_next_arg(int posarg, int nextarg) https://github.com/ruby/ruby/blob/trunk/sprintf.c#L147
     }
 }
 
+static void
+check_pos_arg(int posarg, int n)
+{
+    if (posarg > 0) {
+	rb_raise(rb_eArgError, "numbered(%d) after unnumbered(%d)", n, posarg);
+    }
+    if (posarg == -2) {
+	rb_raise(rb_eArgError, "numbered(%d) after named", n);
+    }
+    if (n < 1) {
+	rb_raise(rb_eArgError, "invalid index - %d$", n);
+    }
+}
+
 static VALUE
 get_hash(volatile VALUE *hash, int argc, const VALUE *argv)
 {

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

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