Commit 9215510d authored by Stefan Behnel's avatar Stefan Behnel

fix 'set' type checks (prevent match with frozenset)

parent f972b042
...@@ -548,6 +548,12 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -548,6 +548,12 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
#define PyBytes_Repr PyString_Repr #define PyBytes_Repr PyString_Repr
#define PyBytes_Concat PyString_Concat #define PyBytes_Concat PyString_Concat
#define PyBytes_ConcatAndDel PyString_ConcatAndDel #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 #endif
#if PY_MAJOR_VERSION >= 3 #if PY_MAJOR_VERSION >= 3
......
...@@ -416,20 +416,27 @@ class BuiltinObjectType(PyObjectType): ...@@ -416,20 +416,27 @@ class BuiltinObjectType(PyObjectType):
def subtype_of(self, type): def subtype_of(self, type):
return type.is_pyobject and self.assignable_from(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 type_name = self.name
if type_name == 'bool':
return 'PyBool_Check'
if type_name == 'str': if type_name == 'str':
type_check = 'PyString_CheckExact' type_check = 'PyString_Check'
elif type_name == 'set':
type_check = 'PyAnySet_CheckExact'
elif type_name == 'frozenset': elif type_name == 'frozenset':
type_check = 'PyFrozenSet_CheckExact' type_check = 'PyFrozenSet_Check'
elif type_name == 'bool':
type_check = 'PyBool_Check'
else: 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) check = 'likely(%s(%s))' % (type_check, arg)
if not notnone: if not notnone:
check = check + ('||((%s) == Py_None)' % arg) check = check + ('||((%s) == Py_None)' % arg)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment