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

ruby-changes:35135

From: nobu <ko1@a...>
Date: Tue, 19 Aug 2014 10:13:39 +0900 (JST)
Subject: [ruby-changes:35135] nobu:r47217 (trunk): thread.c: check initialized

nobu	2014-08-19 10:13:24 +0900 (Tue, 19 Aug 2014)

  New Revision: 47217

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

  Log:
    thread.c: check initialized
    
    * ext/thread/thread.c (get_array): check instance variables are
      initialized properly.  [ruby-core:63826][Bug #10062]

  Modified files:
    trunk/ChangeLog
    trunk/ext/thread/thread.c
    trunk/test/thread/test_cv.rb
    trunk/test/thread/test_queue.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 47216)
+++ ChangeLog	(revision 47217)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Aug 19 10:13:23 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* ext/thread/thread.c (get_array): check instance variables are
+	  initialized properly.  [ruby-core:63826][Bug #10062]
+
 Mon Aug 18 17:06:27 2014  Nobuyoshi Nakada  <nobu@r...>
 
 	* sprintf.c (rb_str_format): support rational 'f' format.
Index: ext/thread/thread.c
===================================================================
--- ext/thread/thread.c	(revision 47216)
+++ ext/thread/thread.c	(revision 47217)
@@ -11,15 +11,25 @@ enum { https://github.com/ruby/ruby/blob/trunk/ext/thread/thread.c#L11
     SZQUEUE_MAX     = 3
 };
 
-#define GET_CONDVAR_WAITERS(cv) RSTRUCT_GET((cv), CONDVAR_WAITERS)
+#define GET_CONDVAR_WAITERS(cv) get_array((cv), CONDVAR_WAITERS)
 
-#define GET_QUEUE_QUE(q)        RSTRUCT_GET((q), QUEUE_QUE)
-#define GET_QUEUE_WAITERS(q)    RSTRUCT_GET((q), QUEUE_WAITERS)
-#define GET_SZQUEUE_WAITERS(q)  RSTRUCT_GET((q), SZQUEUE_WAITERS)
+#define GET_QUEUE_QUE(q)        get_array((q), QUEUE_QUE)
+#define GET_QUEUE_WAITERS(q)    get_array((q), QUEUE_WAITERS)
+#define GET_SZQUEUE_WAITERS(q)  get_array((q), SZQUEUE_WAITERS)
 #define GET_SZQUEUE_MAX(q)      RSTRUCT_GET((q), SZQUEUE_MAX)
 #define GET_SZQUEUE_ULONGMAX(q) NUM2ULONG(GET_SZQUEUE_MAX(q))
 
 static VALUE
+get_array(VALUE obj, int idx)
+{
+    VALUE ary = RSTRUCT_GET(obj, idx);
+    if (!RB_TYPE_P(ary, T_ARRAY)) {
+	rb_raise(rb_eTypeError, "%+"PRIsVALUE" not initialized", obj);
+    }
+    return ary;
+}
+
+static VALUE
 ary_buf_new(void)
 {
     return rb_ary_tmp_new(1);
Index: test/thread/test_queue.rb
===================================================================
--- test/thread/test_queue.rb	(revision 47216)
+++ test/thread/test_queue.rb	(revision 47217)
@@ -5,6 +5,18 @@ require 'timeout' https://github.com/ruby/ruby/blob/trunk/test/thread/test_queue.rb#L5
 require_relative '../ruby/envutil'
 
 class TestQueue < Test::Unit::TestCase
+  def test_queue_initialized
+    assert_raise(TypeError) {
+      Queue.allocate.push(nil)
+    }
+  end
+
+  def test_sized_queue_initialized
+    assert_raise(TypeError) {
+      SizedQueue.allocate.push(nil)
+    }
+  end
+
   def test_queue
     grind(5, 1000, 15, Queue)
   end
Index: test/thread/test_cv.rb
===================================================================
--- test/thread/test_cv.rb	(revision 47216)
+++ test/thread/test_cv.rb	(revision 47217)
@@ -4,6 +4,12 @@ require 'tmpdir' https://github.com/ruby/ruby/blob/trunk/test/thread/test_cv.rb#L4
 require_relative '../ruby/envutil'
 
 class TestConditionVariable < Test::Unit::TestCase
+  def test_initialized
+    assert_raise(TypeError) {
+      ConditionVariable.allocate.wait(nil)
+    }
+  end
+
   def test_condvar_signal_and_wait
     mutex = Mutex.new
     condvar = ConditionVariable.new

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

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