aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken2/libshiboken/basewrapper.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'sources/shiboken2/libshiboken/basewrapper.cpp')
-rw-r--r--sources/shiboken2/libshiboken/basewrapper.cpp127
1 files changed, 0 insertions, 127 deletions
diff --git a/sources/shiboken2/libshiboken/basewrapper.cpp b/sources/shiboken2/libshiboken/basewrapper.cpp
index 9dfd87208..2f19e5bd2 100644
--- a/sources/shiboken2/libshiboken/basewrapper.cpp
+++ b/sources/shiboken2/libshiboken/basewrapper.cpp
@@ -135,23 +135,6 @@ static PyGetSetDef SbkObjectType_Type_getsetlist[] = {
{nullptr} // Sentinel
};
-#if PY_VERSION_HEX < 0x03000000
-
-static PyObject *SbkObjectType_repr(PyObject *type)
-{
- Shiboken::AutoDecRef mod(PyObject_GetAttr(type, Shiboken::PyMagicName::module()));
- if (mod.isNull())
- return nullptr;
- Shiboken::AutoDecRef name(PyObject_GetAttr(type, Shiboken::PyMagicName::qualname()));
- if (name.isNull())
- return nullptr;
- return PyString_FromFormat("<class '%s.%s'>",
- PyString_AS_STRING(mod.object()),
- PyString_AS_STRING(name.object()));
-}
-
-#endif // PY_VERSION_HEX < 0x03000000
-
static PyObject *(*type_getattro)(PyObject *type, PyObject *name); // forward
static PyObject *mangled_type_getattro(PyTypeObject *type, PyObject *name); // forward
@@ -163,9 +146,6 @@ static PyType_Slot SbkObjectType_Type_slots[] = {
{Py_tp_new, reinterpret_cast<void *>(SbkObjectTypeTpNew)},
{Py_tp_free, reinterpret_cast<void *>(PyObject_GC_Del)},
{Py_tp_getset, reinterpret_cast<void *>(SbkObjectType_Type_getsetlist)},
-#if PY_VERSION_HEX < 0x03000000
- {Py_tp_repr, reinterpret_cast<void *>(SbkObjectType_repr)},
-#endif
{0, nullptr}
};
static PyType_Spec SbkObjectType_Type_spec = {
@@ -176,95 +156,6 @@ static PyType_Spec SbkObjectType_Type_spec = {
SbkObjectType_Type_slots,
};
-
-#if PY_VERSION_HEX < 0x03000000
-/*****************************************************************************
- *
- * PYSIDE-816: Workaround for Python 2.7 for SbkObjectType_TypeF().
- *
- * This is an add-on for function typeobject.c:tp_new_wrapper from Python 2.7 .
- * Problem:
- * In Python 3.X, tp_new_wrapper uses this check:
-
- while (staticbase && (staticbase->tp_new == slot_tp_new))
-
- * In Python 2.7, it uses this, instead:
-
- while (staticbase && (staticbase->tp_flags & Py_TPFLAGS_HEAPTYPE))
-
- * The problem is that heap types have this unwanted dependency.
- * But we cannot get at static slot_tp_new, and so we have to use
- * the original function and patch Py_TPFLAGS_HEAPTYPE away during the call.
- *
- * PYSIDE-1051: The same problem holds for all dynamic metatypes generated by
- * SbkObjectTypeTpNew() and all types generated by
- * introduceWrapperType() .
- *
- * This led to a drastic overhaul of patch_tp_new_wrapper() which now adds
- * the new wrapper to exactly those types which have the old wrapper.
- */
-
-ternaryfunc old_tp_new_wrapper = nullptr;
-
-static PyObject *
-tp_new_wrapper(PyObject *self, PyObject *args, PyObject *kwds)
-{
- PyTypeObject *type = reinterpret_cast<PyTypeObject *>(self);
- Py_ssize_t orig_flags = type->tp_flags;
- type->tp_flags &= ~Py_TPFLAGS_HEAPTYPE;
- PyObject *ret = reinterpret_cast<ternaryfunc>(old_tp_new_wrapper)(self, args, kwds);
- type->tp_flags = orig_flags;
- return ret;
-}
-
-// This is intentionally the __new__ docstring of Python 3.7 .
-static struct PyMethodDef tp_new_methoddef[] = {
- {"__new__", reinterpret_cast<PyCFunction>(tp_new_wrapper), METH_VARARGS|METH_KEYWORDS,
- PyDoc_STR("__new__($type, *args, **kwargs)\n--\n\n"
- "Create and return a new object. "
- "See help(type) for accurate signature.")},
- {0}
-};
-
-static int
-patch_tp_new_wrapper(PyTypeObject *type)
-{
- /*
- * The old tp_new_wrapper is added to all types that have tp_new.
- * We patch that with a version that ignores the heaptype flag.
- */
- auto newMethod = Shiboken::PyMagicName::new_();
- if (old_tp_new_wrapper == nullptr) {
- PyObject *func = PyDict_GetItem(PyType_Type.tp_dict, newMethod);
- assert(func);
- PyCFunctionObject *pycf_ob = reinterpret_cast<PyCFunctionObject *>(func);
- old_tp_new_wrapper = reinterpret_cast<ternaryfunc>(pycf_ob->m_ml->ml_meth);
- }
- PyObject *mro = type->tp_mro;
- Py_ssize_t i, n = PyTuple_GET_SIZE(mro);
- for (i = 0; i < n; i++) {
- type = reinterpret_cast<PyTypeObject *>(PyTuple_GET_ITEM(mro, i));
- PyObject *existing = PyDict_GetItem(type->tp_dict, newMethod);
- if (existing && PyCFunction_Check(existing)
- && type->tp_flags & Py_TPFLAGS_HEAPTYPE) {
- auto *pycf_ob = reinterpret_cast<PyCFunctionObject *>(existing);
- auto existing_wrapper = reinterpret_cast<ternaryfunc>(pycf_ob->m_ml->ml_meth);
- if (existing_wrapper == tp_new_wrapper)
- break;
- if (existing_wrapper == old_tp_new_wrapper) {
- PyObject *ob_type = reinterpret_cast<PyObject *>(type);
- Shiboken::AutoDecRef func(PyCFunction_New(tp_new_methoddef, ob_type));
- if (func.isNull() || PyDict_SetItem(type->tp_dict, newMethod, func))
- return -1;
- }
- }
- }
- return 0;
-}
-/*****************************************************************************/
-#endif // PY_VERSION_HEX < 0x03000000
-
-
PyTypeObject *SbkObjectType_TypeF(void)
{
static PyTypeObject *type = nullptr;
@@ -275,10 +166,6 @@ PyTypeObject *SbkObjectType_TypeF(void)
SbkObjectType_Type_spec.basicsize =
PepHeapType_SIZE + sizeof(SbkObjectTypePrivate);
type = reinterpret_cast<PyTypeObject *>(SbkType_FromSpec(&SbkObjectType_Type_spec));
-#if PY_VERSION_HEX < 0x03000000
- if (patch_tp_new_wrapper(type) < 0)
- return nullptr;
-#endif
}
return type;
}
@@ -674,11 +561,6 @@ static PyObject *SbkObjectTypeTpNew(PyTypeObject *metatype, PyObject *args, PyOb
if (!newType)
return nullptr;
-#if PY_VERSION_HEX < 0x03000000
- // PYSIDE-1051: The newly created metatype needs the PYSIDE-816 wrapper, too.
- if (patch_tp_new_wrapper(&newType->type) < 0)
- return nullptr;
-#endif
Shiboken::ObjectType::initPrivateData(newType);
SbkObjectTypePrivate *sotp = PepType_SOTP(newType);
@@ -930,10 +812,6 @@ void init()
Conversions::init();
-#if PY_VERSION_HEX < 0x03070000
- PyEval_InitThreads();
-#endif
-
//Init private data
Pep384_Init();
@@ -1099,11 +977,6 @@ introduceWrapperType(PyObject *enclosingObject,
Py_TYPE(heaptype) = SbkObjectType_TypeF();
Py_INCREF(Py_TYPE(heaptype));
auto *type = reinterpret_cast<SbkObjectType *>(heaptype);
-#if PY_VERSION_HEX < 0x03000000
- // PYSIDE-1051: The newly created type needs the PYSIDE-816 wrapper, too.
- if (patch_tp_new_wrapper(&type->type) < 0)
- return nullptr;
-#endif
if (baseType) {
if (baseTypes) {
for (int i = 0; i < PySequence_Fast_GET_SIZE(baseTypes); ++i)