aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Tismer <tismer@stackless.com>2022-11-21 12:06:18 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-11-29 21:10:14 +0000
commit4c1618d7ef8da5d4b45f29346ba6a1c7d34bce29 (patch)
tree406d7229eaf509a028160529d8d4e35511962d5b
parentbd809e6b2435b0c31b89ad9d413471c9d3470347 (diff)
__feature__: Cleanup before reworking the context switching
Some small changes: - Reserved bits are now signed - old comments were no more true - SelectFeatureSet simplified Task-number: PYSIDE-2029 Change-Id: Id8d83de4278bd4e618f5c601f9fa3c25ac172d53 Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> (cherry picked from commit 916bae507f76f4f063af81439f17cf11c914b4bd) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--sources/pyside6/libpyside/feature_select.cpp21
-rw-r--r--sources/pyside6/libpyside/feature_select.h2
-rw-r--r--sources/shiboken6/libshiboken/basewrapper.h2
-rw-r--r--sources/shiboken6/libshiboken/basewrapper_p.h2
-rw-r--r--sources/shiboken6/libshiboken/sbkfeature_base.cpp18
5 files changed, 24 insertions, 21 deletions
diff --git a/sources/pyside6/libpyside/feature_select.cpp b/sources/pyside6/libpyside/feature_select.cpp
index cf55ae7cf..b3117d40d 100644
--- a/sources/pyside6/libpyside/feature_select.cpp
+++ b/sources/pyside6/libpyside/feature_select.cpp
@@ -155,7 +155,7 @@ static inline PyObject *getSelectId(PyObject *dict)
static inline void setCurrentSelectId(PyTypeObject *type, PyObject *select_id)
{
- SbkObjectType_SetReserved(type, PyLong_AsSsize_t(select_id)); // int/long cheating
+ SbkObjectType_SetReserved(type, PyLong_AsSsize_t(select_id));
}
static inline void setCurrentSelectId(PyTypeObject *type, int id)
@@ -267,7 +267,7 @@ static bool createNewFeatureSet(PyTypeObject *type, PyObject *select_id)
Py_INCREF(prev_dict); // keep the first ref unchanged
if (!addNewDict(type, select_id))
return false;
- auto id = PyLong_AsSsize_t(select_id); // int/long cheating
+ auto id = PyLong_AsSsize_t(select_id);
if (id == -1)
return false;
setCurrentSelectId(type, id);
@@ -313,7 +313,7 @@ static bool SelectFeatureSetSubtype(PyTypeObject *type, PyObject *select_id)
return true;
}
-static inline PyObject *SelectFeatureSet(PyTypeObject *type)
+static inline void SelectFeatureSet(PyTypeObject *type)
{
/*
* This is the main function of the module.
@@ -325,8 +325,10 @@ static inline PyObject *SelectFeatureSet(PyTypeObject *type)
*/
if (Py_TYPE(type->tp_dict) == Py_TYPE(PyType_Type.tp_dict)) {
// We initialize the dynamic features by using our own dict type.
- if (!replaceClassDict(type))
- return nullptr;
+ if (!replaceClassDict(type)) {
+ Py_FatalError("failed to replace class dict!");
+ return;
+ }
}
PyObject *select_id = getFeatureSelectId(); // borrowed
PyObject *current_id = getCurrentSelectId(type); // borrowed
@@ -349,7 +351,7 @@ static inline PyObject *SelectFeatureSet(PyTypeObject *type)
// PYSIDE-1436: Clear all caches for the type and subtypes.
PyType_Modified(type);
}
- return type->tp_dict;
+ return;
}
// For cppgenerator:
@@ -358,14 +360,13 @@ void Select(PyObject *obj)
if (featurePointer == nullptr)
return;
auto type = Py_TYPE(obj);
- type->tp_dict = SelectFeatureSet(type);
+ SelectFeatureSet(type);
}
-PyObject *Select(PyTypeObject *type)
+void Select(PyTypeObject *type)
{
if (featurePointer != nullptr)
- type->tp_dict = SelectFeatureSet(type);
- return type->tp_dict;
+ SelectFeatureSet(type);
}
static bool feature_01_addLowerNames(PyTypeObject *type, PyObject *prev_dict, int id);
diff --git a/sources/pyside6/libpyside/feature_select.h b/sources/pyside6/libpyside/feature_select.h
index f7eed358b..af8f2c324 100644
--- a/sources/pyside6/libpyside/feature_select.h
+++ b/sources/pyside6/libpyside/feature_select.h
@@ -12,7 +12,7 @@ namespace Feature {
PYSIDE_API void init();
PYSIDE_API void Select(PyObject *obj);
-PYSIDE_API PyObject *Select(PyTypeObject *type);
+PYSIDE_API void Select(PyTypeObject *type);
PYSIDE_API void Enable(bool);
} // namespace Feature
diff --git a/sources/shiboken6/libshiboken/basewrapper.h b/sources/shiboken6/libshiboken/basewrapper.h
index 2c54c7d6a..947bfdd1c 100644
--- a/sources/shiboken6/libshiboken/basewrapper.h
+++ b/sources/shiboken6/libshiboken/basewrapper.h
@@ -58,7 +58,7 @@ typedef void (*SubTypeInitHook)(PyTypeObject *, PyObject *, PyObject *);
/// PYSIDE-1019: Set the function to select the current feature.
/// Return value is the previous content.
-typedef PyObject *(*SelectableFeatureHook)(PyTypeObject *);
+typedef void (*SelectableFeatureHook)(PyTypeObject *);
LIBSHIBOKEN_API SelectableFeatureHook initSelectableFeature(SelectableFeatureHook func);
/// PYSIDE-1019: Get access to PySide reserved bits.
diff --git a/sources/shiboken6/libshiboken/basewrapper_p.h b/sources/shiboken6/libshiboken/basewrapper_p.h
index 9f163836d..fcd22bf2d 100644
--- a/sources/shiboken6/libshiboken/basewrapper_p.h
+++ b/sources/shiboken6/libshiboken/basewrapper_p.h
@@ -98,7 +98,7 @@ struct SbkObjectTypePrivate
/// Pointer to a function responsible for deletion of the C++ instance calling the proper destructor.
ObjectDestructor cpp_dtor;
/// PYSIDE-1019: Caching the current select Id
- unsigned int pyside_reserved_bits : 8; // MSVC has bug with the sign bit!
+ int pyside_reserved_bits; // MSVC has bug with the sign bit, so use no bitfield.!
/// True if this type holds two or more C++ instances, e.g.: a Python class which inherits from two C++ classes.
unsigned int is_multicpp : 1;
/// True if this type was defined by the user.
diff --git a/sources/shiboken6/libshiboken/sbkfeature_base.cpp b/sources/shiboken6/libshiboken/sbkfeature_base.cpp
index 1d1399ae7..3b7439262 100644
--- a/sources/shiboken6/libshiboken/sbkfeature_base.cpp
+++ b/sources/shiboken6/libshiboken/sbkfeature_base.cpp
@@ -44,7 +44,7 @@ PyObject *getFeatureSelectId()
PyObject *select_id = PyDict_GetItem(feature_dict, modname);
if (select_id == nullptr
- || !PyLong_Check(select_id) // int/long cheating
+ || !PyLong_Check(select_id)
|| select_id == undef)
return last_select_id;
@@ -103,7 +103,7 @@ void disassembleFrame(const char *marker)
// Python 3.11
static int const PRECALL = 166;
-// we have "big instructins" with gaps after them
+// we have "big instructions" with gaps after them
static int const LOAD_ATTR_GAP = 4 * 2;
static int const LOAD_METHOD_GAP = 10 * 2;
// Python 3.7 - 3.10
@@ -222,7 +222,7 @@ PyObject *mangled_type_getattro(PyTypeObject *type, PyObject *name)
static PyObject *const _member_map_ = String::createStaticString("_member_map_");
if (SelectFeatureSet != nullptr)
- type->tp_dict = SelectFeatureSet(type);
+ SelectFeatureSet(type);
auto *ret = type_getattro(reinterpret_cast<PyObject *>(type), name);
// PYSIDE-1735: Be forgiving with strict enums and fetch the enum, silently.
@@ -340,8 +340,10 @@ PyObject *Sbk_TypeGet___dict__(PyTypeObject *type, void * /* context */)
auto dict = type->tp_dict;
if (dict == nullptr)
Py_RETURN_NONE;
- if (SelectFeatureSet != nullptr)
- dict = SelectFeatureSet(type);
+ if (SelectFeatureSet != nullptr) {
+ SelectFeatureSet(type);
+ dict = type->tp_dict;
+ }
return PyDictProxy_New(dict);
}
@@ -352,7 +354,7 @@ PyObject *SbkObject_GenericGetAttr(PyObject *obj, PyObject *name)
{
auto type = Py_TYPE(obj);
if (SelectFeatureSet != nullptr)
- type->tp_dict = SelectFeatureSet(type);
+ SelectFeatureSet(type);
return PyObject_GenericGetAttr(obj, name);
}
@@ -360,7 +362,7 @@ int SbkObject_GenericSetAttr(PyObject *obj, PyObject *name, PyObject *value)
{
auto type = Py_TYPE(obj);
if (SelectFeatureSet != nullptr)
- type->tp_dict = SelectFeatureSet(type);
+ SelectFeatureSet(type);
return PyObject_GenericSetAttr(obj, name, value);
}
@@ -394,7 +396,7 @@ void SbkObjectType_SetEnumFlagInfo(PyTypeObject *type, const char **strings)
void SbkObjectType_UpdateFeature(PyTypeObject *type)
{
if (SelectFeatureSet != nullptr)
- type->tp_dict = SelectFeatureSet(type);
+ SelectFeatureSet(type);
}
} // extern "C"