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

ruby-changes:36663

From: nobu <ko1@a...>
Date: Tue, 9 Dec 2014 10:16:35 +0900 (JST)
Subject: [ruby-changes:36663] nobu:r48744 (trunk): thread.c: get rid of invalid ID symbol

nobu	2014-12-09 10:16:27 +0900 (Tue, 09 Dec 2014)

  New Revision: 48744

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

  Log:
    thread.c: get rid of invalid ID symbol
    
    * eval.c (rb_frame_last_func): return the most recent frame method
      name.
    * thread.c (recursive_list_access): use the last method name,
      instead of the current method name which can be unset in some
      cases, not to use a symbol by the invalid ID.
      [ruby-core:66742] [Bug #10579]

  Modified files:
    trunk/ChangeLog
    trunk/eval.c
    trunk/test/ruby/test_objectspace.rb
    trunk/thread.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 48743)
+++ ChangeLog	(revision 48744)
@@ -1,3 +1,13 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Dec  9 10:16:24 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* eval.c (rb_frame_last_func): return the most recent frame method
+	  name.
+
+	* thread.c (recursive_list_access): use the last method name,
+	  instead of the current method name which can be unset in some
+	  cases, not to use a symbol by the invalid ID.
+	  [ruby-core:66742] [Bug #10579]
+
 Sun Dec  7 19:36:12 2014  Kazuki Tsujimoto  <kazuki@c...>
 
 	* ext/socket/basicsocket.c, ext/socket/sockssocket.c:
Index: thread.c
===================================================================
--- thread.c	(revision 48743)
+++ thread.c	(revision 48744)
@@ -4696,6 +4696,8 @@ threadptr_recursive_hash_set(rb_thread_t https://github.com/ruby/ruby/blob/trunk/thread.c#L4696
     th->local_storage_recursive_hash = hash;
 }
 
+ID rb_frame_last_func(void);
+
 /*
  * Returns the current "recursive list" used to detect recursion.
  * This list is a hash table, unique for the current thread and for
@@ -4707,7 +4709,8 @@ recursive_list_access(void) https://github.com/ruby/ruby/blob/trunk/thread.c#L4709
 {
     rb_thread_t *th = GET_THREAD();
     VALUE hash = threadptr_recursive_hash(th);
-    VALUE sym = ID2SYM(rb_frame_this_func());
+    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();
Index: eval.c
===================================================================
--- eval.c	(revision 48743)
+++ eval.c	(revision 48744)
@@ -1030,6 +1030,19 @@ prev_frame_func(void) https://github.com/ruby/ruby/blob/trunk/eval.c#L1030
     return frame_func_id(prev_cfp);
 }
 
+ID
+rb_frame_last_func(void)
+{
+    rb_thread_t *th = GET_THREAD();
+    rb_control_frame_t *cfp = th->cfp;
+    ID mid;
+
+    while (!(mid = frame_func_id(cfp)) &&
+	   (cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp),
+	    !RUBY_VM_CONTROL_FRAME_STACK_OVERFLOW_P(th, cfp)));
+    return mid;
+}
+
 /*
  *  call-seq:
  *     append_features(mod)   -> mod
Index: test/ruby/test_objectspace.rb
===================================================================
--- test/ruby/test_objectspace.rb	(revision 48743)
+++ test/ruby/test_objectspace.rb	(revision 48744)
@@ -102,4 +102,11 @@ End https://github.com/ruby/ruby/blob/trunk/test/ruby/test_objectspace.rb#L102
     }
     End
   end
+
+  def test_each_object_recursive_key
+    assert_normal_exit(<<-'end;', '[ruby-core:66742] [Bug #10579]')
+      h = {["foo"]=>nil}
+      p Thread.current[:__recursive_key__]
+    end;
+  end
 end

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

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