diff options
author | Samuel Williams <samuel.williams@oriontransfer.co.nz> | 2020-10-01 13:42:58 +1300 |
---|---|---|
committer | Samuel Williams <samuel.williams@oriontransfer.co.nz> | 2020-10-01 16:02:03 +1300 |
commit | 13660105e225df0a4fc1f91b8c9618261e5761f3 (patch) | |
tree | 952edb6842ada12121d4c4fc9f64308f916a5f22 | |
parent | bc23216e5a4204b8e626704c7277e9edc1708189 (diff) |
Don't call `Scheduler#close` if it doesn't exist.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/3612
-rw-r--r-- | scheduler.c | 4 | ||||
-rw-r--r-- | test/fiber/test_scheduler.rb | 8 |
2 files changed, 11 insertions, 1 deletions
diff --git a/scheduler.c b/scheduler.c index 8ec5039096..f0bb5ee597 100644 --- a/scheduler.c +++ b/scheduler.c @@ -39,7 +39,9 @@ Init_Scheduler(void) VALUE rb_scheduler_close(VALUE scheduler) { - return rb_funcall(scheduler, id_close, 0); + if (rb_respond_to(scheduler, id_close)) { + return rb_funcall(scheduler, id_close, 0); + } } VALUE diff --git a/test/fiber/test_scheduler.rb b/test/fiber/test_scheduler.rb index 23b59c06b0..d85aa7a6ce 100644 --- a/test/fiber/test_scheduler.rb +++ b/test/fiber/test_scheduler.rb @@ -49,4 +49,12 @@ class TestFiberScheduler < Test::Unit::TestCase end RUBY end + + def test_optional_close + thread = Thread.new do + Thread.current.scheduler = Object.new + end + + thread.join + end end |