diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-08-19 01:13:24 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-08-19 01:13:24 +0000 |
commit | a198bb3929a4562a12b4aa245a297c7d3695149f (patch) | |
tree | 43f13b4c94e499e8b291cd1ce6d63d36cc268f2c /ext/thread | |
parent | 1d196e0d2bd99590d03a73d7e59aa87f7266f8e3 (diff) | |
download | ruby-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
Diffstat (limited to 'ext/thread')
-rw-r--r-- | ext/thread/thread.c | 18 |
1 files changed, 14 insertions, 4 deletions
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); |