Skip to content

Commit ce99468

Browse files
committed
merge revision(s) r45423,r45424: [Backport ruby#9674]
* ext/thread/thread.c (undumpable): ConditionVariable and Queue are not dumpable. [ruby-core:61677] [Bug ruby#9674] * marshal.c (w_object): internal objects are not dumpable. [ruby-core:61677] [Bug ruby#9674] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_1@46805 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent 02e809a commit ce99468

File tree

6 files changed

+57
-3
lines changed

6 files changed

+57
-3
lines changed

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
Sun Jul 13 22:44:05 2014 Nobuyoshi Nakada <[email protected]>
2+
3+
* ext/thread/thread.c (undumpable): ConditionVariable and Queue
4+
are not dumpable. [ruby-core:61677] [Bug #9674]
5+
16
Fri Jul 11 23:07:09 2014 Marc-Andre Lafortune <[email protected]>
27

38
* lib/matrix.rb: Fix sign for cross_product [#9499]

ext/thread/thread.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,13 @@ rb_szqueue_num_waiting(VALUE self)
534534
#define UNDER_THREAD 1
535535
#endif
536536

537+
static VALUE
538+
undumpable(VALUE obj)
539+
{
540+
rb_raise(rb_eTypeError, "can't dump %"PRIsVALUE, rb_obj_class(obj));
541+
UNREACHABLE;
542+
}
543+
537544
void
538545
Init_thread(void)
539546
{
@@ -572,11 +579,13 @@ Init_thread(void)
572579
id_sleep = rb_intern("sleep");
573580

574581
rb_define_method(rb_cConditionVariable, "initialize", rb_condvar_initialize, 0);
582+
rb_define_method(rb_cConditionVariable, "marshal_dump", undumpable, 0);
575583
rb_define_method(rb_cConditionVariable, "wait", rb_condvar_wait, -1);
576584
rb_define_method(rb_cConditionVariable, "signal", rb_condvar_signal, 0);
577585
rb_define_method(rb_cConditionVariable, "broadcast", rb_condvar_broadcast, 0);
578586

579587
rb_define_method(rb_cQueue, "initialize", rb_queue_initialize, 0);
588+
rb_define_method(rb_cQueue, "marshal_dump", undumpable, 0);
580589
rb_define_method(rb_cQueue, "push", rb_queue_push, 1);
581590
rb_define_method(rb_cQueue, "pop", rb_queue_pop, -1);
582591
rb_define_method(rb_cQueue, "empty?", rb_queue_empty_p, 0);

marshal.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,11 @@ w_object(VALUE obj, struct dump_arg *arg, int limit)
650650
else {
651651
VALUE v;
652652

653+
if (!RBASIC_CLASS(obj)) {
654+
rb_raise(rb_eTypeError, "can't dump internal %s",
655+
rb_builtin_type_name(BUILTIN_TYPE(obj)));
656+
}
657+
653658
arg->infection |= (int)FL_TEST(obj, MARSHAL_INFECTION);
654659

655660
if (rb_obj_respond_to(obj, s_mdump, TRUE)) {

test/thread/test_cv.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,4 +188,19 @@ def test_condvar_empty_broadcast
188188

189189
assert_nothing_raised(Exception) { mutex.synchronize {condvar.broadcast} }
190190
end
191+
192+
(DumpableCV = ConditionVariable.dup).class_eval {remove_method :marshal_dump}
193+
194+
def test_dump
195+
bug9674 = '[ruby-core:61677] [Bug #9674]'
196+
condvar = ConditionVariable.new
197+
assert_raise_with_message(TypeError, /#{ConditionVariable}/, bug9674) do
198+
Marshal.dump(condvar)
199+
end
200+
201+
condvar = DumpableCV.new
202+
assert_raise_with_message(TypeError, /internal Array/, bug9674) do
203+
Marshal.dump(condvar)
204+
end
205+
end
191206
end

test/thread/test_queue.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,4 +207,24 @@ def test_queue_thread_raise
207207
timeout(1) { th2.join }
208208
end
209209
end
210+
211+
(DumpableQueue = Queue.dup).class_eval {remove_method :marshal_dump}
212+
213+
def test_dump
214+
bug9674 = '[ruby-core:61677] [Bug #9674]'
215+
q = Queue.new
216+
assert_raise_with_message(TypeError, /#{Queue}/, bug9674) do
217+
Marshal.dump(q)
218+
end
219+
220+
sq = SizedQueue.new(1)
221+
assert_raise_with_message(TypeError, /#{SizedQueue}/, bug9674) do
222+
Marshal.dump(sq)
223+
end
224+
225+
q = DumpableQueue.new
226+
assert_raise_with_message(TypeError, /internal Array/, bug9674) do
227+
Marshal.dump(q)
228+
end
229+
end
210230
end

version.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#define RUBY_VERSION "2.1.2"
2-
#define RUBY_RELEASE_DATE "2014-07-11"
3-
#define RUBY_PATCHLEVEL 169
2+
#define RUBY_RELEASE_DATE "2014-07-13"
3+
#define RUBY_PATCHLEVEL 170
44

55
#define RUBY_RELEASE_YEAR 2014
66
#define RUBY_RELEASE_MONTH 7
7-
#define RUBY_RELEASE_DAY 11
7+
#define RUBY_RELEASE_DAY 13
88

99
#include "ruby/version.h"
1010

0 commit comments

Comments
 (0)