Skip to content

Commit 645588b

Browse files
committed
merge revision(s) r47217: [Backport ruby#10062]
* ext/thread/thread.c (get_array): check instance variables are initialized properly. [ruby-core:63826][Bug ruby#10062] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_1@47378 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent 348e55c commit 645588b

File tree

5 files changed

+38
-5
lines changed

5 files changed

+38
-5
lines changed

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
Thu Sep 4 00:31:23 2014 Nobuyoshi Nakada <[email protected]>
2+
3+
* ext/thread/thread.c (get_array): check instance variables are
4+
initialized properly. [ruby-core:63826][Bug #10062]
5+
16
Thu Sep 4 00:29:10 2014 Nobuyoshi Nakada <[email protected]>
27

38
* io.c (rb_io_initialize): [DOC] fix rdoc of append mode. it does

ext/thread/thread.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,24 @@ enum {
1111
SZQUEUE_MAX = 3
1212
};
1313

14-
#define GET_CONDVAR_WAITERS(cv) RSTRUCT_GET((cv), CONDVAR_WAITERS)
14+
#define GET_CONDVAR_WAITERS(cv) get_array((cv), CONDVAR_WAITERS)
1515

16-
#define GET_QUEUE_QUE(q) RSTRUCT_GET((q), QUEUE_QUE)
17-
#define GET_QUEUE_WAITERS(q) RSTRUCT_GET((q), QUEUE_WAITERS)
18-
#define GET_SZQUEUE_WAITERS(q) RSTRUCT_GET((q), SZQUEUE_WAITERS)
16+
#define GET_QUEUE_QUE(q) get_array((q), QUEUE_QUE)
17+
#define GET_QUEUE_WAITERS(q) get_array((q), QUEUE_WAITERS)
18+
#define GET_SZQUEUE_WAITERS(q) get_array((q), SZQUEUE_WAITERS)
1919
#define GET_SZQUEUE_MAX(q) RSTRUCT_GET((q), SZQUEUE_MAX)
2020
#define GET_SZQUEUE_ULONGMAX(q) NUM2ULONG(GET_SZQUEUE_MAX(q))
2121

22+
static VALUE
23+
get_array(VALUE obj, int idx)
24+
{
25+
VALUE ary = RSTRUCT_GET(obj, idx);
26+
if (!RB_TYPE_P(ary, T_ARRAY)) {
27+
rb_raise(rb_eTypeError, "%+"PRIsVALUE" not initialized", obj);
28+
}
29+
return ary;
30+
}
31+
2232
static VALUE
2333
ary_buf_new(void)
2434
{

test/thread/test_cv.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
require_relative '../ruby/envutil'
55

66
class TestConditionVariable < Test::Unit::TestCase
7+
def test_initialized
8+
assert_raise(TypeError) {
9+
ConditionVariable.allocate.wait(nil)
10+
}
11+
end
12+
713
def test_condvar_signal_and_wait
814
mutex = Mutex.new
915
condvar = ConditionVariable.new

test/thread/test_queue.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@
55
require_relative '../ruby/envutil'
66

77
class TestQueue < Test::Unit::TestCase
8+
def test_queue_initialized
9+
assert_raise(TypeError) {
10+
Queue.allocate.push(nil)
11+
}
12+
end
13+
14+
def test_sized_queue_initialized
15+
assert_raise(TypeError) {
16+
SizedQueue.allocate.push(nil)
17+
}
18+
end
19+
820
def test_queue
921
grind(5, 1000, 15, Queue)
1022
end

version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#define RUBY_VERSION "2.1.2"
22
#define RUBY_RELEASE_DATE "2014-09-04"
3-
#define RUBY_PATCHLEVEL 221
3+
#define RUBY_PATCHLEVEL 222
44

55
#define RUBY_RELEASE_YEAR 2014
66
#define RUBY_RELEASE_MONTH 9

0 commit comments

Comments
 (0)