diff options
Diffstat (limited to 'sources/shiboken2/libshiboken')
-rw-r--r-- | sources/shiboken2/libshiboken/basewrapper.cpp | 16 | ||||
-rw-r--r-- | sources/shiboken2/libshiboken/sbkenum.cpp | 13 | ||||
-rw-r--r-- | sources/shiboken2/libshiboken/sbknumpyarrayconverter.cpp | 5 | ||||
-rw-r--r-- | sources/shiboken2/libshiboken/sbkstring.cpp | 19 |
4 files changed, 46 insertions, 7 deletions
diff --git a/sources/shiboken2/libshiboken/basewrapper.cpp b/sources/shiboken2/libshiboken/basewrapper.cpp index afca7fa08..1919f2825 100644 --- a/sources/shiboken2/libshiboken/basewrapper.cpp +++ b/sources/shiboken2/libshiboken/basewrapper.cpp @@ -376,8 +376,9 @@ SbkObjectType *SbkObject_TypeF(void) { static PyTypeObject *type = nullptr; if (!type) { - type = reinterpret_cast<PyTypeObject *>(SbkType_FromSpec(&SbkObject_Type_spec)); - Py_TYPE(type) = SbkObjectType_TypeF(); + auto *obj = SbkType_FromSpec(&SbkObject_Type_spec); + type = reinterpret_cast<PyTypeObject *>(obj); + obj->ob_type = SbkObjectType_TypeF(); Py_INCREF(Py_TYPE(type)); type->tp_weaklistoffset = offsetof(SbkObject, weakreflist); type->tp_dictoffset = offsetof(SbkObject, ob_dict); @@ -521,7 +522,11 @@ void SbkObjectTypeDealloc(PyObject *pyObj) PyObject_GC_UnTrack(pyObj); #ifndef Py_LIMITED_API +# if PY_VERSION_HEX >= 0x030A0000 + Py_TRASHCAN_BEGIN(pyObj, 1); +# else Py_TRASHCAN_SAFE_BEGIN(pyObj); +# endif #endif if (sotp) { if (sotp->user_data && sotp->d_func) { @@ -536,7 +541,11 @@ void SbkObjectTypeDealloc(PyObject *pyObj) sotp = nullptr; } #ifndef Py_LIMITED_API +# if PY_VERSION_HEX >= 0x030A0000 + Py_TRASHCAN_END; +# else Py_TRASHCAN_SAFE_END(pyObj); +# endif #endif if (PepRuntime_38_flag) { // PYSIDE-939: Handling references correctly. @@ -1161,7 +1170,7 @@ introduceWrapperType(PyObject *enclosingObject, typeSpec->slots[0].pfunc = reinterpret_cast<void *>(baseType ? baseType : SbkObject_TypeF()); PyObject *heaptype = SbkType_FromSpecWithBases(typeSpec, baseTypes); - Py_TYPE(heaptype) = SbkObjectType_TypeF(); + heaptype->ob_type = SbkObjectType_TypeF(); Py_INCREF(Py_TYPE(heaptype)); auto *type = reinterpret_cast<SbkObjectType *>(heaptype); #if PY_VERSION_HEX < 0x03000000 @@ -1526,6 +1535,7 @@ bool setCppPointer(SbkObject *sbkObj, PyTypeObject *desiredType, void *cptr) bool isValid(PyObject *pyObj) { if (!pyObj || pyObj == Py_None + || PyType_Check(pyObj) != 0 || Py_TYPE(Py_TYPE(pyObj)) != SbkObjectType_TypeF()) { return true; } diff --git a/sources/shiboken2/libshiboken/sbkenum.cpp b/sources/shiboken2/libshiboken/sbkenum.cpp index 7dc73dfbc..38e702296 100644 --- a/sources/shiboken2/libshiboken/sbkenum.cpp +++ b/sources/shiboken2/libshiboken/sbkenum.cpp @@ -330,13 +330,21 @@ void SbkEnumTypeDealloc(PyObject *pyObj) PyObject_GC_UnTrack(pyObj); #ifndef Py_LIMITED_API +# if PY_VERSION_HEX >= 0x030A0000 + Py_TRASHCAN_BEGIN(pyObj, 1); +# else Py_TRASHCAN_SAFE_BEGIN(pyObj); +# endif #endif if (PepType_SETP(sbkType)->converter) { Shiboken::Conversions::deleteConverter(PepType_SETP(sbkType)->converter); } #ifndef Py_LIMITED_API +# if PY_VERSION_HEX >= 0x030A0000 + Py_TRASHCAN_END; +# else Py_TRASHCAN_SAFE_END(pyObj); +# endif #endif if (PepRuntime_38_flag) { // PYSIDE-939: Handling references correctly. @@ -752,9 +760,10 @@ newTypeWithName(const char *name, static auto basetype = SbkEnum_TypeF(); Py_INCREF(basetype); PyTuple_SetItem(bases, 0, reinterpret_cast<PyObject *>(basetype)); - auto *type = reinterpret_cast<PyTypeObject *>(SbkType_FromSpecWithBases(&newspec, bases)); + auto *obj = SbkType_FromSpecWithBases(&newspec, bases); + auto *type = reinterpret_cast<PyTypeObject *>(obj); PyErr_Print(); - Py_TYPE(type) = SbkEnumType_TypeF(); + obj->ob_type = SbkEnumType_TypeF(); auto *enumType = reinterpret_cast<SbkEnumType *>(type); PepType_SETP(enumType)->cppName = cppName; diff --git a/sources/shiboken2/libshiboken/sbknumpyarrayconverter.cpp b/sources/shiboken2/libshiboken/sbknumpyarrayconverter.cpp index 996968fa1..cc25b349d 100644 --- a/sources/shiboken2/libshiboken/sbknumpyarrayconverter.cpp +++ b/sources/shiboken2/libshiboken/sbknumpyarrayconverter.cpp @@ -116,8 +116,13 @@ std::ostream &operator<<(std::ostream &str, PyArrayObject *o) str << " NPY_ARRAY_NOTSWAPPED"; if ((flags & NPY_ARRAY_WRITEABLE) != 0) str << " NPY_ARRAY_WRITEABLE"; +#if NPY_VERSION >= 0x00000010 // NPY_1_23_API_VERSION + if ((flags & NPY_ARRAY_WRITEBACKIFCOPY) != 0) + str << " NPY_ARRAY_WRITEBACKIFCOPY"; +#else if ((flags & NPY_ARRAY_UPDATEIFCOPY) != 0) str << " NPY_ARRAY_UPDATEIFCOPY"; +#endif } else { str << '0'; } diff --git a/sources/shiboken2/libshiboken/sbkstring.cpp b/sources/shiboken2/libshiboken/sbkstring.cpp index 077fb531b..0f83aeef0 100644 --- a/sources/shiboken2/libshiboken/sbkstring.cpp +++ b/sources/shiboken2/libshiboken/sbkstring.cpp @@ -41,8 +41,14 @@ #include "sbkstaticstrings_p.h" #include "autodecref.h" -#include <vector> -#include <unordered_set> +#if PY_VERSION_HEX >= 0x03000000 +# define USE_INTERN_STRINGS +#endif + +#ifndef USE_INTERN_STRINGS +# include <vector> +# include <unordered_set> +#endif namespace Shiboken { @@ -233,6 +239,13 @@ Py_ssize_t len(PyObject *str) // PyObject *attr = PyObject_GetAttr(obj, name()); // +#ifdef USE_INTERN_STRINGS +PyObject *createStaticString(const char *str) +{ + return PyUnicode_InternFromString(str); +} +#else + using StaticStrings = std::unordered_set<PyObject *>; static void finalizeStaticStrings(); // forward @@ -283,6 +296,8 @@ PyObject *createStaticString(const char *str) return result; } +#endif // !USE_INTERN_STRINGS + /////////////////////////////////////////////////////////////////////// // // PYSIDE-1019: Helper function for snake_case vs. camelCase names |