aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2025-09-29 13:47:12 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2025-10-01 20:59:53 +0200
commitbddaf9d442f62ce8d2eec02ed579032237f493a5 (patch)
treeb7c84084072d84cee38a8faa009cfbb51c433ec4
parentf7d6326bbe7a80ee460d6b8135e1e9a0f6a51d98 (diff)
libshiboken/global types: Introduce a struct and function for access
Put qApp and the SbkObject type into a struct which in the future will exist per interpreter as interpreters can only share immortal objects. Also remove storage of the function results in static variables. Task-number: PYSIDE-3155 Change-Id: I5e1f12a80e858d2b8f7b5aa5d969f4024f8e3a2f Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
-rw-r--r--sources/pyside6/PySide6/QtCore/glue/core_snippets.cpp2
-rw-r--r--sources/shiboken6/libshiboken/basewrapper.cpp29
-rw-r--r--sources/shiboken6/libshiboken/pep384impl.cpp6
3 files changed, 26 insertions, 11 deletions
diff --git a/sources/pyside6/PySide6/QtCore/glue/core_snippets.cpp b/sources/pyside6/PySide6/QtCore/glue/core_snippets.cpp
index a77a8ddea..181e5291d 100644
--- a/sources/pyside6/PySide6/QtCore/glue/core_snippets.cpp
+++ b/sources/pyside6/PySide6/QtCore/glue/core_snippets.cpp
@@ -139,7 +139,7 @@ QString qObjectTr(PyTypeObject *type, const char *sourceText, const char *disamb
auto len = PyTuple_Size(mro);
QString result = QString::fromUtf8(sourceText);
QString oldResult = result;
- static auto *sbkObjectType = reinterpret_cast<PyTypeObject *>(SbkObject_TypeF());
+ auto *sbkObjectType = reinterpret_cast<PyTypeObject *>(SbkObject_TypeF());
for (Py_ssize_t idx = 0; idx < len - 1; ++idx) {
// Skip the last class which is `object`.
auto *type = reinterpret_cast<PyTypeObject *>(PyTuple_GetItem(mro, idx));
diff --git a/sources/shiboken6/libshiboken/basewrapper.cpp b/sources/shiboken6/libshiboken/basewrapper.cpp
index e02177e44..9be91bf9b 100644
--- a/sources/shiboken6/libshiboken/basewrapper.cpp
+++ b/sources/shiboken6/libshiboken/basewrapper.cpp
@@ -37,6 +37,19 @@ namespace {
void _destroyParentInfo(SbkObject *obj, bool keepReference);
}
+struct BaseWrapperGlobals
+{
+ PyTypeObject *sbkObjectType = nullptr;
+ PyTypeObject *sbkObjectMetaType = nullptr;
+ PyObject *qAppLast = nullptr;
+};
+
+static BaseWrapperGlobals *baseWrapperGlobals()
+{
+ static BaseWrapperGlobals result;
+ return &result;
+}
+
namespace Shiboken
{
// Walk through the first level of non-user-type Sbk base classes relevant for
@@ -240,8 +253,10 @@ static PyTypeObject *createObjectTypeType()
PyTypeObject *SbkObjectType_TypeF(void)
{
- static auto *type = createObjectTypeType();
- return type;
+ auto *globals = baseWrapperGlobals();
+ if (globals->sbkObjectMetaType == nullptr)
+ globals->sbkObjectMetaType = createObjectTypeType();
+ return globals->sbkObjectMetaType;
}
static PyObject *SbkObjectGetDict(PyObject *pObj, void *)
@@ -335,8 +350,10 @@ static PyTypeObject *createObjectType()
PyTypeObject *SbkObject_TypeF(void)
{
- static auto *type = createObjectType(); // bufferprocs
- return type;
+ auto *globals = baseWrapperGlobals();
+ if (globals->sbkObjectType == nullptr)
+ globals->sbkObjectType = createObjectType(); // bufferprocs
+ return globals->sbkObjectType;
}
static const char *SbkObject_SignatureStrings[] = {
@@ -514,7 +531,7 @@ void SbkObjectType_tp_dealloc(PyTypeObject *sbkType)
PyObject *MakeQAppWrapper(PyTypeObject *type)
{
- static PyObject *qApp_last = nullptr;
+ PyObject *&qApp_last = baseWrapperGlobals()->qAppLast;
// protecting from multiple application instances
if (type != nullptr && qApp_last != Py_None) {
@@ -707,7 +724,7 @@ PyObject *FallbackRichCompare(PyObject *self, PyObject *other, int op)
bool SbkObjectType_Check(PyTypeObject *type)
{
- static auto *meta = SbkObjectType_TypeF();
+ auto *meta = SbkObjectType_TypeF();
auto *obType = reinterpret_cast<PyObject *>(type);
return Py_TYPE(obType) == meta || PyType_IsSubtype(Py_TYPE(obType), meta);
}
diff --git a/sources/shiboken6/libshiboken/pep384impl.cpp b/sources/shiboken6/libshiboken/pep384impl.cpp
index e71eba1db..4afdcdc8b 100644
--- a/sources/shiboken6/libshiboken/pep384impl.cpp
+++ b/sources/shiboken6/libshiboken/pep384impl.cpp
@@ -900,10 +900,9 @@ SbkObjectTypePrivate *PepType_SOTP(PyTypeObject *type)
{
// PYSIDE-2676: Use the meta type explicitly.
// A derived type would fail the offset calculation.
- static auto *meta = SbkObjectType_TypeF();
assert(SbkObjectType_Check(type));
auto *obType = reinterpret_cast<PyObject *>(type);
- void *data = PyObject_GetTypeData(obType, meta);
+ void *data = PyObject_GetTypeData(obType, SbkObjectType_TypeF());
return reinterpret_cast<SbkObjectTypePrivate *>(data);
}
@@ -953,12 +952,11 @@ static thread_local SbkObjectTypePrivate *SOTP_value{};
SbkObjectTypePrivate *PepType_SOTP(PyTypeObject *type)
{
- static auto *meta = SbkObjectType_TypeF();
static bool use_312 = _PepRuntimeVersion() >= 0x030C00;
assert(SbkObjectType_Check(type));
if (use_312) {
auto *obType = reinterpret_cast<PyObject *>(type);
- void *data = PepObject_GetTypeData(obType, meta);
+ void *data = PepObject_GetTypeData(obType, SbkObjectType_TypeF());
return reinterpret_cast<SbkObjectTypePrivate *>(data);
}
if (type == SOTP_key)