ruby-changes:33344
From: nobu <ko1@a...>
Date: Wed, 26 Mar 2014 11:20:31 +0900 (JST)
Subject: [ruby-changes:33344] nobu:r45423 (trunk): thread.c: undumpable
nobu 2014-03-26 11:20:26 +0900 (Wed, 26 Mar 2014) New Revision: 45423 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=45423 Log: thread.c: undumpable * ext/thread/thread.c (undumpable): ConditionVariable and Queue are not dumpable. [ruby-core:61677] [Bug #9674] Modified files: trunk/ChangeLog trunk/ext/thread/thread.c trunk/test/thread/test_cv.rb trunk/test/thread/test_queue.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 45422) +++ ChangeLog (revision 45423) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Wed Mar 26 11:20:24 2014 Nobuyoshi Nakada <nobu@r...> + + * ext/thread/thread.c (undumpable): ConditionVariable and Queue + are not dumpable. [ruby-core:61677] [Bug #9674] + Wed Mar 26 10:36:39 2014 NARUSE, Yui <naruse@r...> * addr2line.c (follow_debuglink): show message if it closes opened Index: ext/thread/thread.c =================================================================== --- ext/thread/thread.c (revision 45422) +++ ext/thread/thread.c (revision 45423) @@ -534,6 +534,13 @@ rb_szqueue_num_waiting(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/thread/thread.c#L534 #define UNDER_THREAD 1 #endif +static VALUE +undumpable(VALUE obj) +{ + rb_raise(rb_eTypeError, "can't dump %"PRIsVALUE, rb_obj_class(obj)); + UNREACHABLE; +} + void Init_thread(void) { @@ -573,12 +580,14 @@ Init_thread(void) https://github.com/ruby/ruby/blob/trunk/ext/thread/thread.c#L580 rb_define_method(rb_cConditionVariable, "initialize", rb_condvar_initialize, 0); rb_undef_method(rb_cConditionVariable, "initialize_copy"); + rb_define_method(rb_cConditionVariable, "marshal_dump", undumpable, 0); rb_define_method(rb_cConditionVariable, "wait", rb_condvar_wait, -1); rb_define_method(rb_cConditionVariable, "signal", rb_condvar_signal, 0); rb_define_method(rb_cConditionVariable, "broadcast", rb_condvar_broadcast, 0); rb_define_method(rb_cQueue, "initialize", rb_queue_initialize, 0); rb_undef_method(rb_cQueue, "initialize_copy"); + rb_define_method(rb_cQueue, "marshal_dump", undumpable, 0); rb_define_method(rb_cQueue, "push", rb_queue_push, 1); rb_define_method(rb_cQueue, "pop", rb_queue_pop, -1); rb_define_method(rb_cQueue, "empty?", rb_queue_empty_p, 0); Index: test/thread/test_queue.rb =================================================================== --- test/thread/test_queue.rb (revision 45422) +++ test/thread/test_queue.rb (revision 45423) @@ -215,4 +215,17 @@ class TestQueue < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/thread/test_queue.rb#L215 q.dup end end + + def test_dump + bug9674 = '[ruby-core:61677] [Bug #9674]' + q = Queue.new + assert_raise_with_message(TypeError, /#{Queue}/, bug9674) do + Marshal.dump(q) + end + + sq = SizedQueue.new(1) + assert_raise_with_message(TypeError, /#{SizedQueue}/, bug9674) do + Marshal.dump(sq) + end + end end Index: test/thread/test_cv.rb =================================================================== --- test/thread/test_cv.rb (revision 45422) +++ test/thread/test_cv.rb (revision 45423) @@ -196,4 +196,12 @@ INPUT https://github.com/ruby/ruby/blob/trunk/test/thread/test_cv.rb#L196 condvar.dup end end + + def test_dump + bug9674 = '[ruby-core:61677] [Bug #9674]' + condvar = ConditionVariable.new + assert_raise_with_message(TypeError, /#{ConditionVariable}/, bug9674) do + Marshal.dump(condvar) + end + end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/