aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Tismer <tismer@stackless.com>2022-11-29 15:03:16 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-11-29 21:10:28 +0000
commitc10447ccb2f2a7e7a335ba94b7449be730b5143d (patch)
tree66ef8e779346afb93e3a8a0c6b1a212e3ba625b0
parent1bb1f9b5ce6d1ad656c21768f2393d1bc75845d2 (diff)
__feature__: Remove the no longer efficient reserved_bits structure
The reserved_bits structure is no longer an optimization after moving to PyPy. Accessing any extra field involves always a dict lookup. - remove the reserved_bits field - re-order SbkObjectTypePrivate - replace access functions by currentSelectId() Task-number: PSYIDE-2029 Change-Id: I08642eace9a6399649c039bcc358ce678bbd4fd3 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> (cherry picked from commit 47a9622599822d5db2dd20f13f369c671c4c4fca) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--sources/pyside6/libpyside/feature_select.cpp15
-rw-r--r--sources/pyside6/libpyside/pyside.cpp7
-rw-r--r--sources/shiboken6/libshiboken/basewrapper.h4
-rw-r--r--sources/shiboken6/libshiboken/basewrapper_p.h17
-rw-r--r--sources/shiboken6/libshiboken/sbkfeature_base.cpp21
-rw-r--r--sources/shiboken6/libshiboken/signature/signature.cpp3
6 files changed, 21 insertions, 46 deletions
diff --git a/sources/pyside6/libpyside/feature_select.cpp b/sources/pyside6/libpyside/feature_select.cpp
index 17c6169af..695a0e61e 100644
--- a/sources/pyside6/libpyside/feature_select.cpp
+++ b/sources/pyside6/libpyside/feature_select.cpp
@@ -153,16 +153,6 @@ static inline PyObject *getSelectId(PyObject *dict)
return select_id;
}
-static inline void setCurrentSelectId(PyTypeObject *type, PyObject *select_id)
-{
- SbkObjectType_SetReserved(type, PyLong_AsSsize_t(select_id));
-}
-
-static inline void setCurrentSelectId(PyTypeObject *type, int id)
-{
- SbkObjectType_SetReserved(type, id);
-}
-
static bool replaceClassDict(PyTypeObject *type)
{
/*
@@ -184,7 +174,6 @@ static bool replaceClassDict(PyTypeObject *type)
// Replace `__dict__` which usually has refcount 1 (but see cyclic_test.py)
Py_DECREF(type->tp_dict);
type->tp_dict = new_dict;
- setCurrentSelectId(type, select_id.object());
return true;
}
@@ -205,7 +194,6 @@ static bool addNewDict(PyTypeObject *type, PyObject *select_id)
setNextDict(dict, new_dict);
setNextDict(new_dict, next_dict);
type->tp_dict = new_dict;
- setCurrentSelectId(type, select_id);
return true;
}
@@ -222,13 +210,11 @@ static inline bool moveToFeatureSet(PyTypeObject *type, PyObject *select_id)
// This works because small numbers are singleton objects.
if (current_id == select_id) {
type->tp_dict = dict;
- setCurrentSelectId(type, select_id);
return true;
}
dict = nextInCircle(dict);
} while (dict != initial_dict);
type->tp_dict = initial_dict;
- setCurrentSelectId(type, getSelectId(initial_dict));
return false;
}
@@ -261,7 +247,6 @@ static bool createNewFeatureSet(PyTypeObject *type, PyObject *select_id)
auto id = PyLong_AsSsize_t(select_id);
if (id == -1)
return false;
- setCurrentSelectId(type, id);
FeatureProc *proc = featurePointer;
for (int idx = id; *proc != nullptr; ++proc, idx >>= 1) {
if (idx & 1) {
diff --git a/sources/pyside6/libpyside/pyside.cpp b/sources/pyside6/libpyside/pyside.cpp
index 6b94fc0c8..b830a3115 100644
--- a/sources/pyside6/libpyside/pyside.cpp
+++ b/sources/pyside6/libpyside/pyside.cpp
@@ -31,6 +31,7 @@
#include <sbkconverter.h>
#include <sbkstring.h>
#include <sbkstaticstrings.h>
+#include <sbkfeature_base.h>
#include <QtCore/QByteArray>
#include <QtCore/QCoreApplication>
@@ -232,7 +233,7 @@ static bool _setProperty(PyObject *qObj, PyObject *name, PyObject *value, bool *
QByteArray propName(Shiboken::String::toCString(name));
auto type = Py_TYPE(qObj);
- int flags = SbkObjectType_GetReserved(type);
+ int flags = currentSelectId(type);
int prop_flag = flags & 0x02;
auto found = false;
QByteArray getterName{}, setterName{};
@@ -301,7 +302,7 @@ bool fillQtProperties(PyObject *qObj, const QMetaObject *metaObj, PyObject *kwds
PyObject *key, *value;
Py_ssize_t pos = 0;
- int flags = SbkObjectType_GetReserved(Py_TYPE(qObj));
+ int flags = currentSelectId(Py_TYPE(qObj));
int snake_flag = flags & 0x01;
while (PyDict_Next(kwds, &pos, &key, &value)) {
@@ -517,7 +518,7 @@ PyObject *getMetaDataFromQObject(QObject *cppSelf, PyObject *self, PyObject *nam
PyErr_Fetch(&type, &value, &traceback); // This was omitted for a loong time.
const char *cname = Shiboken::String::toCString(name);
- int flags = SbkObjectType_GetReserved(Py_TYPE(self));
+ int flags = currentSelectId(Py_TYPE(self));
int snake_flag = flags & 0x01;
uint cnameLen = qstrlen(cname);
if (std::strncmp("__", cname, 2)) {
diff --git a/sources/shiboken6/libshiboken/basewrapper.h b/sources/shiboken6/libshiboken/basewrapper.h
index 947bfdd1c..86806c917 100644
--- a/sources/shiboken6/libshiboken/basewrapper.h
+++ b/sources/shiboken6/libshiboken/basewrapper.h
@@ -61,10 +61,6 @@ typedef void (*SubTypeInitHook)(PyTypeObject *, PyObject *, PyObject *);
typedef void (*SelectableFeatureHook)(PyTypeObject *);
LIBSHIBOKEN_API SelectableFeatureHook initSelectableFeature(SelectableFeatureHook func);
-/// PYSIDE-1019: Get access to PySide reserved bits.
-LIBSHIBOKEN_API int SbkObjectType_GetReserved(PyTypeObject *type);
-LIBSHIBOKEN_API void SbkObjectType_SetReserved(PyTypeObject *type, int value);
-
/// PYSIDE-1626: Enforcing a context switch without further action.
LIBSHIBOKEN_API void SbkObjectType_UpdateFeature(PyTypeObject *type);
diff --git a/sources/shiboken6/libshiboken/basewrapper_p.h b/sources/shiboken6/libshiboken/basewrapper_p.h
index fcd22bf2d..fc3cc321c 100644
--- a/sources/shiboken6/libshiboken/basewrapper_p.h
+++ b/sources/shiboken6/libshiboken/basewrapper_p.h
@@ -97,15 +97,6 @@ struct SbkObjectTypePrivate
TypeDiscoveryFuncV2 type_discovery;
/// 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
- 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.
- unsigned int is_user_type : 1;
- /// Tells is the type is a value type or an object-type, see BEHAVIOUR_ *constants.
- unsigned int type_behaviour : 2;
- unsigned int delete_in_main_thread : 1;
/// C++ name
char *original_name;
/// Type user data
@@ -116,6 +107,14 @@ struct SbkObjectTypePrivate
const char **enumFlagInfo;
PyObject *enumFlagsDict;
PyObject *enumTypeDict;
+
+ /// 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.
+ unsigned int is_user_type : 1;
+ /// Tells is the type is a value type or an object-type, see BEHAVIOUR_ *constants.
+ unsigned int type_behaviour : 2;
+ unsigned int delete_in_main_thread : 1;
};
diff --git a/sources/shiboken6/libshiboken/sbkfeature_base.cpp b/sources/shiboken6/libshiboken/sbkfeature_base.cpp
index 3b7439262..9e28d1239 100644
--- a/sources/shiboken6/libshiboken/sbkfeature_base.cpp
+++ b/sources/shiboken6/libshiboken/sbkfeature_base.cpp
@@ -56,9 +56,13 @@ PyObject *getFeatureSelectId()
int currentSelectId(PyTypeObject *type)
{
- int sel = SbkObjectType_GetReserved(type);
- // This could theoretically be -1 if used too early.
- assert(sel >= 0);
+ PyObject *PyId = PyObject_GetAttr(type->tp_dict, PyName::select_id());
+ if (PyId == nullptr) {
+ PyErr_Clear();
+ return 0x00;
+ }
+ int sel = PyLong_AsLong(PyId);
+ Py_DECREF(PyId);
return sel;
}
@@ -366,17 +370,6 @@ int SbkObject_GenericSetAttr(PyObject *obj, PyObject *name, PyObject *value)
return PyObject_GenericSetAttr(obj, name, value);
}
-// Caching the select Id.
-int SbkObjectType_GetReserved(PyTypeObject *type)
-{
- return PepType_SOTP(type)->pyside_reserved_bits;
-}
-
-void SbkObjectType_SetReserved(PyTypeObject *type, int value)
-{
- PepType_SOTP(type)->pyside_reserved_bits = value;
-}
-
const char **SbkObjectType_GetPropertyStrings(PyTypeObject *type)
{
return PepType_SOTP(type)->propertyStrings;
diff --git a/sources/shiboken6/libshiboken/signature/signature.cpp b/sources/shiboken6/libshiboken/signature/signature.cpp
index 808edc5cf..f83618779 100644
--- a/sources/shiboken6/libshiboken/signature/signature.cpp
+++ b/sources/shiboken6/libshiboken/signature/signature.cpp
@@ -21,6 +21,7 @@
#include "sbkstring.h"
#include "sbkstaticstrings.h"
#include "sbkstaticstrings_p.h"
+#include "sbkfeature_base.h"
#include <structmember.h>
@@ -534,7 +535,7 @@ static PyObject *adjustFuncName(const char *func_name)
// Find the feature flags
auto type = reinterpret_cast<PyTypeObject *>(obtype.object());
auto dict = type->tp_dict;
- int id = SbkObjectType_GetReserved(type);
+ int id = currentSelectId(type);
id = id < 0 ? 0 : id; // if undefined, set to zero
auto lower = id & 0x01;
auto is_prop = id & 0x02;