Commit b7ba1caf authored by Stefan Behnel's avatar Stefan Behnel

Use an inlined version of PyType_HasFeature() instead of directly accessing...

Use an inlined version of PyType_HasFeature() instead of directly accessing "tp_flags" in the generated code.
parent ec95d13d
...@@ -1454,7 +1454,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -1454,7 +1454,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
if is_final_type: if is_final_type:
type_safety_check = '' type_safety_check = ''
else: else:
type_safety_check = ' & ((t->tp_flags & (Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_HEAPTYPE)) == 0)' type_safety_check = ' & (__Pyx_PyType_HasFeature(t, (Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_HEAPTYPE)) == 0)'
obj_struct = type.declaration_code("", deref=True) obj_struct = type.declaration_code("", deref=True)
code.putln( code.putln(
"if (CYTHON_COMPILING_IN_CPYTHON && likely((%s > 0) & (t->tp_basicsize == sizeof(%s))%s)) {" % ( "if (CYTHON_COMPILING_IN_CPYTHON && likely((%s > 0) & (t->tp_basicsize == sizeof(%s))%s)) {" % (
...@@ -1467,7 +1467,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -1467,7 +1467,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code.putln("PyObject_GC_Track(o);") code.putln("PyObject_GC_Track(o);")
code.putln("} else {") code.putln("} else {")
if not is_final_type: if not is_final_type:
code.putln("if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) {") code.putln("if (likely(__Pyx_PyType_HasFeature(t, Py_TPFLAGS_IS_ABSTRACT) == 0)) {")
code.putln("o = (*t->tp_alloc)(t, 0);") code.putln("o = (*t->tp_alloc)(t, 0);")
if not is_final_type: if not is_final_type:
code.putln("} else {") code.putln("} else {")
...@@ -1584,7 +1584,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -1584,7 +1584,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
'(!PyType_IS_GC(Py_TYPE(o)) || !_PyGC_FINALIZED(o))') '(!PyType_IS_GC(Py_TYPE(o)) || !_PyGC_FINALIZED(o))')
code.putln( code.putln(
"if (unlikely(" "if (unlikely("
"(PY_VERSION_HEX >= 0x03080000 || PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE))" "(PY_VERSION_HEX >= 0x03080000 || __Pyx_PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE))"
" && Py_TYPE(o)->tp_finalize) && %s) {" % finalised_check) " && Py_TYPE(o)->tp_finalize) && %s) {" % finalised_check)
# if instance was resurrected by finaliser, return # if instance was resurrected by finaliser, return
code.putln("if (PyObject_CallFinalizerFromDealloc(o)) return;") code.putln("if (PyObject_CallFinalizerFromDealloc(o)) return;")
...@@ -1660,7 +1660,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -1660,7 +1660,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
type_safety_check = '' type_safety_check = ''
else: else:
type_safety_check = ( type_safety_check = (
' & ((Py_TYPE(o)->tp_flags & (Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_HEAPTYPE)) == 0)') ' & (__Pyx_PyType_HasFeature(Py_TYPE(o), (Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_HEAPTYPE)) == 0)')
type = scope.parent_type type = scope.parent_type
code.putln( code.putln(
......
...@@ -4601,8 +4601,8 @@ class OverrideCheckNode(StatNode): ...@@ -4601,8 +4601,8 @@ class OverrideCheckNode(StatNode):
if self.py_func.is_module_scope: if self.py_func.is_module_scope:
code.putln("else {") code.putln("else {")
else: else:
code.putln("else if (unlikely((Py_TYPE(%s)->tp_dictoffset != 0)" code.putln("else if (unlikely((Py_TYPE(%s)->tp_dictoffset != 0) || "
" || (Py_TYPE(%s)->tp_flags & (Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_HEAPTYPE)))) {" % ( "__Pyx_PyType_HasFeature(Py_TYPE(%s), (Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_HEAPTYPE)))) {" % (
self_arg, self_arg)) self_arg, self_arg))
code.putln("#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS") code.putln("#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS")
......
...@@ -36,7 +36,7 @@ static int __Pyx_PyType_Ready(PyTypeObject *t) { ...@@ -36,7 +36,7 @@ static int __Pyx_PyType_Ready(PyTypeObject *t) {
} }
#endif #endif
b = (PyTypeObject*)b0; b = (PyTypeObject*)b0;
if (!PyType_HasFeature(b, Py_TPFLAGS_HEAPTYPE)) if (!__Pyx_PyType_HasFeature(b, Py_TPFLAGS_HEAPTYPE))
{ {
PyErr_Format(PyExc_TypeError, "base class '%.200s' is not a heap type", PyErr_Format(PyExc_TypeError, "base class '%.200s' is not a heap type",
b->tp_name); b->tp_name);
......
...@@ -715,6 +715,12 @@ static CYTHON_INLINE PyObject * __Pyx_PyDict_GetItemStrWithError(PyObject *dict, ...@@ -715,6 +715,12 @@ static CYTHON_INLINE PyObject * __Pyx_PyDict_GetItemStrWithError(PyObject *dict,
#define __Pyx_PyType_GetFlags(tp) (((PyTypeObject *)tp)->tp_flags) #define __Pyx_PyType_GetFlags(tp) (((PyTypeObject *)tp)->tp_flags)
#endif #endif
#if CYTHON_USE_TYPE_SLOTS
#define __Pyx_PyType_HasFeature(type, feature) ((__Pyx_PyType_GetFlags(type) & (feature)) != 0)
#else
#define __Pyx_PyType_HasFeature(type, feature) PyType_HasFeature(type, feature)
#endif
#if CYTHON_COMPILING_IN_LIMITED_API #if CYTHON_COMPILING_IN_LIMITED_API
#define CYTHON_PEP393_ENABLED 1 #define CYTHON_PEP393_ENABLED 1
#define __Pyx_PyUnicode_READY(op) (0) #define __Pyx_PyUnicode_READY(op) (0)
......
...@@ -1763,7 +1763,7 @@ static int __Pyx_PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **me ...@@ -1763,7 +1763,7 @@ static int __Pyx_PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **me
if (likely(descr != NULL)) { if (likely(descr != NULL)) {
Py_INCREF(descr); Py_INCREF(descr);
#if defined(Py_TPFLAGS_METHOD_DESCRIPTOR) && Py_TPFLAGS_METHOD_DESCRIPTOR #if defined(Py_TPFLAGS_METHOD_DESCRIPTOR) && Py_TPFLAGS_METHOD_DESCRIPTOR
if (PyType_HasFeature(Py_TYPE(descr), Py_TPFLAGS_METHOD_DESCRIPTOR)) if (__Pyx_PyType_HasFeature(Py_TYPE(descr), Py_TPFLAGS_METHOD_DESCRIPTOR))
#elif PY_MAJOR_VERSION >= 3 #elif PY_MAJOR_VERSION >= 3
// Repeating the condition below accommodates for MSVC's inability to test macros inside of macro expansions. // Repeating the condition below accommodates for MSVC's inability to test macros inside of macro expansions.
#ifdef __Pyx_CyFunction_USED #ifdef __Pyx_CyFunction_USED
......
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