From c951d4e28cd67dfc3b4d84de5ee22bf1dd5c007c Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Sat, 1 May 2010 17:38:23 +0200 Subject: [PATCH] avoid GIL error for optimised container bool tests that run in plain C --- Cython/Compiler/ExprNodes.py | 2 +- tests/run/builtins_truth_test.pyx | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index 36b4e560..169e93a5 100755 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -6321,7 +6321,7 @@ class CoerceToBooleanNode(CoercionNode): self.is_temp = 1 def nogil_check(self, env): - if self.arg.type.is_pyobject: + if self.arg.type.is_pyobject and self._special_builtins.get(self.arg.type) is None: self.gil_error() gil_message = "Truth-testing Python object" diff --git a/tests/run/builtins_truth_test.pyx b/tests/run/builtins_truth_test.pyx index b30f581f..be20d64c 100644 --- a/tests/run/builtins_truth_test.pyx +++ b/tests/run/builtins_truth_test.pyx @@ -24,6 +24,23 @@ def if_list(list obj): else: return False +def if_list_nogil(list obj): + """ + >>> if_list_nogil( [] ) + False + >>> if_list_nogil( [1] ) + True + >>> if_list_nogil(None) + False + """ + cdef bint result + with nogil: + if obj: + result = True + else: + result = False + return result + def if_list_literal(t): """ >>> if_list_literal(True) -- 2.26.2