aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken6
diff options
context:
space:
mode:
authorFriedemann Kleint <[email protected]>2025-03-25 19:44:20 +0100
committerFriedemann Kleint <[email protected]>2025-05-07 22:57:49 +0200
commit05f8aa42fe6ff3fbda39c81565dccee8819b9c89 (patch)
tree03c1bd13e2f0aef64b05052cd2f9908a6fc65c82 /sources/shiboken6
parentd8ca812879ad70cd2aa914ea76cd529786deadc6 (diff)
libshiboken: Move override name calculation into basewrapper
Task-number: PYSIDE-2916 Change-Id: I4e4619b5144451512be3eadc6810df3f3f47ada0 Reviewed-by: Christian Tismer <[email protected]>
Diffstat (limited to 'sources/shiboken6')
-rw-r--r--sources/shiboken6/libshiboken/basewrapper.cpp30
-rw-r--r--sources/shiboken6/libshiboken/bindingmanager.cpp19
-rw-r--r--sources/shiboken6/libshiboken/bindingmanager.h2
3 files changed, 31 insertions, 20 deletions
diff --git a/sources/shiboken6/libshiboken/basewrapper.cpp b/sources/shiboken6/libshiboken/basewrapper.cpp
index a65359a1e..3e26b4605 100644
--- a/sources/shiboken6/libshiboken/basewrapper.cpp
+++ b/sources/shiboken6/libshiboken/basewrapper.cpp
@@ -761,6 +761,28 @@ PyObject *Sbk_ReturnFromPython_Self(PyObject *self)
} //extern "C"
+// Determine name of a Python override of a virtual method according to features
+// and populate name cache.
+static PyObject *overrideMethodName(PyObject *pySelf, const char *methodName,
+ PyObject **nameCache)
+{
+ // PYSIDE-1626: Touch the type to initiate switching early.
+ auto *obType = Py_TYPE(pySelf);
+ SbkObjectType_UpdateFeature(obType);
+
+ const int flag = currentSelectId(obType);
+ const int propFlag = isdigit(methodName[0]) ? methodName[0] - '0' : 0;
+ const bool is_snake = flag & 0x01;
+ PyObject *pyMethodName = nameCache[is_snake]; // borrowed
+ if (pyMethodName == nullptr) {
+ if (propFlag)
+ methodName += 2; // skip the propFlag and ':'
+ pyMethodName = Shiboken::String::getSnakeCaseName(methodName, is_snake);
+ nameCache[is_snake] = pyMethodName;
+ }
+ return pyMethodName;
+}
+
// The virtual function call
PyObject *Sbk_GetPyOverride(const void *voidThis, PyTypeObject *typeObject,
Shiboken::GilState &gil, const char *funcName,
@@ -773,9 +795,13 @@ PyObject *Sbk_GetPyOverride(const void *voidThis, PyTypeObject *typeObject,
SbkObject *wrapper = bindingManager.retrieveWrapper(voidThis, typeObject);
// The refcount can be 0 if the object is dieing and someone called
// a virtual method from the destructor
- if (wrapper == nullptr || Py_REFCNT(reinterpret_cast<const PyObject *>(wrapper)) == 0)
+ if (wrapper == nullptr)
+ return nullptr;
+ auto *pySelf = reinterpret_cast<PyObject *>(wrapper);
+ if (Py_REFCNT(pySelf) == 0)
return nullptr;
- pyOverride = Shiboken::BindingManager::getOverride(wrapper, nameCache, funcName);
+ PyObject *pyMethodName = overrideMethodName(pySelf, funcName, nameCache);
+ pyOverride = Shiboken::BindingManager::getOverride(wrapper, pyMethodName);
if (pyOverride == nullptr) {
resultCache = true;
gil.release();
diff --git a/sources/shiboken6/libshiboken/bindingmanager.cpp b/sources/shiboken6/libshiboken/bindingmanager.cpp
index 3652e4a4a..25cc5c00a 100644
--- a/sources/shiboken6/libshiboken/bindingmanager.cpp
+++ b/sources/shiboken6/libshiboken/bindingmanager.cpp
@@ -366,23 +366,8 @@ SbkObject *BindingManager::retrieveWrapper(const void *cptr, PyTypeObject *typeO
return it != m_d->wrapperMapper.cend() ? it->second : nullptr;
}
-PyObject *BindingManager::getOverride(SbkObject *wrapper, PyObject *nameCache[],
- const char *methodName)
-{
- // PYSIDE-1626: Touch the type to initiate switching early.
- SbkObjectType_UpdateFeature(Py_TYPE(wrapper));
-
- int flag = currentSelectId(Py_TYPE(wrapper));
- int propFlag = isdigit(methodName[0]) ? methodName[0] - '0' : 0;
- bool is_snake = flag & 0x01;
- PyObject *pyMethodName = nameCache[is_snake]; // borrowed
- if (pyMethodName == nullptr) {
- if (propFlag)
- methodName += 2; // skip the propFlag and ':'
- pyMethodName = Shiboken::String::getSnakeCaseName(methodName, is_snake);
- nameCache[is_snake] = pyMethodName;
- }
-
+PyObject *BindingManager::getOverride(SbkObject *wrapper, PyObject *pyMethodName)
+{
auto *obWrapper = reinterpret_cast<PyObject *>(wrapper);
auto *wrapper_dict = SbkObject_GetDict_NoRef(obWrapper);
if (PyObject *method = PyDict_GetItem(wrapper_dict, pyMethodName)) {
diff --git a/sources/shiboken6/libshiboken/bindingmanager.h b/sources/shiboken6/libshiboken/bindingmanager.h
index 4615bfb11..e2a4ac8ea 100644
--- a/sources/shiboken6/libshiboken/bindingmanager.h
+++ b/sources/shiboken6/libshiboken/bindingmanager.h
@@ -44,7 +44,7 @@ public:
SbkObject *retrieveWrapper(const void *cptr, PyTypeObject *typeObject) const;
SbkObject *retrieveWrapper(const void *cptr) const;
- static PyObject *getOverride(SbkObject *wrapper, PyObject *nameCache[], const char *methodName);
+ static PyObject *getOverride(SbkObject *wrapper, PyObject *pyMethodName);
void addClassInheritance(Module::TypeInitStruct *parent, Module::TypeInitStruct *child);
/// Try to find the correct type of cptr via type discovery knowing that it's at least