aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Tismer <tismer@stackless.com>2020-10-27 17:09:45 +0100
committerChristian Tismer <tismer@stackless.com>2020-10-27 21:13:56 +0000
commit5de0db2391c719ef6c484813cc4aee61da355160 (patch)
tree93facde76f304de3118477d90163108e97018d09
parentdcced0742f383b1932d0e56323387fbd8aeb4513 (diff)
remove traces of Python2 from C codeHEADdev
It will be assumed that Python is always Python 3. All checks for Python 2 are removed. This is the second part of cleaning up the C code from references to Python 2. Task-number: PYSIDE-904 Change-Id: I3006412c2a5bb65402101b0aac5a5f2fc79ce2f8 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
-rw-r--r--sources/pyside2/PySide2/glue/qtcore.cpp34
-rw-r--r--sources/pyside2/libpyside/dynamicqmetaobject.cpp2
-rw-r--r--sources/pyside2/libpyside/pyside.cpp12
-rw-r--r--sources/pyside2/libpyside/pysideproperty.cpp7
-rw-r--r--sources/pyside2/libpyside/pysideqenum.cpp2
-rw-r--r--sources/shiboken2/generator/shiboken/cppgenerator.cpp2
-rw-r--r--sources/shiboken2/libshiboken/CMakeLists.txt1
-rw-r--r--sources/shiboken2/libshiboken/basewrapper.cpp127
-rw-r--r--sources/shiboken2/libshiboken/pep384impl.cpp15
-rw-r--r--sources/shiboken2/libshiboken/pep384impl.h32
-rw-r--r--sources/shiboken2/libshiboken/python25compat.h104
-rw-r--r--sources/shiboken2/libshiboken/sbkenum.cpp20
-rw-r--r--sources/shiboken2/libshiboken/sbkpython.h2
-rw-r--r--sources/shiboken2/libshiboken/sbkstring.cpp4
-rw-r--r--sources/shiboken2/libshiboken/signature/signature.cpp4
-rw-r--r--sources/shiboken2/libshiboken/threadstatesaver.cpp4
-rw-r--r--sources/shiboken2/libshiboken/voidptr.cpp38
-rw-r--r--sources/shiboken2/tests/samplebinding/bytearray_bufferprotocol.cpp55
-rw-r--r--sources/shiboken2/tests/samplebinding/typesystem_sample.xml5
19 files changed, 5 insertions, 465 deletions
diff --git a/sources/pyside2/PySide2/glue/qtcore.cpp b/sources/pyside2/PySide2/glue/qtcore.cpp
index 5d466b3f..996d46d4 100644
--- a/sources/pyside2/PySide2/glue/qtcore.cpp
+++ b/sources/pyside2/PySide2/glue/qtcore.cpp
@@ -1038,40 +1038,11 @@ static int SbkQByteArray_getbufferproc(PyObject *obj, Py_buffer *view, int flags
#endif
}
-#if PY_VERSION_HEX < 0x03000000
-static Py_ssize_t SbkQByteArray_segcountproc(PyObject *self, Py_ssize_t *lenp)
-{
- if (lenp)
- *lenp = Py_TYPE(self)->tp_as_sequence->sq_length(self);
- return 1;
-}
-
-static Py_ssize_t SbkQByteArray_readbufferproc(PyObject *self, Py_ssize_t segment, void **ptrptr)
-{
- if (segment || !Shiboken::Object::isValid(self))
- return -1;
-
- QByteArray * cppSelf = %CONVERTTOCPP[QByteArray *](self);
- //XXX /|\ omitting this space crashes shiboken!
- *ptrptr = reinterpret_cast<void *>(cppSelf->data());
- return cppSelf->size();
-}
-
-PyBufferProcs SbkQByteArrayBufferProc = {
- /*bf_getreadbuffer*/ &SbkQByteArray_readbufferproc,
- /*bf_getwritebuffer*/ (writebufferproc) &SbkQByteArray_readbufferproc,
- /*bf_getsegcount*/ &SbkQByteArray_segcountproc,
- /*bf_getcharbuffer*/ (charbufferproc) &SbkQByteArray_readbufferproc,
- /*bf_getbuffer*/ (getbufferproc)SbkQByteArray_getbufferproc,
-};
-#else
-
static PyBufferProcs SbkQByteArrayBufferProc = {
/*bf_getbuffer*/ (getbufferproc)SbkQByteArray_getbufferproc,
/*bf_releasebuffer*/ (releasebufferproc)0,
};
-#endif
}
// @snippet qbytearray-bufferprotocol
@@ -1175,12 +1146,7 @@ if (PyBytes_Check(%PYARG_1)) {
// @snippet qbytearray-3
// @snippet qbytearray-py3
-#if PY_VERSION_HEX < 0x03000000
-Shiboken::SbkType<QByteArray>()->tp_as_buffer = &SbkQByteArrayBufferProc;
-Shiboken::SbkType<QByteArray>()->tp_flags |= Py_TPFLAGS_HAVE_NEWBUFFER;
-#else
PepType_AS_BUFFER(Shiboken::SbkType<QByteArray>()) = &SbkQByteArrayBufferProc;
-#endif
// @snippet qbytearray-py3
// @snippet qbytearray-data
diff --git a/sources/pyside2/libpyside/dynamicqmetaobject.cpp b/sources/pyside2/libpyside/dynamicqmetaobject.cpp
index 2fbda3f6..f67e97e0 100644
--- a/sources/pyside2/libpyside/dynamicqmetaobject.cpp
+++ b/sources/pyside2/libpyside/dynamicqmetaobject.cpp
@@ -569,7 +569,7 @@ void MetaObjectBuilderPrivate::parsePythonType(PyTypeObject *type)
// Therefore, we don't need to error-check here again.
auto name = String::toCString(obName);
AutoDecRef members(PyObject_GetAttr(obEnumType, PyMagicName::members()));
- AutoDecRef items(PepMapping_Items(members));
+ AutoDecRef items(PyMapping_Items(members));
Py_ssize_t nr_items = PySequence_Length(items);
QVector<QPair<QByteArray, int> > entries;
diff --git a/sources/pyside2/libpyside/pyside.cpp b/sources/pyside2/libpyside/pyside.cpp
index 2404788d..4995f35d 100644
--- a/sources/pyside2/libpyside/pyside.cpp
+++ b/sources/pyside2/libpyside/pyside.cpp
@@ -533,17 +533,7 @@ bool registerInternalQtConf()
// This will disable the internal qt.conf which points to the PySide2 subdirectory (due to the
// subdirectory not existing anymore).
QString executablePath =
-#if PY_MAJOR_VERSION >= 3
- QString::fromWCharArray(Py_GetProgramFullPath());
-#else
- // Python 2 unfortunately returns a char * array instead of a wchar *, which means that on
- // Windows if the executable path contains unicode characters, the returned path will be
- // invalid. We can't use QCoreApplication::applicationFilePath because it requires an
- // existing QCoreApplication instance despite being a static method.
- // This means that a qt.conf near an executable won't be picked up correctly on
- // Windows + Python 2.
- QString::fromLocal8Bit(Py_GetProgramFullPath());
-#endif
+ QString::fromWCharArray(Py_GetProgramFullPath());
QString appDirPath = QFileInfo(executablePath).absolutePath();
QString maybeQtConfPath = QDir(appDirPath).filePath(QStringLiteral("qt.conf"));
bool executableQtConfAvailable = QFileInfo::exists(maybeQtConfPath);
diff --git a/sources/pyside2/libpyside/pysideproperty.cpp b/sources/pyside2/libpyside/pysideproperty.cpp
index bcb2ab35..30cfabf8 100644
--- a/sources/pyside2/libpyside/pysideproperty.cpp
+++ b/sources/pyside2/libpyside/pysideproperty.cpp
@@ -354,13 +354,8 @@ static PyObject *qPropertyDocGet(PyObject *self, void *)
PySidePropertyPrivate *pData = data->d;
QByteArray doc(pData->doc);
- if (!doc.isEmpty()) {
-#if PY_MAJOR_VERSION >= 3
+ if (!doc.isEmpty())
return PyUnicode_FromString(doc);
-#else
- return PyString_FromString(doc);
-#endif
- }
if (pData->fget != nullptr) {
// PYSIDE-1019: Fetch the default `__doc__` from fget. We do it late.
AutoDecRef get_doc(PyObject_GetAttr(pData->fget, PyMagicName::doc()));
diff --git a/sources/pyside2/libpyside/pysideqenum.cpp b/sources/pyside2/libpyside/pysideqenum.cpp
index f46b5536..07a548cb 100644
--- a/sources/pyside2/libpyside/pysideqenum.cpp
+++ b/sources/pyside2/libpyside/pysideqenum.cpp
@@ -66,7 +66,7 @@ static PyObject *analyzePyEnum(PyObject *pyenum, PyObject *container = nullptr)
AutoDecRef members(PyObject_GetAttr(pyenum, Shiboken::PyMagicName::members()));
if (members.isNull())
return nullptr;
- AutoDecRef items(PepMapping_Items(members));
+ AutoDecRef items(PyMapping_Items(members));
if (items.isNull())
return nullptr;
int iflag = PySide::QEnum::isFlag(pyenum);
diff --git a/sources/shiboken2/generator/shiboken/cppgenerator.cpp b/sources/shiboken2/generator/shiboken/cppgenerator.cpp
index 4409e0fa..1d7649b1 100644
--- a/sources/shiboken2/generator/shiboken/cppgenerator.cpp
+++ b/sources/shiboken2/generator/shiboken/cppgenerator.cpp
@@ -5966,8 +5966,6 @@ bool CppGenerator::finishGeneration()
// cleanup staticMetaObject attribute
if (usePySideExtensions()) {
s << "void cleanTypesAttributes(void) {\n";
- s << INDENT << "if (PY_VERSION_HEX >= 0x03000000 && PY_VERSION_HEX < 0x03060000)\n";
- s << INDENT << " return; // PYSIDE-953: testbinding crashes in Python 3.5 when hasattr touches types!\n";
s << INDENT << "for (int i = 0, imax = SBK_" << moduleName()
<< "_IDX_COUNT; i < imax; i++) {\n" << indent(INDENT)
<< INDENT << "PyObject *pyType = reinterpret_cast<PyObject *>(" << cppApiVariableName() << "[i]);\n"
diff --git a/sources/shiboken2/libshiboken/CMakeLists.txt b/sources/shiboken2/libshiboken/CMakeLists.txt
index 75261341..f0df2bd8 100644
--- a/sources/shiboken2/libshiboken/CMakeLists.txt
+++ b/sources/shiboken2/libshiboken/CMakeLists.txt
@@ -131,7 +131,6 @@ install(FILES
sbkconverter.h
sbkenum.h
sbkmodule.h
- python25compat.h
sbkdbg.h
sbkstring.h
sbkstaticstrings.h
diff --git a/sources/shiboken2/libshiboken/basewrapper.cpp b/sources/shiboken2/libshiboken/basewrapper.cpp
index 9dfd8720..2f19e5bd 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)
diff --git a/sources/shiboken2/libshiboken/pep384impl.cpp b/sources/shiboken2/libshiboken/pep384impl.cpp
index 4df9bc21..a4a272c2 100644
--- a/sources/shiboken2/libshiboken/pep384impl.cpp
+++ b/sources/shiboken2/libshiboken/pep384impl.cpp
@@ -719,21 +719,6 @@ PepRun_GetResult(const char *command)
/*****************************************************************************
*
- * Python 2 incompatibilities
- *
- * This is incompatibly implemented as macro in Python 2.
- */
-#if PY_VERSION_HEX < 0x03000000
-
-PyObject *PepMapping_Items(PyObject *o)
-{
- return PyObject_CallMethod(o, const_cast<char *>("items"), NULL);
-}
-
-#endif
-
-/*****************************************************************************
- *
* Extra support for name mangling
*
*/
diff --git a/sources/shiboken2/libshiboken/pep384impl.h b/sources/shiboken2/libshiboken/pep384impl.h
index 07f4a913..d314dc6c 100644
--- a/sources/shiboken2/libshiboken/pep384impl.h
+++ b/sources/shiboken2/libshiboken/pep384impl.h
@@ -228,11 +228,7 @@ LIBSHIBOKEN_API int Pep_GetVerboseFlag(void);
//
// PyUnicode_GetSize is deprecated in favor of PyUnicode_GetLength.
-#if PY_VERSION_HEX < 0x03000000
-#define PepUnicode_GetLength(op) PyUnicode_GetSize((PyObject *)(op))
-#else
#define PepUnicode_GetLength(op) PyUnicode_GetLength((PyObject *)(op))
-#endif
#ifdef Py_LIMITED_API
@@ -285,17 +281,6 @@ LIBSHIBOKEN_API char *_PepUnicode_AsString(PyObject *);
/*****************************************************************************
*
- * RESOLVED: dictobject.h
- *
- * PYSIDE-803, PYSIDE-813: We need PyDict_GetItemWithError in order to
- * avoid the GIL.
- */
-#if PY_VERSION_HEX < 0x03000000
-LIBSHIBOKEN_API PyObject *PyDict_GetItemWithError(PyObject *mp, PyObject *key);
-#endif
-
-/*****************************************************************************
- *
* RESOLVED: methodobject.h
*
*/
@@ -524,12 +509,9 @@ LIBSHIBOKEN_API PyObject *PyStaticMethod_New(PyObject *callable);
#else
#define PepStaticMethod_TypePtr &PyStaticMethod_Type
#endif
+
// Although not PEP specific, we resolve this similar issue, here:
-#if PY_VERSION_HEX < 0x03000000
-extern LIBSHIBOKEN_API PyTypeObject *PepMethodDescr_TypePtr;
-#else
#define PepMethodDescr_TypePtr &PyMethodDescr_Type
-#endif
/*****************************************************************************
*
@@ -546,18 +528,6 @@ LIBSHIBOKEN_API PyObject *PepRun_GetResult(const char *command);
/*****************************************************************************
*
- * Python 2 incompatibilities
- *
- * This is incompatibly implemented as macro in Python 2.
- */
-#if PY_VERSION_HEX < 0x03000000
-extern LIBSHIBOKEN_API PyObject *PepMapping_Items(PyObject *o);
-#else
-#define PepMapping_Items PyMapping_Items
-#endif
-
-/*****************************************************************************
- *
* Runtime support for Python 3.8 incompatibilities
*
*/
diff --git a/sources/shiboken2/libshiboken/python25compat.h b/sources/shiboken2/libshiboken/python25compat.h
deleted file mode 100644
index b8a4950d..00000000
--- a/sources/shiboken2/libshiboken/python25compat.h
+++ /dev/null
@@ -1,104 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of Qt for Python.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef PYTHON25COMPAT_H
-#define PYTHON25COMPAT_H
-#include "sbkpython.h"
-#include <cstring>
-
-/*
- *The #defines below were taken from Cython-generated code to allow shiboken to be used with python2.5.
- * Maybe not all of these defines are useful to us, time will tell which ones are really needed or not.
- */
-
-#if PY_VERSION_HEX < 0x02060000
-#define Py_REFCNT(ob) (((PyObject *)(ob))->ob_refcnt)
-#define Py_TYPE(ob) (((PyObject *)(ob))->ob_type)
-#define Py_SIZE(ob) (((PyVarObject *)(ob))->ob_size)
-#define PyVarObject_HEAD_INIT(type, size) \
- PyObject_HEAD_INIT(type) size,
-#define PyType_Modified(t)
-
-typedef struct {
- void *buf;
- PyObject *obj;
- Py_ssize_t len;
- Py_ssize_t itemsize;
- int readonly;
- int ndim;
- char *format;
- Py_ssize_t *shape;
- Py_ssize_t *strides;
- Py_ssize_t *suboffsets;
- void *internal;
-} Py_buffer;
-
-#define PyBUF_SIMPLE 0
-#define PyBUF_WRITABLE 0x0001
-#define PyBUF_LOCK 0x0002
-#define PyBUF_FORMAT 0x0004
-#define PyBUF_ND 0x0008
-#define PyBUF_STRIDES (0x0010 | PyBUF_ND)
-#define PyBUF_C_CONTIGUOUS (0x0020 | PyBUF_STRIDES)
-#define PyBUF_F_CONTIGUOUS (0x0040 | PyBUF_STRIDES)
-#define PyBUF_ANY_CONTIGUOUS (0x0080 | PyBUF_STRIDES)
-#define PyBUF_INDIRECT (0x0100 | PyBUF_STRIDES)
-
-#define PyBytes_Check PyString_Check
-#define PyBytes_FromString PyString_FromString
-#define PyBytes_FromFormat PyString_FromFormat
-#define PyBytes_FromStringAndSize PyString_FromStringAndSize
-#define PyBytes_GET_SIZE PyString_GET_SIZE
-#define PyBytes_AS_STRING PyString_AS_STRING
-#define PyBytes_AsString PyString_AsString
-#define PyBytes_Concat PyString_Concat
-#define PyBytes_Size PyString_Size
-
-inline PyObject *PyUnicode_FromString(const char *s)
-{
- std::size_t len = std::strlen(s);
- return PyUnicode_DecodeUTF8(s, len, 0);
-}
-
-#define PyLong_FromSize_t _PyLong_FromSize_t
-#define PyLong_AsSsize_t _PyLong_AsSsize_t
-
-#endif
-
-#endif
diff --git a/sources/shiboken2/libshiboken/sbkenum.cpp b/sources/shiboken2/libshiboken/sbkenum.cpp
index e5b7bd74..948f57f2 100644
--- a/sources/shiboken2/libshiboken/sbkenum.cpp
+++ b/sources/shiboken2/libshiboken/sbkenum.cpp
@@ -255,23 +255,6 @@ static PyGetSetDef SbkEnumGetSetList[] = {
{nullptr, nullptr, nullptr, nullptr, nullptr} // Sentinel
};
-#if PY_VERSION_HEX < 0x03000000
-
-static PyObject *SbkEnumType_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 void SbkEnumTypeDealloc(PyObject *pyObj);
static PyObject *SbkEnumTypeTpNew(PyTypeObject *metatype, PyObject *args, PyObject *kwds);
@@ -291,9 +274,6 @@ static PyType_Slot SbkEnumType_Type_slots[] = {
{Py_tp_alloc, (void *)PyType_GenericAlloc},
{Py_tp_new, (void *)SbkEnumTypeTpNew},
{Py_tp_free, (void *)PyObject_GC_Del},
-#if PY_VERSION_HEX < 0x03000000
- {Py_tp_repr, (void *)SbkEnumType_repr},
-#endif
{0, nullptr}
};
static PyType_Spec SbkEnumType_Type_spec = {
diff --git a/sources/shiboken2/libshiboken/sbkpython.h b/sources/shiboken2/libshiboken/sbkpython.h
index abdb02eb..772fe76a 100644
--- a/sources/shiboken2/libshiboken/sbkpython.h
+++ b/sources/shiboken2/libshiboken/sbkpython.h
@@ -71,7 +71,6 @@ extern "C" {
}
# include <structmember.h>
// Now we have the usual variables from Python.h .
-# include "python25compat.h"
# include "shibokenmacros.h"
// "pep384impl.h" may nowhere be included but in this file.
# include "pep384impl.h"
@@ -97,7 +96,6 @@ extern "C" {
}
# include <structmember.h>
// Now we have the usual variables from Python.h .
-# include "python25compat.h"
# include "shibokenmacros.h"
// "pep384impl.h" may nowhere be included but in this file.
# include "pep384impl.h"
diff --git a/sources/shiboken2/libshiboken/sbkstring.cpp b/sources/shiboken2/libshiboken/sbkstring.cpp
index ca32f591..93a630ac 100644
--- a/sources/shiboken2/libshiboken/sbkstring.cpp
+++ b/sources/shiboken2/libshiboken/sbkstring.cpp
@@ -211,11 +211,7 @@ PyObject *createStaticString(const char *str)
Py_AtExit(finalizeStaticStrings);
initialized = true;
}
-#if PY_VERSION_HEX >= 0x03000000
PyObject *result = PyUnicode_InternFromString(str);
-#else
- PyObject *result = PyString_InternFromString(str);
-#endif
if (result == nullptr) {
// This error is never checked, but also very unlikely. Report and exit.
PyErr_Print();
diff --git a/sources/shiboken2/libshiboken/signature/signature.cpp b/sources/shiboken2/libshiboken/signature/signature.cpp
index 085d751a..05d3cad2 100644
--- a/sources/shiboken2/libshiboken/signature/signature.cpp
+++ b/sources/shiboken2/libshiboken/signature/signature.cpp
@@ -140,11 +140,7 @@ static PyObject *_GetSignature_Cached(PyObject *props, PyObject *func_kind, PyOb
{
// Special case: We want to know the func_kind.
if (modifier) {
-#if PY_VERSION_HEX >= 0x03000000
PyUnicode_InternInPlace(&modifier);
-#else
- PyString_InternInPlace(&modifier);
-#endif
if (modifier == PyMagicName::func_kind())
return Py_BuildValue("O", func_kind);
}
diff --git a/sources/shiboken2/libshiboken/threadstatesaver.cpp b/sources/shiboken2/libshiboken/threadstatesaver.cpp
index 085535fd..7c587b40 100644
--- a/sources/shiboken2/libshiboken/threadstatesaver.cpp
+++ b/sources/shiboken2/libshiboken/threadstatesaver.cpp
@@ -51,11 +51,7 @@ ThreadStateSaver::~ThreadStateSaver()
void ThreadStateSaver::save()
{
-#if PY_VERSION_HEX >= 0x0309000
if (Py_IsInitialized())
-#else
- if (PyEval_ThreadsInitialized())
-#endif
m_threadState = PyEval_SaveThread();
}
diff --git a/sources/shiboken2/libshiboken/voidptr.cpp b/sources/shiboken2/libshiboken/voidptr.cpp
index a21a4482..1ef1aea0 100644
--- a/sources/shiboken2/libshiboken/voidptr.cpp
+++ b/sources/shiboken2/libshiboken/voidptr.cpp
@@ -280,44 +280,11 @@ static int SbkVoidPtrObject_getbuffer(PyObject *obj, Py_buffer *view, int flags)
return 0;
}
-#if PY_VERSION_HEX < 0x03000000
-
-static Py_ssize_t SbkVoidPtrObject_readbufferproc(PyObject *self, Py_ssize_t segment, void **ptrptr)
-{
- if (segment || !Shiboken::Object::isValid(self))
- return -1;
-
- SbkVoidPtrObject *sbkObject = reinterpret_cast<SbkVoidPtrObject *>(self);
- *ptrptr = reinterpret_cast<void *>(sbkObject->cptr);
- return sbkObject->size;
-}
-
-static Py_ssize_t SbkVoidPtrObject_segcountproc(PyObject *self, Py_ssize_t *lenp)
-{
- if (lenp) {
- SbkVoidPtrObject *sbkObject = reinterpret_cast<SbkVoidPtrObject *>(self);
- *lenp = sbkObject->size;
- }
- return 1;
-}
-
-PyBufferProcs SbkVoidPtrObjectBufferProc = {
- &SbkVoidPtrObject_readbufferproc, // bf_getreadbuffer
- (writebufferproc)&SbkVoidPtrObject_readbufferproc, // bf_getwritebuffer
- &SbkVoidPtrObject_segcountproc, // bf_getsegcount
- (charbufferproc)&SbkVoidPtrObject_readbufferproc, // bf_getcharbuffer
- (getbufferproc)SbkVoidPtrObject_getbuffer, // bf_getbuffer
-};
-
-#else
-
static PyBufferProcs SbkVoidPtrObjectBufferProc = {
(getbufferproc)SbkVoidPtrObject_getbuffer, // bf_getbuffer
(releasebufferproc)nullptr // bf_releasebuffer
};
-#endif
-
// Void pointer type definition.
static PyType_Slot SbkVoidPtrType_slots[] = {
{Py_tp_repr, (void *)SbkVoidPtrObject_repr},
@@ -347,12 +314,7 @@ PyTypeObject *SbkVoidPtrTypeF(void)
static PyTypeObject *type = nullptr;
if (!type) {
type = reinterpret_cast<PyTypeObject *>(SbkType_FromSpec(&SbkVoidPtrType_spec));
-#if PY_VERSION_HEX < 0x03000000
- type->tp_as_buffer = &SbkVoidPtrObjectBufferProc;
- type->tp_flags |= Py_TPFLAGS_HAVE_NEWBUFFER;
-#else
PepType_AS_BUFFER(type) = &SbkVoidPtrObjectBufferProc;
-#endif
}
return type;
}
diff --git a/sources/shiboken2/tests/samplebinding/bytearray_bufferprotocol.cpp b/sources/shiboken2/tests/samplebinding/bytearray_bufferprotocol.cpp
deleted file mode 100644
index 32238708..00000000
--- a/sources/shiboken2/tests/samplebinding/bytearray_bufferprotocol.cpp
+++ /dev/null
@@ -1,55 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of Qt for Python.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#if PY_VERSION_HEX < 0x03000000
-// ByteArray buffer protocol functions
-// See: http://www.python.org/dev/peps/pep-3118/
-extern "C" {
-static Py_ssize_t SbkByteArray_segcountproc(PyObject* self, Py_ssize_t* lenp)
-{
- if (lenp)
- *lenp = Py_TYPE(self)->tp_as_sequence->sq_length(self);
- return 1;
-}
-static Py_ssize_t SbkByteArray_readbufferproc(PyObject* self, Py_ssize_t segment, void** ptrptr)
-{
- if (segment || !Shiboken::Object::isValid(self))
- return -1;
-
- ByteArray* cppSelf = %CONVERTTOCPP[ByteArray*](self);
- *ptrptr = reinterpret_cast<void*>(const_cast<char*>(cppSelf->data()));
- return cppSelf->size();
-}
-PyBufferProcs SbkByteArrayBufferProc = {
- /*bf_getreadbuffer*/ &SbkByteArray_readbufferproc,
- /*bf_getwritebuffer*/ (writebufferproc)&SbkByteArray_readbufferproc,
- /*bf_getsegcount*/ &SbkByteArray_segcountproc,
- /*bf_getcharbuffer*/ (charbufferproc)&SbkByteArray_readbufferproc
-};
-}
-#endif
diff --git a/sources/shiboken2/tests/samplebinding/typesystem_sample.xml b/sources/shiboken2/tests/samplebinding/typesystem_sample.xml
index d0ccbb34..b310f8d6 100644
--- a/sources/shiboken2/tests/samplebinding/typesystem_sample.xml
+++ b/sources/shiboken2/tests/samplebinding/typesystem_sample.xml
@@ -2141,12 +2141,7 @@
</modify-function>
<!-- buffer protocol -->
- <inject-code class="native" position="beginning" file="bytearray_bufferprotocol.cpp" />
<inject-code class="target" position="end">
- #if PY_VERSION_HEX &lt; 0x03000000
- Shiboken::SbkType&lt;ByteArray&gt;()->tp_as_buffer = &amp;SbkByteArrayBufferProc;
- Shiboken::SbkType&lt;ByteArray&gt;()->tp_flags |= Py_TPFLAGS_HAVE_GETCHARBUFFER;
- #endif
</inject-code>
<modify-function signature="data() const">