diff options
author | Christian Tismer <tismer@stackless.com> | 2021-12-23 10:19:23 +0100 |
---|---|---|
committer | Christian Tismer <tismer@stackless.com> | 2022-01-05 15:51:40 +0100 |
commit | d7526db85fcec588fa6ca643bd6fb8a9f45c3fc2 (patch) | |
tree | 165a849b190e80d67905b342f15eeff7ed5583ed | |
parent | 981ffb345928cf740a5b751aaef43a266d077d13 (diff) |
PyPySide: Do some cleanup and Improvements
For more clarity, the function SbkObject_GetDict is renamed to
SbkObject_GetDict_NoRef.
The internal __dict__ implementation SbkObjectGetDict is
re-written to use SbkObject_GetDict_NoRef, which is more
correct because of PyPy's tp_dict handling.
Task-number: PYSIDE-535
Change-Id: I28034d9199918859de809fde08c413b4b66a3136
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
-rw-r--r-- | sources/pyside6/libpyside/signalmanager.cpp | 4 | ||||
-rw-r--r-- | sources/shiboken6/generator/shiboken/cppgenerator.cpp | 6 | ||||
-rw-r--r-- | sources/shiboken6/libshiboken/basewrapper.cpp | 12 | ||||
-rw-r--r-- | sources/shiboken6/libshiboken/basewrapper.h | 2 | ||||
-rw-r--r-- | sources/shiboken6/libshiboken/bindingmanager.cpp | 2 |
5 files changed, 11 insertions, 15 deletions
diff --git a/sources/pyside6/libpyside/signalmanager.cpp b/sources/pyside6/libpyside/signalmanager.cpp index 05769f213..bf9a5a4ad 100644 --- a/sources/pyside6/libpyside/signalmanager.cpp +++ b/sources/pyside6/libpyside/signalmanager.cpp @@ -526,7 +526,7 @@ int SignalManager::registerMetaMethodGetIndex(QObject *source, const char *signa return -1; } auto *pySelf = reinterpret_cast<PyObject *>(self); - auto *dict = SbkObject_GetDict(pySelf); + auto *dict = SbkObject_GetDict_NoRef(pySelf); MetaObjectBuilder *dmo = metaBuilderFromDict(dict); // Create a instance meta object @@ -555,7 +555,7 @@ const QMetaObject *SignalManager::retrieveMetaObject(PyObject *self) // m_dirty flag is set. Q_ASSERT(self); - auto *ob_dict = SbkObject_GetDict(self); + auto *ob_dict = SbkObject_GetDict_NoRef(self); MetaObjectBuilder *builder = metaBuilderFromDict(ob_dict); if (!builder) builder = &(retrieveTypeUserData(self)->mo); diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.cpp b/sources/shiboken6/generator/shiboken/cppgenerator.cpp index f93024d55..e7f0f5351 100644 --- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp +++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp @@ -6084,8 +6084,8 @@ void CppGenerator::writeGetattroFunction(TextStream &s, AttroCheck attroCheck, if (attroCheck.testFlag(AttroCheckFlag::GetattroOverloads)) { s << "// Search the method in the instance dict\n" - << "auto ob_dict = SbkObject_GetDict(self);\n"; - s << "if (auto meth = PyDict_GetItem(ob_dict, name)) {\n"; + << "auto *ob_dict = SbkObject_GetDict_NoRef(self);\n"; + s << "if (auto *meth = PyDict_GetItem(ob_dict, name)) {\n"; { Indentation indent(s); s << "Py_INCREF(meth);\n" @@ -6098,7 +6098,7 @@ void CppGenerator::writeGetattroFunction(TextStream &s, AttroCheck attroCheck, Indentation indent(s); // PYSIDE-772: Perform optimized name mangling. s << "Shiboken::AutoDecRef tmp(_Pep_PrivateMangle(self, name));\n" - << "if (auto meth = PyDict_GetItem(Py_TYPE(self)->tp_dict, tmp)) {\n"; + << "if (auto *meth = PyDict_GetItem(Py_TYPE(self)->tp_dict, tmp)) {\n"; { Indentation indent(s); // PYSIDE-1523: PyFunction_Check is not accepting compiled functions. diff --git a/sources/shiboken6/libshiboken/basewrapper.cpp b/sources/shiboken6/libshiboken/basewrapper.cpp index 7a615b06b..eb8069525 100644 --- a/sources/shiboken6/libshiboken/basewrapper.cpp +++ b/sources/shiboken6/libshiboken/basewrapper.cpp @@ -104,7 +104,7 @@ void setDestroyQApplication(DestroyQAppHook func) } // PYSIDE-535: Use the C API in PyPy instead of `op->ob_dict`, directly -LIBSHIBOKEN_API PyObject *SbkObject_GetDict(PyObject *op) +LIBSHIBOKEN_API PyObject *SbkObject_GetDict_NoRef(PyObject *op) { #ifdef PYPY_VERSION auto *ret = PyObject_GenericGetDict(op, nullptr); @@ -187,13 +187,9 @@ PyTypeObject *SbkObjectType_TypeF(void) static PyObject *SbkObjectGetDict(PyObject *pObj, void *) { - auto *obj = reinterpret_cast<SbkObject *>(pObj); - if (!obj->ob_dict) - obj->ob_dict = PyDict_New(); - if (!obj->ob_dict) - return nullptr; - Py_INCREF(obj->ob_dict); - return obj->ob_dict; + auto ret = SbkObject_GetDict_NoRef(pObj); + Py_XINCREF(ret); + return ret; } static PyGetSetDef SbkObjectGetSetList[] = { diff --git a/sources/shiboken6/libshiboken/basewrapper.h b/sources/shiboken6/libshiboken/basewrapper.h index 27441ad17..85556ec61 100644 --- a/sources/shiboken6/libshiboken/basewrapper.h +++ b/sources/shiboken6/libshiboken/basewrapper.h @@ -113,7 +113,7 @@ typedef void(*DestroyQAppHook)(); LIBSHIBOKEN_API void setDestroyQApplication(DestroyQAppHook func); /// PYSIDE-535: Use the C API in PyPy instead of `op->ob_dict`, directly (borrowed ref) -LIBSHIBOKEN_API PyObject *SbkObject_GetDict(PyObject *op); +LIBSHIBOKEN_API PyObject *SbkObject_GetDict_NoRef(PyObject *op); extern LIBSHIBOKEN_API PyTypeObject *SbkObjectType_TypeF(void); extern LIBSHIBOKEN_API PyTypeObject *SbkObject_TypeF(void); diff --git a/sources/shiboken6/libshiboken/bindingmanager.cpp b/sources/shiboken6/libshiboken/bindingmanager.cpp index 020ff3c9b..6fa625907 100644 --- a/sources/shiboken6/libshiboken/bindingmanager.cpp +++ b/sources/shiboken6/libshiboken/bindingmanager.cpp @@ -304,7 +304,7 @@ PyObject *BindingManager::getOverride(const void *cptr, } auto *obWrapper = reinterpret_cast<PyObject *>(wrapper); - auto *wrapper_dict = SbkObject_GetDict(obWrapper); + auto *wrapper_dict = SbkObject_GetDict_NoRef(obWrapper); if (PyObject *method = PyDict_GetItem(wrapper_dict, pyMethodName)) { Py_INCREF(method); return method; |