aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken2/libshiboken
diff options
context:
space:
mode:
authorChristian Tismer <tismer@stackless.com>2020-09-03 11:49:22 +0200
committerChristian Tismer <tismer@stackless.com>2020-09-04 10:42:01 +0200
commit2bd69b9877f7b240512f03b4df042adf9acea744 (patch)
treecb5667739064968de6b2a723da2195cccbb9d277 /sources/shiboken2/libshiboken
parentd02b070e23c757fa72a66a4049a659f4f5c5fc77 (diff)
Add compatibility with Nuitka
This patch is based upon the old PYSIDE-198 proposal. It worked with a few changes on Python 3 with limited API disabled. When enabling the Limited API, there were a lot of crashes. This was due to the way we need to get around access to certain implementations. This showed that the original patch was wrong in the expression of bindingmanager.cpp bool isCompiled = !isMethod && Py_TYPE(method)->tp_call != nullptr; After fixing this expression with bool isCompiled = !isMethod && Py_TYPE(method) != &PyCFunction_Type && Py_TYPE(method)->tp_call != nullptr; everything worked fine with the Limited API, too. Fixes: PYSIDE-198 Task-number: PYSIDE-829 Change-Id: I4f887c639628041682052e90ba4c72aa98284e9e Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'sources/shiboken2/libshiboken')
-rw-r--r--sources/shiboken2/libshiboken/bindingmanager.cpp14
-rw-r--r--sources/shiboken2/libshiboken/sbkstaticstrings.cpp2
-rw-r--r--sources/shiboken2/libshiboken/sbkstaticstrings.h1
-rw-r--r--sources/shiboken2/libshiboken/sbkstaticstrings_p.h1
4 files changed, 12 insertions, 6 deletions
diff --git a/sources/shiboken2/libshiboken/bindingmanager.cpp b/sources/shiboken2/libshiboken/bindingmanager.cpp
index 4f8c6068a..7b06a4a00 100644
--- a/sources/shiboken2/libshiboken/bindingmanager.cpp
+++ b/sources/shiboken2/libshiboken/bindingmanager.cpp
@@ -305,15 +305,21 @@ PyObject *BindingManager::getOverride(const void *cptr, PyObject *methodNameCach
PyObject *method = PyObject_GetAttr(reinterpret_cast<PyObject *>(wrapper), pyMethodName);
- if (method && PyMethod_Check(method)
- && PyMethod_GET_SELF(method) == reinterpret_cast<PyObject *>(wrapper)) {
+ // PYSIDE-198: Support for Nuitka compiled methods.
+ bool isMethod = method && PyMethod_Check(method);
+ bool isCompiled = !( isMethod
+ || Py_TYPE(method) == &PyCFunction_Type
+ || Py_TYPE(method)->tp_call == nullptr);
+ Shiboken::AutoDecRef meth_self(PyObject_GetAttr(method, Shiboken::PyMagicName::self()));
+ bool wrapsParent = meth_self.object() == reinterpret_cast<PyObject *>(wrapper);
+ if ((isMethod && wrapsParent) || isCompiled) {
PyObject *defaultMethod;
PyObject *mro = Py_TYPE(wrapper)->tp_mro;
// The first class in the mro (index 0) is the class being checked and it should not be tested.
// The last class in the mro (size - 1) is the base Python object class which should not be tested also.
- for (int i = 1; i < PyTuple_GET_SIZE(mro) - 1; i++) {
- auto *parent = reinterpret_cast<PyTypeObject *>(PyTuple_GET_ITEM(mro, i));
+ for (int idx = 1; idx < PyTuple_GET_SIZE(mro) - 1; ++idx) {
+ auto *parent = reinterpret_cast<PyTypeObject *>(PyTuple_GET_ITEM(mro, idx));
if (parent->tp_dict) {
defaultMethod = PyDict_GetItem(parent->tp_dict, pyMethodName);
if (defaultMethod && PyMethod_GET_FUNCTION(method) != defaultMethod)
diff --git a/sources/shiboken2/libshiboken/sbkstaticstrings.cpp b/sources/shiboken2/libshiboken/sbkstaticstrings.cpp
index 602c0619b..564853edb 100644
--- a/sources/shiboken2/libshiboken/sbkstaticstrings.cpp
+++ b/sources/shiboken2/libshiboken/sbkstaticstrings.cpp
@@ -86,6 +86,7 @@ STATIC_STRING_IMPL(members, "__members__")
STATIC_STRING_IMPL(module, "__module__")
STATIC_STRING_IMPL(name, "__name__")
STATIC_STRING_IMPL(qualname, "__qualname__")
+STATIC_STRING_IMPL(self, "__self__")
// Internal:
STATIC_STRING_IMPL(base, "__base__")
@@ -99,7 +100,6 @@ STATIC_STRING_IMPL(iter, "__iter__")
STATIC_STRING_IMPL(mro, "__mro__")
STATIC_STRING_IMPL(new_, "__new__")
STATIC_STRING_IMPL(objclass, "__objclass__")
-STATIC_STRING_IMPL(self, "__self__")
STATIC_STRING_IMPL(signature, "__signature__")
STATIC_STRING_IMPL(weakrefoffset, "__weakrefoffset__")
} // namespace PyMagicName
diff --git a/sources/shiboken2/libshiboken/sbkstaticstrings.h b/sources/shiboken2/libshiboken/sbkstaticstrings.h
index df0c683b0..d8744bd8d 100644
--- a/sources/shiboken2/libshiboken/sbkstaticstrings.h
+++ b/sources/shiboken2/libshiboken/sbkstaticstrings.h
@@ -72,6 +72,7 @@ LIBSHIBOKEN_API PyObject *members();
LIBSHIBOKEN_API PyObject *module();
LIBSHIBOKEN_API PyObject *name();
LIBSHIBOKEN_API PyObject *qualname();
+LIBSHIBOKEN_API PyObject *self();
} // namespace PyMagicName
} // namespace Shiboken
diff --git a/sources/shiboken2/libshiboken/sbkstaticstrings_p.h b/sources/shiboken2/libshiboken/sbkstaticstrings_p.h
index 12c11376f..c33fa0299 100644
--- a/sources/shiboken2/libshiboken/sbkstaticstrings_p.h
+++ b/sources/shiboken2/libshiboken/sbkstaticstrings_p.h
@@ -67,7 +67,6 @@ PyObject *module();
PyObject *mro();
PyObject *new_();
PyObject *objclass();
-PyObject *self();
PyObject *signature();
PyObject *weakrefoffset();
} // namespace PyMagicName