avoid GIL error for optimised container bool tests that run in plain C
authorStefan Behnel <scoder@users.berlios.de>
Sat, 1 May 2010 15:38:23 +0000 (17:38 +0200)
committerStefan Behnel <scoder@users.berlios.de>
Sat, 1 May 2010 15:38:23 +0000 (17:38 +0200)
Cython/Compiler/ExprNodes.py
tests/run/builtins_truth_test.pyx

index 36b4e560df16a35987881a6e718c863c8db86f31..169e93a55546b0a66113e341d446d1c4ee839f81 100755 (executable)
@@ -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"
index b30f581ff19954dd62155c323575ce041d19dcb8..be20d64c9f5fc16791ea9c226978ceb4c5f3e7b8 100644 (file)
@@ -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)