aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken6
diff options
context:
space:
mode:
authorFriedemann Kleint <[email protected]>2025-03-20 08:54:35 +0100
committerFriedemann Kleint <[email protected]>2025-03-20 16:44:45 +0100
commit0a6258be9fbf0812808807c5e9360f215d866a19 (patch)
tree107fcb499ec130342116e353d657c71afaf3524a /sources/shiboken6
parentd65666b764e7079d60a496d6ad6f17bacb7f1cdb (diff)
Move helper function isCompiledMethod() to libshiboken
Pick-to: 6.9 Task-number: PYSIDE-2916 Change-Id: I6e72977bfcf95c3c28cc160e07febb84220fa505 Reviewed-by: Shyamnath Premnadh <[email protected]>
Diffstat (limited to 'sources/shiboken6')
-rw-r--r--sources/shiboken6/libshiboken/bindingmanager.cpp4
-rw-r--r--sources/shiboken6/libshiboken/helper.cpp8
-rw-r--r--sources/shiboken6/libshiboken/helper.h3
3 files changed, 12 insertions, 3 deletions
diff --git a/sources/shiboken6/libshiboken/bindingmanager.cpp b/sources/shiboken6/libshiboken/bindingmanager.cpp
index f75c50c22..810592235 100644
--- a/sources/shiboken6/libshiboken/bindingmanager.cpp
+++ b/sources/shiboken6/libshiboken/bindingmanager.cpp
@@ -415,9 +415,7 @@ PyObject *BindingManager::getOverride(const void *cptr,
Py_DECREF(method);
method = nullptr;
}
- } else if (PyObject_HasAttr(method, PyName::im_self())
- && PyObject_HasAttr(method, PyName::im_func())
- && PyObject_HasAttr(method, Shiboken::PyMagicName::code())) {
+ } else if (isCompiledMethod(method)) {
PyObject *im_self = PyObject_GetAttr(method, PyName::im_self());
// Not retaining a reference inline with what PyMethod_GET_SELF does.
Py_DECREF(im_self);
diff --git a/sources/shiboken6/libshiboken/helper.cpp b/sources/shiboken6/libshiboken/helper.cpp
index 2a22cdcf2..ab388812e 100644
--- a/sources/shiboken6/libshiboken/helper.cpp
+++ b/sources/shiboken6/libshiboken/helper.cpp
@@ -621,6 +621,14 @@ const char *typeNameOf(const char *typeIdName)
return result;
}
+bool isCompiledMethod(PyObject *method)
+{
+ return method != nullptr && method != Py_None
+ && PyObject_HasAttr(method, PyName::im_self()) != 0
+ && PyObject_HasAttr(method, PyName::im_func()) != 0
+ && PyObject_HasAttr(method, Shiboken::PyMagicName::code()) != 0;
+}
+
#if !defined(Py_LIMITED_API) && PY_VERSION_HEX >= 0x030A0000 && !defined(PYPY_VERSION)
static int _getPyVerbose()
{
diff --git a/sources/shiboken6/libshiboken/helper.h b/sources/shiboken6/libshiboken/helper.h
index 2ec0e702f..63f76cb52 100644
--- a/sources/shiboken6/libshiboken/helper.h
+++ b/sources/shiboken6/libshiboken/helper.h
@@ -43,6 +43,9 @@ LIBSHIBOKEN_API int *sequenceToIntArray(PyObject *obj, bool zeroTerminated = fal
/// \returns Fixed name (allocated).
LIBSHIBOKEN_API const char *typeNameOf(const char *typeIdName);
+/// Returns whether \a method is a compiled method (Nuitka).
+LIBSHIBOKEN_API bool isCompiledMethod(PyObject *method);
+
/**
* Creates and automatically deallocates C++ arrays.
*/