From a6fea9229d0af2bb544747853c45db38aa568ae8 Mon Sep 17 00:00:00 2001 From: Kenta Murata Date: Thu, 10 Feb 2022 09:45:13 +0900 Subject: [PATCH] Fix without_gvl for exceptions occurred in a block Fixes GH-154 --- ext/pycall/pycall.c | 4 ++++ test/pycall/test-gvl.rb | 10 ++++++++++ 2 files changed, 14 insertions(+) create mode 100644 test/pycall/test-gvl.rb diff --git a/ext/pycall/pycall.c b/ext/pycall/pycall.c index afe6903..c69373d 100644 --- a/ext/pycall/pycall.c +++ b/ext/pycall/pycall.c @@ -107,6 +107,10 @@ pycall_without_gvl(VALUE (* func)(VALUE), VALUE arg) pycall_set_with_gvl(); + if (state) { + rb_jump_tag(state); + } + return result; } diff --git a/test/pycall/test-gvl.rb b/test/pycall/test-gvl.rb new file mode 100644 index 0000000..02ceda4 --- /dev/null +++ b/test/pycall/test-gvl.rb @@ -0,0 +1,10 @@ +class PyCallGvlTest < Test::Unit::TestCase + def test_exception + math = PyCall.import_module("math") + assert_raise_message(/factorial\(\) not defined for negative values/) do + PyCall.without_gvl do + math.factorial(-1) + end + end + end +end