diff options
author | Stefan Behnel <stefan_ml@behnel.de> | 2020-05-09 08:49:50 +0200 |
---|---|---|
committer | Stefan Behnel <stefan_ml@behnel.de> | 2020-05-09 08:54:26 +0200 |
commit | 2d8f7f35c28c5c398143c74a9b2f34ee65e61554 (patch) | |
tree | 52e06fef2087f4d1c12d46be4bf3db6aacb5e6c4 | |
parent | c47bcecaa04fc4b90755a6f774b6ced6eb7ea1ee (diff) | |
download | cython-2d8f7f35c28c5c398143c74a9b2f34ee65e61554.tar.gz |
Guard the local variable cleanup in nogil functions with 'with gil' sections with the GIL.
Closes https://github.com/cython/cython/issues/3590
-rw-r--r-- | Cython/Compiler/Nodes.py | 5 | ||||
-rw-r--r-- | tests/run/with_gil.pyx | 15 |
2 files changed, 18 insertions, 2 deletions
diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index 45f195128..3a5c86d99 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -2146,8 +2146,9 @@ class FuncDefNode(StatNode, BlockNode): if entry.type.is_pyobject: if entry.is_arg and not entry.cf_is_reassigned: continue + assure_gil('success') # FIXME ideally use entry.xdecref_cleanup but this currently isn't reliable - code.put_var_xdecref(entry, have_gil=not lenv.nogil) + code.put_var_xdecref(entry, have_gil=gil_owned['success']) # Decref any increfed args for entry in lenv.arg_entries: @@ -2163,7 +2164,7 @@ class FuncDefNode(StatNode, BlockNode): continue # FIXME use entry.xdecref_cleanup - del arg seems to be the problem - code.put_var_xdecref(entry, have_gil=not lenv.nogil) + code.put_var_xdecref(entry, have_gil=gil_owned['success']) if self.needs_closure: assure_gil('success') code.put_decref(Naming.cur_scope_cname, lenv.scope_class.type) diff --git a/tests/run/with_gil.pyx b/tests/run/with_gil.pyx index 9b43b7df4..a5211975e 100644 --- a/tests/run/with_gil.pyx +++ b/tests/run/with_gil.pyx @@ -463,6 +463,21 @@ def test_nogil_try_finally_error_label(): print e.args[0] +def void_with_python_objects(): + """ + >>> void_with_python_objects() + """ + with nogil: + _void_with_python_objects() + + +cdef void _void_with_python_objects() nogil: + c = 123 + with gil: + obj1 = [123] + obj2 = [456] + + cdef void test_timing_callback() with gil: pass |