From 1dd527012b5da0f7d84986a201c3b7f834adef78 Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 26 Mar 2014 02:20:26 +0000 Subject: thread.c: undumpable * ext/thread/thread.c (undumpable): ConditionVariable and Queue are not dumpable. [ruby-core:61677] [Bug #9674] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45423 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ ext/thread/thread.c | 9 +++++++++ test/thread/test_cv.rb | 8 ++++++++ test/thread/test_queue.rb | 13 +++++++++++++ 4 files changed, 35 insertions(+) diff --git a/ChangeLog b/ChangeLog index ef23c94f83..f1a2545394 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Wed Mar 26 11:20:24 2014 Nobuyoshi Nakada + + * 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 * addr2line.c (follow_debuglink): show message if it closes opened diff --git a/ext/thread/thread.c b/ext/thread/thread.c index cec8a5b4fa..38b8a8c4e7 100644 --- a/ext/thread/thread.c +++ b/ext/thread/thread.c @@ -534,6 +534,13 @@ rb_szqueue_num_waiting(VALUE self) #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) 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); diff --git a/test/thread/test_cv.rb b/test/thread/test_cv.rb index 92179e8e45..bb0bcb8685 100644 --- a/test/thread/test_cv.rb +++ b/test/thread/test_cv.rb @@ -196,4 +196,12 @@ INPUT 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 diff --git a/test/thread/test_queue.rb b/test/thread/test_queue.rb index 6d527ad68c..b3662742c1 100644 --- a/test/thread/test_queue.rb +++ b/test/thread/test_queue.rb @@ -215,4 +215,17 @@ class TestQueue < Test::Unit::TestCase 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 -- cgit v1.2.3