fix 'set' type checks (prevent match with frozenset)
authorStefan Behnel <scoder@users.berlios.de>
Tue, 20 Jul 2010 22:44:02 +0000 (00:44 +0200)
committerStefan Behnel <scoder@users.berlios.de>
Tue, 20 Jul 2010 22:44:02 +0000 (00:44 +0200)
Cython/Compiler/ModuleNode.py
Cython/Compiler/PyrexTypes.py

index 143ccbfbbc02c6e913fbf5ad5187881a84893e17..15022436381b23f64d793555a53fa8fa06edcbee 100644 (file)
@@ -548,6 +548,12 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
   #define PyBytes_Repr                 PyString_Repr
   #define PyBytes_Concat               PyString_Concat
   #define PyBytes_ConcatAndDel         PyString_ConcatAndDel
+  #define PySet_Check(obj)             PyObject_TypeCheck(obj, &PySet_Type)
+  #define PyFrozenSet_Check(obj)       PyObject_TypeCheck(obj, &PyFrozenSet_Type)
+#endif
+
+#ifndef PySet_CheckExact
+#  define PySet_CheckExact(obj)          (Py_TYPE(obj) == PySet_Type)
 #endif
 
 #if PY_MAJOR_VERSION >= 3
index f1ad4eaf18c9984fcaecfae2ffdb05e5c99afa48..eafe8e3611ee4bb1481c92e62305dcdbcbae2c7f 100755 (executable)
@@ -416,20 +416,27 @@ class BuiltinObjectType(PyObjectType):
         
     def subtype_of(self, type):
         return type.is_pyobject and self.assignable_from(type)
-        
-    def type_test_code(self, arg, notnone=False):
+
+    def type_check_function(self, exact=True):
         type_name = self.name
+        if type_name == 'bool':
+            return 'PyBool_Check'
+
         if type_name == 'str':
-            type_check = 'PyString_CheckExact'
-        elif type_name == 'set':
-            type_check = 'PyAnySet_CheckExact'
+            type_check = 'PyString_Check'
         elif type_name == 'frozenset':
-            type_check = 'PyFrozenSet_CheckExact'
-        elif type_name == 'bool':
-            type_check = 'PyBool_Check'
+            type_check = 'PyFrozenSet_Check'
         else:
-            type_check = 'Py%s_CheckExact' % type_name.capitalize()
+            type_check = 'Py%s_Check' % type_name.capitalize()
+        if exact:
+            type_check += 'Exact'
+        return type_check
+
+    def isinstance_code(self, arg):
+        return '%s(%s)' % (self.type_check_function(exact=False), arg)
 
+    def type_test_code(self, arg, notnone=False):
+        type_check = self.type_check_function(exact=True)
         check = 'likely(%s(%s))' % (type_check, arg)
         if not notnone:
             check = check + ('||((%s) == Py_None)' % arg)