aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Tismer <tismer@stackless.com>2021-01-05 18:50:49 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-01-06 14:22:22 +0000
commitb9a89e1f3c8d0b80cc91bf1d277ead3b7857dabd (patch)
treee557dbe0120f290f169acd10498d08fc7dbcb88f
parent09670a8746fa443c4b8271381bf21fc5c993f1bb (diff)
feature: Disable selection while creating a type
PySide 6 suddenly has problems with feature switching during subtype initialization. We introduce an enable function that can temporarily suppress switching. This problem is solved so far. It is the question whether this will break again in another constellation. It might be considerable for the future to have something like Python's PyType_Ready function. Right now this is too much effort. Change-Id: If0ed786d4761cf2356f01f7478e4a0d750e88d3c Fixes: PYSIDE-1463 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io> (cherry picked from commit b6d1b76b46d7b756f7cb01361037e1cb5efc990a) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--sources/pyside6/libpyside/feature_select.cpp10
-rw-r--r--sources/pyside6/libpyside/feature_select.h1
-rw-r--r--sources/pyside6/libpyside/pyside.cpp5
-rw-r--r--sources/shiboken6/libshiboken/basewrapper.cpp7
-rw-r--r--sources/shiboken6/libshiboken/basewrapper.h5
5 files changed, 24 insertions, 4 deletions
diff --git a/sources/pyside6/libpyside/feature_select.cpp b/sources/pyside6/libpyside/feature_select.cpp
index 47a7472e1..b87751271 100644
--- a/sources/pyside6/libpyside/feature_select.cpp
+++ b/sources/pyside6/libpyside/feature_select.cpp
@@ -451,11 +451,11 @@ void finalize()
}
static bool patch_property_impl();
+static bool is_initialized = false;
void init()
{
// This function can be called multiple times.
- static bool is_initialized = false;
if (!is_initialized) {
fast_id_array = &_fast_id_array[1];
for (int idx = -1; idx < 256; ++idx)
@@ -472,6 +472,14 @@ void init()
cached_globals = nullptr;
}
+void Enable(bool enable)
+{
+ if (!is_initialized)
+ return;
+ featurePointer = enable ? featureProcArray : nullptr;
+ initSelectableFeature(enable ? SelectFeatureSet : nullptr);
+}
+
//////////////////////////////////////////////////////////////////////////////
//
// PYSIDE-1019: Support switchable extensions
diff --git a/sources/pyside6/libpyside/feature_select.h b/sources/pyside6/libpyside/feature_select.h
index 845828a4c..c7c14df3c 100644
--- a/sources/pyside6/libpyside/feature_select.h
+++ b/sources/pyside6/libpyside/feature_select.h
@@ -49,6 +49,7 @@ namespace Feature {
PYSIDE_API void init();
PYSIDE_API void Select(PyObject *obj);
PYSIDE_API PyObject *Select(PyTypeObject *type);
+PYSIDE_API void Enable(bool);
} // namespace Feature
} // namespace PySide
diff --git a/sources/pyside6/libpyside/pyside.cpp b/sources/pyside6/libpyside/pyside.cpp
index 7cc17f0c6..75b3eb16f 100644
--- a/sources/pyside6/libpyside/pyside.cpp
+++ b/sources/pyside6/libpyside/pyside.cpp
@@ -50,6 +50,7 @@
#include "pysidemetafunction_p.h"
#include "pysidemetafunction.h"
#include "dynamicqmetaobject.h"
+#include "feature_select.h"
#include <autodecref.h>
#include <basewrapper.h>
@@ -285,7 +286,11 @@ void initQObjectSubType(SbkObjectType *type, PyObject *args, PyObject * /* kwds
qWarning("Sub class of QObject not inheriting QObject!? Crash will happen when using %s.", className.constData());
return;
}
+ // PYSIDE-1463: Don't change feature selection durin subtype initialization.
+ // This behavior is observed with PySide 6.
+ PySide::Feature::Enable(false);
initDynamicMetaObject(type, userData->mo.update(), userData->cppObjSize);
+ PySide::Feature::Enable(true);
}
void initQApp()
diff --git a/sources/shiboken6/libshiboken/basewrapper.cpp b/sources/shiboken6/libshiboken/basewrapper.cpp
index ce6b0bacf..62e2df2cf 100644
--- a/sources/shiboken6/libshiboken/basewrapper.cpp
+++ b/sources/shiboken6/libshiboken/basewrapper.cpp
@@ -474,9 +474,11 @@ PyObject *MakeQAppWrapper(PyTypeObject *type)
// SbkObject_GenericSetAttr PyObject_GenericSetAttr
//
-void initSelectableFeature(SelectableFeatureHook func)
+SelectableFeatureHook initSelectableFeature(SelectableFeatureHook func)
{
+ auto ret = SelectFeatureSet;
SelectFeatureSet = func;
+ return ret;
}
static PyObject *mangled_type_getattro(PyTypeObject *type, PyObject *name)
@@ -629,10 +631,13 @@ static PyObject *SbkObjectTypeTpNew(PyTypeObject *metatype, PyObject *args, PyOb
sotp->d_func = nullptr;
sotp->is_user_type = 1;
+ // PYSIDE-1463: Prevent feature switching while in the creation process
+ auto saveFeature = initSelectableFeature(nullptr);
for (SbkObjectType *base : bases) {
if (PepType_SOTP(base)->subtype_init)
PepType_SOTP(base)->subtype_init(newType, args, kwds);
}
+ initSelectableFeature(saveFeature);
return reinterpret_cast<PyObject *>(newType);
}
diff --git a/sources/shiboken6/libshiboken/basewrapper.h b/sources/shiboken6/libshiboken/basewrapper.h
index fedd143c2..364f6c5cb 100644
--- a/sources/shiboken6/libshiboken/basewrapper.h
+++ b/sources/shiboken6/libshiboken/basewrapper.h
@@ -93,9 +93,10 @@ typedef void (*ObjectDestructor)(void *);
typedef void (*SubTypeInitHook)(SbkObjectType *, PyObject *, PyObject *);
-// PYSIDE-1019: Set the function to select the current feature.
+/// PYSIDE-1019: Set the function to select the current feature.
+/// Return value is the previous content.
typedef PyObject *(*SelectableFeatureHook)(PyTypeObject *);
-LIBSHIBOKEN_API void initSelectableFeature(SelectableFeatureHook func);
+LIBSHIBOKEN_API SelectableFeatureHook initSelectableFeature(SelectableFeatureHook func);
// PYSIDE-1019: Get access to PySide reserved bits.
LIBSHIBOKEN_API int SbkObjectType_GetReserved(PyTypeObject *type);