diff options
author | nagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-09-03 15:47:46 +0000 |
---|---|---|
committer | nagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-09-03 15:47:46 +0000 |
commit | aac5c2c7affaa188b84c4f9ccf8b21e83aa21141 (patch) | |
tree | 16185fdf700bce91563d3e1b49baaf86a0c8e3e5 | |
parent | 17fc590e089ad268d634c85cb7bf94a53a96d596 (diff) |
merge revision(s) r47217: [Backport #10062]
* 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/branches/ruby_2_1@47378 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | ext/thread/thread.c | 18 | ||||
-rw-r--r-- | test/thread/test_cv.rb | 6 | ||||
-rw-r--r-- | test/thread/test_queue.rb | 12 | ||||
-rw-r--r-- | version.h | 2 |
5 files changed, 38 insertions, 5 deletions
@@ -1,3 +1,8 @@ +Thu Sep 4 00:31: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] + Thu Sep 4 00:29:10 2014 Nobuyoshi Nakada <nobu@ruby-lang.org> * io.c (rb_io_initialize): [DOC] fix rdoc of append mode. it does diff --git a/ext/thread/thread.c b/ext/thread/thread.c index fa27708678..c3d81dc58d 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 f0d7c6d094..08459a0a04 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 c9481aa299..314ee98dab 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 @@ -1,6 +1,6 @@ #define RUBY_VERSION "2.1.2" #define RUBY_RELEASE_DATE "2014-09-04" -#define RUBY_PATCHLEVEL 221 +#define RUBY_PATCHLEVEL 222 #define RUBY_RELEASE_YEAR 2014 #define RUBY_RELEASE_MONTH 9 |