From 5bc3a71e82e74c6b336a9439fadd18b22000c405 Mon Sep 17 00:00:00 2001 From: Lisandro Dalcin Date: Fri, 1 Oct 2010 22:36:30 -0300 Subject: [PATCH] protect PyGILState_Ensure|Release for Python configured without threads --- Cython/Compiler/Nodes.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index ecd4b8f7..5864b472 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -1284,7 +1284,9 @@ class FuncDefNode(StatNode, BlockNode): acquire_gil = self.acquire_gil if acquire_gil: env.use_utility_code(force_init_threads_utility_code) + code.putln("#ifdef WITH_THREAD") code.putln("PyGILState_STATE _save = PyGILState_Ensure();") + code.putln("#endif") # ----- set up refnanny if not lenv.nogil: code.put_setup_refcount_context(self.entry.name) @@ -1469,7 +1471,9 @@ class FuncDefNode(StatNode, BlockNode): code.put_finish_refcount_context() if acquire_gil: + code.putln("#ifdef WITH_THREAD") code.putln("PyGILState_Release(_save);") + code.putln("#endif") if not self.return_type.is_void: code.putln("return %s;" % Naming.retval_cname) @@ -5085,7 +5089,9 @@ class GILStatNode(TryFinallyStatNode): def generate_execution_code(self, code): code.mark_pos(self.pos) if self.state == 'gil': + code.putln("#ifdef WITH_THREAD") code.putln("{ PyGILState_STATE _save = PyGILState_Ensure();") + code.putln("#endif") else: code.putln("{ PyThreadState *_save;") code.putln("Py_UNBLOCK_THREADS") @@ -5105,7 +5111,9 @@ class GILExitNode(StatNode): def generate_execution_code(self, code): if self.state == 'gil': - code.putln("PyGILState_Release();") + code.putln("#ifdef WITH_THREAD") + code.putln("PyGILState_Release(_save); }") + code.putln("#endif") else: code.putln("Py_BLOCK_THREADS") -- 2.26.2