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

ruby-changes:34673

From: nobu <ko1@a...>
Date: Tue, 8 Jul 2014 17:04:31 +0900 (JST)
Subject: [ruby-changes:34673] nobu:r46756 (trunk): sprintf.c: skip non-interned name

nobu	2014-07-08 17:04:12 +0900 (Tue, 08 Jul 2014)

  New Revision: 46756

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

  Log:
    sprintf.c: skip non-interned name
    
    * sprintf.c (rb_str_format): get rid of accessing by symbol of
      invalid ID, when the name is not interned.

  Modified files:
    trunk/sprintf.c
Index: sprintf.c
===================================================================
--- sprintf.c	(revision 46755)
+++ sprintf.c	(revision 46756)
@@ -92,9 +92,9 @@ sign_bits(int base, const char *p) https://github.com/ruby/ruby/blob/trunk/sprintf.c#L92
 #define GETNTHARG(nth) \
     (((nth) >= argc) ? (rb_raise(rb_eArgError, "too few arguments"), 0) : argv[(nth)])
 
-#define GETNAMEARG(id, name, len, enc) ( \
+#define CHECKNAMEARG(name, len, enc) ( \
     check_name_arg(posarg, name, len, enc), \
-    (posarg = -2, rb_hash_lookup2(get_hash(&hash, argc, argv), (id), Qundef)))
+    posarg = -2)
 
 #define GETNUM(n, val) \
     (!(p = get_num(p, end, enc, &(n))) ? \
@@ -605,11 +605,12 @@ rb_str_format(int argc, const VALUE *arg https://github.com/ruby/ruby/blob/trunk/sprintf.c#L605
 		    rb_enc_raise(enc, rb_eArgError, "named%.*s after <%s>",
 				 len, start, rb_id2name(id));
 		}
-		nextvalue = GETNAMEARG((id = rb_check_id_cstr_without_pindown(start + 1,
-							      len - 2 /* without parenthesis */,
-							      enc),
-					ID2SYM(id)),
-				       start, len, enc);
+		CHECKNAMEARG(start, len, enc);
+		get_hash(&hash, argc, argv);
+		id = rb_check_id_cstr_without_pindown(start + 1,
+						      len - 2 /* without parenthesis */,
+						      enc);
+		if (id) nextvalue = rb_hash_lookup2(hash, ID2SYM(id), Qundef);
 		if (nextvalue == Qundef) {
 		    rb_enc_raise(enc, rb_eKeyError, "key%.*s not found", len, start);
 		}

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

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