ruby-changes:34578
From: nobu <ko1@a...>
Date: Wed, 2 Jul 2014 17:04:16 +0900 (JST)
Subject: [ruby-changes:34578] nobu:r46659 (trunk): sprintf.c: check_name_arg
nobu 2014-07-02 17:03:57 +0900 (Wed, 02 Jul 2014) New Revision: 46659 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=46659 Log: sprintf.c: check_name_arg * sprintf.c (check_name_arg): utility function for GETNAMEARG(). Modified files: trunk/sprintf.c Index: sprintf.c =================================================================== --- sprintf.c (revision 46658) +++ sprintf.c (revision 46659) @@ -93,10 +93,7 @@ sign_bits(int base, const char *p) https://github.com/ruby/ruby/blob/trunk/sprintf.c#L93 (((nth) >= argc) ? (rb_raise(rb_eArgError, "too few arguments"), 0) : argv[(nth)]) #define GETNAMEARG(id, name, len, enc) ( \ - posarg > 0 ? \ - (rb_enc_raise((enc), rb_eArgError, "named%.*s after unnumbered(%d)", (len), (name), posarg), 0) : \ - posarg == -1 ? \ - (rb_enc_raise((enc), rb_eArgError, "named%.*s after numbered", (len), (name)), 0) : \ + check_name_arg(posarg, name, len, enc), \ (posarg = -2, rb_hash_lookup2(get_hash(&hash, argc, argv), (id), Qundef))) #define GETNUM(n, val) \ @@ -161,6 +158,17 @@ check_pos_arg(int posarg, int n) https://github.com/ruby/ruby/blob/trunk/sprintf.c#L158 } } +static void +check_name_arg(int posarg, const char *name, int len, rb_encoding *enc) +{ + if (posarg > 0) { + rb_enc_raise(enc, rb_eArgError, "named%.*s after unnumbered(%d)", len, name, posarg); + } + if (posarg == -1) { + rb_enc_raise(enc, rb_eArgError, "named%.*s after numbered", len, name); + } +} + static VALUE get_hash(volatile VALUE *hash, int argc, const VALUE *argv) { -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/