* thread.c (rb_threadptr_interrupt_mask): add argument check.
* thread.c (async_interrupt_timing_arg_check_i): helper function for the above. * test/ruby/test_thread.rb (test_async_interrupt_timing_invalid_argument): test for the above. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38081 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
6ca32179e6
commit
279cd29b1b
@ -1,3 +1,11 @@
|
|||||||
|
Sat Dec 1 02:11:47 2012 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
|
||||||
|
|
||||||
|
* thread.c (rb_threadptr_interrupt_mask): add argument check.
|
||||||
|
* thread.c (async_interrupt_timing_arg_check_i): helper function
|
||||||
|
for the above.
|
||||||
|
* test/ruby/test_thread.rb (test_async_interrupt_timing_invalid_argument):
|
||||||
|
test for the above.
|
||||||
|
|
||||||
Sat Dec 1 01:19:34 2012 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
|
Sat Dec 1 01:19:34 2012 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
|
||||||
|
|
||||||
* lib/thread.rb (ConditionVariable#broadcast): protect from
|
* lib/thread.rb (ConditionVariable#broadcast): protect from
|
||||||
|
@ -714,6 +714,18 @@ class TestThread < Test::Unit::TestCase
|
|||||||
# TODO: complex cases are needed.
|
# TODO: complex cases are needed.
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_async_interrupt_timing_invalid_argument
|
||||||
|
assert_raise(ArgumentError) {
|
||||||
|
Thread.async_interrupt_timing(RuntimeError => :immediate) # no block
|
||||||
|
}
|
||||||
|
assert_raise(ArgumentError) {
|
||||||
|
Thread.async_interrupt_timing(RuntimeError => :never) {} # never?
|
||||||
|
}
|
||||||
|
assert_raise(TypeError) {
|
||||||
|
Thread.async_interrupt_timing([]) {} # array
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
def test_async_interrupted?
|
def test_async_interrupted?
|
||||||
q = Queue.new
|
q = Queue.new
|
||||||
Thread.async_interrupt_timing(RuntimeError => :defer){
|
Thread.async_interrupt_timing(RuntimeError => :defer){
|
||||||
|
15
thread.c
15
thread.c
@ -1545,12 +1545,27 @@ rb_threadptr_async_errinfo_active_p(rb_thread_t *th)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
async_interrupt_timing_arg_check_i(VALUE key, VALUE val)
|
||||||
|
{
|
||||||
|
VALUE immediate = ID2SYM(rb_intern("immediate"));
|
||||||
|
VALUE on_blocking = ID2SYM(rb_intern("on_blocking"));
|
||||||
|
VALUE defer = ID2SYM(rb_intern("defer"));
|
||||||
|
|
||||||
|
if (val != immediate && val != on_blocking && val != defer) {
|
||||||
|
rb_raise(rb_eArgError, "unknown mask signature");
|
||||||
|
}
|
||||||
|
|
||||||
|
return ST_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
rb_threadptr_interrupt_mask(rb_thread_t *th, VALUE mask, VALUE (*func)(rb_thread_t *th))
|
rb_threadptr_interrupt_mask(rb_thread_t *th, VALUE mask, VALUE (*func)(rb_thread_t *th))
|
||||||
{
|
{
|
||||||
VALUE r = Qnil;
|
VALUE r = Qnil;
|
||||||
int state;
|
int state;
|
||||||
|
|
||||||
|
rb_hash_foreach(mask, async_interrupt_timing_arg_check_i, 0);
|
||||||
rb_ary_push(th->async_errinfo_mask_stack, mask);
|
rb_ary_push(th->async_errinfo_mask_stack, mask);
|
||||||
if (!rb_threadptr_async_errinfo_empty_p(th)) {
|
if (!rb_threadptr_async_errinfo_empty_p(th)) {
|
||||||
th->async_errinfo_queue_checked = 0;
|
th->async_errinfo_queue_checked = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user