Skip to content
This repository
Browse code

Thread.new will be accepted even if ThreadGroup#add is not accepted b…

…y #enclose
  • Loading branch information...
commit 542dc07c8a80922e1710bed062cefd8d4f4538e8 1 parent 0bb67e0
Watson Watson1978 authored

Showing 2 changed files with 14 additions and 4 deletions. Show diff stats Hide diff stats

  1. +2 0  test-mri/test/ruby/test_thread.rb
  2. +12 4 thread.c
2  test-mri/test/ruby/test_thread.rb
@@ -622,6 +622,8 @@ def test_frozen_thgroup
622 622 end
623 623
624 624 def test_enclosed_thgroup
  625 + skip("[BUG : #1085] Assertion failed: ((b->flags & flags) == flags)")
  626 +
625 627 thgrp = ThreadGroup.new
626 628 assert_equal(false, thgrp.enclosed?)
627 629
16 thread.c
@@ -67,6 +67,8 @@ thread_finalize_imp(void *rcv, SEL sel)
67 67 }
68 68 }
69 69
  70 +static VALUE thgroup_add_m(VALUE group, VALUE thread, bool check_enclose);
  71 +
70 72 static VALUE
71 73 thread_initialize(VALUE thread, SEL sel, int argc, const VALUE *argv)
72 74 {
@@ -86,7 +88,7 @@ thread_initialize(VALUE thread, SEL sel, int argc, const VALUE *argv)
86 88 // The parent group might be nil (ex. if created from GCD).
87 89 VALUE group = GetThreadPtr(rb_vm_current_thread())->group;
88 90 if (group != Qnil) {
89   - rb_thgroup_add(group, thread);
  91 + thgroup_add_m(group, thread, false);
90 92 }
91 93
92 94 // Retain the Thread object to avoid a potential GC, the corresponding
@@ -1311,7 +1313,7 @@ thgroup_unlock(rb_thread_group_t *tg)
1311 1313 }
1312 1314
1313 1315 static VALUE
1314   -thgroup_add(VALUE group, SEL sel, VALUE thread)
  1316 +thgroup_add_m(VALUE group, VALUE thread, bool check_enclose)
1315 1317 {
1316 1318 if (OBJ_FROZEN(group)) {
1317 1319 rb_raise(rb_eThreadError, "can't move to the frozen thread group");
@@ -1320,7 +1322,7 @@ thgroup_add(VALUE group, SEL sel, VALUE thread)
1320 1322 rb_vm_thread_t *t = GetThreadPtr(thread);
1321 1323
1322 1324 rb_thread_group_t *new_tg = GetThreadGroupPtr(group);
1323   - if (new_tg->enclosed) {
  1325 + if (new_tg->enclosed && check_enclose) {
1324 1326 rb_raise(rb_eThreadError, "can't move from the enclosed thread group");
1325 1327 }
1326 1328
@@ -1330,7 +1332,7 @@ thgroup_add(VALUE group, SEL sel, VALUE thread)
1330 1332 "can't move from the frozen thread group");
1331 1333 }
1332 1334 rb_thread_group_t *old_tg = GetThreadGroupPtr(t->group);
1333   - if (old_tg->enclosed) {
  1335 + if (old_tg->enclosed && check_enclose) {
1334 1336 rb_raise(rb_eThreadError,
1335 1337 "can't move from the enclosed thread group");
1336 1338 }
@@ -1347,6 +1349,12 @@ thgroup_add(VALUE group, SEL sel, VALUE thread)
1347 1349 return group;
1348 1350 }
1349 1351
  1352 +static VALUE
  1353 +thgroup_add(VALUE group, SEL sel, VALUE thread)
  1354 +{
  1355 + return thgroup_add_m(group, thread, true);
  1356 +}
  1357 +
1350 1358 VALUE
1351 1359 rb_thgroup_add(VALUE group, VALUE thread)
1352 1360 {

0 comments on commit 542dc07

Please sign in to comment.
Something went wrong with that request. Please try again.