aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside6/libpyside/feature_select.cpp
diff options
context:
space:
mode:
authorChristian Tismer <tismer@stackless.com>2020-11-06 14:53:53 +0100
committerChristian Tismer <tismer@stackless.com>2020-11-11 17:29:38 +0000
commit12c93597dd09c68e2d619e03f9867afbc56dcf48 (patch)
tree8fdf4cff22b88b1dbab209f744568923fc963c98 /sources/pyside6/libpyside/feature_select.cpp
parentce8dcd2c7755aa5272f484c0e475a1b65b8a01c3 (diff)
__feature__: provide useful error message when feature is active
Features seem to work quite good so far, but they clearly need much more testing. One of the problems is that error messages are produced, but the function name is not found and we get an ugly default error message. This is an efficient implementation that does all name mangling in the C code. A helper dict avoids linear search for properties. Task-number: PYSIDE-1019 Change-Id: Ic87c4a6e7dc2b2a251e809d6df0eb7fb9ca8021c Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'sources/pyside6/libpyside/feature_select.cpp')
-rw-r--r--sources/pyside6/libpyside/feature_select.cpp20
1 files changed, 15 insertions, 5 deletions
diff --git a/sources/pyside6/libpyside/feature_select.cpp b/sources/pyside6/libpyside/feature_select.cpp
index d6d77a530..23a39ed34 100644
--- a/sources/pyside6/libpyside/feature_select.cpp
+++ b/sources/pyside6/libpyside/feature_select.cpp
@@ -43,7 +43,6 @@
#include "class_property.h"
#include <shiboken.h>
-#include <sbkstaticstrings.h>
//////////////////////////////////////////////////////////////////////////////
//
@@ -142,7 +141,7 @@ static inline PyObject *getFeatureSelectId()
static PyObject *feature_dict = GetFeatureDict();
// these things are all borrowed
PyObject *globals = PyEval_GetGlobals();
- if ( globals == nullptr
+ if (globals == nullptr
|| globals == cached_globals)
return last_select_id;
@@ -151,7 +150,7 @@ static inline PyObject *getFeatureSelectId()
return last_select_id;
PyObject *select_id = PyDict_GetItem(feature_dict, modname);
- if ( select_id == nullptr
+ if (select_id == nullptr
|| !PyInt_Check(select_id) // int/long cheating
|| select_id == undef)
return last_select_id;
@@ -525,7 +524,7 @@ static bool feature_01_addLowerNames(PyTypeObject *type, PyObject *prev_dict, in
// We first copy the things over which will not be changed:
while (PyDict_Next(prev_dict, &pos, &key, &value)) {
- if ( Py_TYPE(value) != PepMethodDescr_TypePtr
+ if (Py_TYPE(value) != PepMethodDescr_TypePtr
&& Py_TYPE(value) != PepStaticMethod_TypePtr) {
if (PyDict_SetItem(lower_dict, key, value))
return false;
@@ -641,6 +640,15 @@ static bool feature_02_true_property(PyTypeObject *type, PyObject *prev_dict, in
if (PyDict_Update(prop_dict, prev_dict) < 0)
return false;
+ // For speed, we establish a helper dict that maps the removed property
+ // method names to property name.
+ PyObject *prop_methods = PyDict_GetItem(prop_dict, PyMagicName::property_methods());
+ if (prop_methods == nullptr) {
+ prop_methods = PyDict_New();
+ if (prop_methods == nullptr
+ || PyDict_SetItem(prop_dict, PyMagicName::property_methods(), prop_methods))
+ return false;
+ }
// We then replace methods by properties.
bool lower = (id & 0x01) != 0;
auto props = SbkObjectType_GetPropertyStrings(type);
@@ -662,7 +670,9 @@ static bool feature_02_true_property(PyTypeObject *type, PyObject *prev_dict, in
AutoDecRef PyProperty(createProperty(type, getter, setter));
if (PyProperty.isNull())
return false;
- if (PyDict_SetItem(prop_dict, name, PyProperty) < 0)
+ if (PyDict_SetItem(prop_dict, name, PyProperty) < 0
+ || PyDict_SetItem(prop_methods, read, name) < 0
+ || (setter != nullptr && PyDict_SetItem(prop_methods, write, name) < 0))
return false;
if (fields[0] != fields[1] && PyDict_GetItem(prop_dict, read))
if (PyDict_DelItem(prop_dict, read) < 0)