ruby-changes:26024
From: kosaki <ko1@a...>
Date: Sat, 1 Dec 2012 02:42:50 +0900 (JST)
Subject: [ruby-changes:26024] kosaki:r38081 (trunk): * thread.c (rb_threadptr_interrupt_mask): add argument check.
kosaki 2012-12-01 02:39:48 +0900 (Sat, 01 Dec 2012) New Revision: 38081 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=38081 Log: * 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. Modified files: trunk/ChangeLog trunk/test/ruby/test_thread.rb trunk/thread.c Index: ChangeLog =================================================================== --- ChangeLog (revision 38080) +++ ChangeLog (revision 38081) @@ -1,3 +1,11 @@ +Sat Dec 1 02:11:47 2012 KOSAKI Motohiro <kosaki.motohiro@g...> + + * 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@g...> * lib/thread.rb (ConditionVariable#broadcast): protect from Index: thread.c =================================================================== --- thread.c (revision 38080) +++ thread.c (revision 38081) @@ -1545,12 +1545,27 @@ 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 rb_threadptr_interrupt_mask(rb_thread_t *th, VALUE mask, VALUE (*func)(rb_thread_t *th)) { VALUE r = Qnil; int state; + rb_hash_foreach(mask, async_interrupt_timing_arg_check_i, 0); rb_ary_push(th->async_errinfo_mask_stack, mask); if (!rb_threadptr_async_errinfo_empty_p(th)) { th->async_errinfo_queue_checked = 0; Index: test/ruby/test_thread.rb =================================================================== --- test/ruby/test_thread.rb (revision 38080) +++ test/ruby/test_thread.rb (revision 38081) @@ -714,6 +714,18 @@ # TODO: complex cases are needed. 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? q = Queue.new Thread.async_interrupt_timing(RuntimeError => :defer){ -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/