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

ruby-changes:36671

From: nobu <ko1@a...>
Date: Wed, 10 Dec 2014 09:38:58 +0900 (JST)
Subject: [ruby-changes:36671] nobu:r48752 (trunk): thread.c: use the same method name

nobu	2014-12-10 09:38:43 +0900 (Wed, 10 Dec 2014)

  New Revision: 48752

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

  Log:
    thread.c: use the same method name
    
    * thread.c (exec_recursive): use the same last method name as
      recursive_push in the error message when recursive_pop failed.
      [ruby-core:66742] [Bug #10579]

  Modified files:
    trunk/ChangeLog
    trunk/thread.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 48751)
+++ ChangeLog	(revision 48752)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Dec 10 09:38:40 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* thread.c (exec_recursive): use the same last method name as
+	  recursive_push in the error message when recursive_pop failed.
+	  [ruby-core:66742] [Bug #10579]
+
 Wed Dec 10 02:48:46 2014  NAKAMURA Usaku  <usa@r...>
 
 	* test/net/http/test_https.rb
Index: thread.c
===================================================================
--- thread.c	(revision 48751)
+++ thread.c	(revision 48752)
@@ -4705,12 +4705,10 @@ ID rb_frame_last_func(void); https://github.com/ruby/ruby/blob/trunk/thread.c#L4705
  */
 
 static VALUE
-recursive_list_access(void)
+recursive_list_access(VALUE sym)
 {
     rb_thread_t *th = GET_THREAD();
     VALUE hash = threadptr_recursive_hash(th);
-    ID mid = rb_frame_last_func();
-    VALUE sym = mid ? ID2SYM(mid) : ID2SYM(idNULL);
     VALUE list;
     if (NIL_P(hash) || !RB_TYPE_P(hash, T_HASH)) {
 	hash = ident_hash_new();
@@ -4798,25 +4796,23 @@ recursive_push(VALUE list, VALUE obj, VA https://github.com/ruby/ruby/blob/trunk/thread.c#L4796
  * Assumes the recursion list is valid.
  */
 
-static void
+static int
 recursive_pop(VALUE list, VALUE obj, VALUE paired_obj)
 {
     if (paired_obj) {
 	VALUE pair_list = rb_hash_lookup2(list, obj, Qundef);
 	if (pair_list == Qundef) {
-	    VALUE symname = rb_inspect(ID2SYM(rb_frame_this_func()));
-	    VALUE thrname = rb_inspect(rb_thread_current());
-	    rb_raise(rb_eTypeError, "invalid inspect_tbl pair_list for %s in %s",
-		     StringValuePtr(symname), StringValuePtr(thrname));
+	    return 0;
 	}
 	if (RB_TYPE_P(pair_list, T_HASH)) {
 	    rb_hash_delete(pair_list, paired_obj);
 	    if (!RHASH_EMPTY_P(pair_list)) {
-		return; /* keep hash until is empty */
+		return 1; /* keep hash until is empty */
 	    }
 	}
     }
     rb_hash_delete(list, obj);
+    return 1;
 }
 
 struct exec_recursive_params {
@@ -4850,9 +4846,11 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/thread.c#L4846
 exec_recursive(VALUE (*func) (VALUE, VALUE, int), VALUE obj, VALUE pairid, VALUE arg, int outer)
 {
     VALUE result = Qundef;
+    const ID mid = rb_frame_last_func();
+    const VALUE sym = mid ? ID2SYM(mid) : ID2SYM(idNULL);
     struct exec_recursive_params p;
     int outermost;
-    p.list = recursive_list_access();
+    p.list = recursive_list_access(sym);
     p.objid = rb_obj_id(obj);
     p.obj = obj;
     p.pairid = pairid;
@@ -4874,8 +4872,8 @@ exec_recursive(VALUE (*func) (VALUE, VAL https://github.com/ruby/ruby/blob/trunk/thread.c#L4872
 	    recursive_push(p.list, ID2SYM(recursive_key), 0);
 	    recursive_push(p.list, p.objid, p.pairid);
 	    result = rb_catch_protect(p.list, exec_recursive_i, (VALUE)&p, &state);
-	    recursive_pop(p.list, p.objid, p.pairid);
-	    recursive_pop(p.list, ID2SYM(recursive_key), 0);
+	    if (!recursive_pop(p.list, p.objid, p.pairid)) goto invalid;
+	    if (!recursive_pop(p.list, ID2SYM(recursive_key), 0)) goto invalid;
 	    if (state) JUMP_TAG(state);
 	    if (result == p.list) {
 		result = (*func)(obj, arg, TRUE);
@@ -4888,7 +4886,12 @@ exec_recursive(VALUE (*func) (VALUE, VAL https://github.com/ruby/ruby/blob/trunk/thread.c#L4886
 		result = (*func)(obj, arg, FALSE);
 	    }
 	    POP_TAG();
-	    recursive_pop(p.list, p.objid, p.pairid);
+	    if (!recursive_pop(p.list, p.objid, p.pairid)) {
+	      invalid:
+		rb_raise(rb_eTypeError, "invalid inspect_tbl pair_list "
+			 "for %+"PRIsVALUE" in %+"PRIsVALUE,
+			 sym, rb_thread_current());
+	    }
 	    if (state) JUMP_TAG(state);
 	}
     }

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

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