aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-08-19 01:13:24 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-08-19 01:13:24 +0000
commita198bb3929a4562a12b4aa245a297c7d3695149f (patch)
tree43f13b4c94e499e8b291cd1ce6d63d36cc268f2c
parent1d196e0d2bd99590d03a73d7e59aa87f7266f8e3 (diff)
downloadruby-a198bb3929a4562a12b4aa245a297c7d3695149f.tar.gz
thread.c: check initialized
* ext/thread/thread.c (get_array): check instance variables are initialized properly. [ruby-core:63826][Bug #10062] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47217 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--ext/thread/thread.c18
-rw-r--r--test/thread/test_cv.rb6
-rw-r--r--test/thread/test_queue.rb12
4 files changed, 37 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 7417a98d2d..aea3500cb5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Tue Aug 19 10:13:23 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * 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@ruby-lang.org>
* sprintf.c (rb_str_format): support rational 'f' format.
diff --git a/ext/thread/thread.c b/ext/thread/thread.c
index 09ece03f25..c14443b06c 100644
--- a/ext/thread/thread.c
+++ b/ext/thread/thread.c
@@ -11,15 +11,25 @@ enum {
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);
diff --git a/test/thread/test_cv.rb b/test/thread/test_cv.rb
index 49fee24249..db6067e71c 100644
--- a/test/thread/test_cv.rb
+++ b/test/thread/test_cv.rb
@@ -4,6 +4,12 @@ require 'tmpdir'
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
diff --git a/test/thread/test_queue.rb b/test/thread/test_queue.rb
index b886fcc27a..6a3397734a 100644
--- a/test/thread/test_queue.rb
+++ b/test/thread/test_queue.rb
@@ -5,6 +5,18 @@ require 'timeout'
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