diff options
| author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-09-04 16:11:09 +0200 |
|---|---|---|
| committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-09-04 16:11:09 +0200 |
| commit | 704d3aab0f25d6b0d2939f1bb4e95ca73861ca9c (patch) | |
| tree | 69680c1ce0a1a296aa1ed78fdbff30f583172e67 | |
| parent | d6d31c5c277d30080a6b92de3774460048dcf49e (diff) | |
| parent | fedc289138bd912384e71a91e49ef9ee7b8a0fbb (diff) | |
Merge remote-tracking branch 'origin/5.15' into dev
Change-Id: Ib1d2c1b76a043526e8f715e45296104cad085a4a
15 files changed, 59 insertions, 24 deletions
diff --git a/coin/module_config.yaml b/coin/module_config.yaml index 772166fb5..fd80acf9e 100644 --- a/coin/module_config.yaml +++ b/coin/module_config.yaml @@ -21,7 +21,7 @@ accept_configuration: not_in_values: [OPENSUSE_13_01, QEMU, WebAssembly, Ubuntu_18_04, SLES_12, SLES_15] - condition: property # MibnGW and msvc2015 are not supported property: target.compiler - not_in_values: [Mingw73, MSVC2015] + not_in_values: [Mingw, MSVC2015] - condition: and conditions: - condition: property diff --git a/sources/pyside2/PySide2/__init__.py.in b/sources/pyside2/PySide2/__init__.py.in index 94683b463..035cdd636 100644 --- a/sources/pyside2/PySide2/__init__.py.in +++ b/sources/pyside2/PySide2/__init__.py.in @@ -65,7 +65,8 @@ def _setupQtDirectories(): # Trigger signature initialization. try: # PYSIDE-829: Avoid non-existent attributes in compiled code (Nuitka). - eval("type.__signature__") + # We now use an explicit function instead of touching a signature. + _init_pyside_extension() except AttributeError: print(dedent('''\ {stars} diff --git a/sources/pyside2/libpyside/dynamicqmetaobject.cpp b/sources/pyside2/libpyside/dynamicqmetaobject.cpp index efdf33ac9..2fbda3f6a 100644 --- a/sources/pyside2/libpyside/dynamicqmetaobject.cpp +++ b/sources/pyside2/libpyside/dynamicqmetaobject.cpp @@ -533,7 +533,8 @@ void MetaObjectBuilderPrivate::parsePythonType(PyTypeObject *type) const int index = m_baseObject->indexOfProperty(String::toCString(key)); if (index == -1) addProperty(String::toCString(key), value); - } else if (PyFunction_Check(value)) { + } else if (Py_TYPE(value)->tp_call != nullptr) { + // PYSIDE-198: PyFunction_Check does not work with Nuitka. // Register slots. if (PyObject_HasAttr(value, slotAttrName)) { PyObject *signatureList = PyObject_GetAttr(value, slotAttrName); diff --git a/sources/pyside2/libpyside/pysideslot.cpp b/sources/pyside2/libpyside/pysideslot.cpp index e60115450..7bfd1719a 100644 --- a/sources/pyside2/libpyside/pysideslot.cpp +++ b/sources/pyside2/libpyside/pysideslot.cpp @@ -47,6 +47,8 @@ #include <QtCore/QString> #include <signature.h> +using namespace Shiboken; + struct SlotData { QByteArray name; @@ -136,23 +138,25 @@ PyObject *slotCall(PyObject *self, PyObject *args, PyObject * /* kw */) callback = PyTuple_GetItem(args, 0); Py_INCREF(callback); - if (PyFunction_Check(callback)) { + if (Py_TYPE(callback)->tp_call != nullptr) { PySideSlot *data = reinterpret_cast<PySideSlot *>(self); if (!data->slotData) data->slotData = new SlotData; - if (data->slotData->name.isEmpty()) - data->slotData->name = Shiboken::String::toCString(PepFunction_GetName(callback)); - + if (data->slotData->name.isEmpty()) { + // PYSIDE-198: Use PyObject_GetAttr instead of PepFunction_GetName to support Nuitka. + AutoDecRef funcName(PyObject_GetAttr(callback, PyMagicName::name())); + data->slotData->name = String::toCString(funcName); + } const QByteArray returnType = QMetaObject::normalizedType(data->slotData->resultType); const QByteArray signature = returnType + ' ' + data->slotData->name + '(' + data->slotData->args + ')'; if (!pySlotName) - pySlotName = Shiboken::String::fromCString(PYSIDE_SLOT_LIST_ATTR); + pySlotName = String::fromCString(PYSIDE_SLOT_LIST_ATTR); - PyObject *pySignature = Shiboken::String::fromCString(signature); + PyObject *pySignature = String::fromCString(signature); PyObject *signatureList = 0; if (PyObject_HasAttr(callback, pySlotName)) { signatureList = PyObject_GetAttr(callback, pySlotName); diff --git a/sources/pyside2/tests/QtCore/qprocess_test.py b/sources/pyside2/tests/QtCore/qprocess_test.py index 2e0ad3807..daaf0843b 100644 --- a/sources/pyside2/tests/QtCore/qprocess_test.py +++ b/sources/pyside2/tests/QtCore/qprocess_test.py @@ -48,13 +48,14 @@ class TestQProcess (unittest.TestCase): def testPid(self): p = QProcess() - p.start("dir") + p.start("dir", []) p.waitForStarted() pid = p.pid() # We can't test the pid method result because it returns 0 when the # process isn't running if p.state() == QProcess.Running: self.assertNotEqual(pid, 0) + p.waitForFinished() else: print("PROCESS ALREADY DEAD :-/") 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/embed/signature_bootstrap.py b/sources/shiboken2/libshiboken/embed/signature_bootstrap.py index 3a74bb42e..b7d9d2793 100644 --- a/sources/shiboken2/libshiboken/embed/signature_bootstrap.py +++ b/sources/shiboken2/libshiboken/embed/signature_bootstrap.py @@ -73,7 +73,7 @@ def bootstrap(): if recursion_trap: # we are probably called from outside, already print("Recursion occurred in Bootstrap. Did you start by hand? Then it's ok.") - print("""But you should trigger start by 'eval("type.__signature__")', only!""") + print("But you should trigger start by '_init_pyside_extension()', only!") recursion_trap += 1 @contextmanager 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 diff --git a/sources/shiboken2/libshiboken/signature.cpp b/sources/shiboken2/libshiboken/signature.cpp index e2c02a196..70f1e8de7 100644 --- a/sources/shiboken2/libshiboken/signature.cpp +++ b/sources/shiboken2/libshiboken/signature.cpp @@ -98,6 +98,7 @@ static PyObject *PySide_BuildSignatureProps(PyObject *class_mod); static void init_module_1(void); static void init_module_2(void); +static PyObject *_init_pyside_extension(PyObject * /* self */, PyObject * /* args */); static PyObject * CreateSignature(PyObject *props, PyObject *key) @@ -486,8 +487,14 @@ static const unsigned char PySide_SignatureLoader[] = { #include "embed/signature_bootstrap_inc.h" }; +// This function will be inserted into __builtins__. +static PyMethodDef init_methods[] = { + {"_init_pyside_extension", (PyCFunction)_init_pyside_extension, METH_NOARGS}, + {nullptr, nullptr} +}; + static safe_globals_struc * -init_phase_1(void) +init_phase_1(PyMethodDef *init_meth) { { auto *p = reinterpret_cast<safe_globals_struc *> @@ -582,6 +589,12 @@ init_phase_1(void) // This function will be disabled until phase 2 is done. p->finish_import_func = nullptr; + // Initialize the explicit init function. + Shiboken::AutoDecRef init(PyCFunction_NewEx(init_meth, nullptr, nullptr)); + if (init.isNull() + || PyDict_SetItemString(PyEval_GetBuiltins(), init_meth->ml_name, init) != 0) + goto error; + return p; } error: @@ -870,6 +883,14 @@ get_signature(PyObject * /* self */, PyObject *args) Py_RETURN_NONE; } +static PyObject * +_init_pyside_extension(PyObject * /* self */, PyObject * /* args */) +{ + init_module_1(); + init_module_2(); + Py_RETURN_NONE; +} + //////////////////////////////////////////////////////////////////////////// // // This special Type_Ready does certain initializations earlier with @@ -955,7 +976,7 @@ init_module_1(void) static int init_done = 0; if (!init_done) { - pyside_globals = init_phase_1(); + pyside_globals = init_phase_1(init_methods); if (pyside_globals != nullptr) init_done = 1; } diff --git a/sources/shiboken2/shibokenmodule/__init__.py.in b/sources/shiboken2/shibokenmodule/__init__.py.in index eb392e847..6ba8929c9 100644 --- a/sources/shiboken2/shibokenmodule/__init__.py.in +++ b/sources/shiboken2/shibokenmodule/__init__.py.in @@ -26,5 +26,5 @@ if sys.version_info[0] == 3: from .shiboken2 import * -# Trigger signature initialization. -eval("type.__signature__") +# Trigger signature initialization via __builtins__. +_init_pyside_extension() diff --git a/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/__feature__.py b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/__feature__.py index 57b9eee15..482d81017 100644 --- a/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/__feature__.py +++ b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/__feature__.py @@ -103,7 +103,8 @@ Note: This are two imports. """ # XXX build an improved C version? I guess not. def _import(name, *args, **kwargs): - importing_module = sys._getframe(1).f_globals['__name__'] + # PYSIDE-1368: The `__name__` attribute does not need to exist in all modules. + importing_module = sys._getframe(1).f_globals.get("__name__", "__main__") existing = pyside_feature_dict.get(importing_module, 0) if name == "__feature__" and args[2]: diff --git a/sources/shiboken2/tests/minimalbinding/brace_pattern_test.py b/sources/shiboken2/tests/minimalbinding/brace_pattern_test.py index bcaccac44..550a609cb 100644 --- a/sources/shiboken2/tests/minimalbinding/brace_pattern_test.py +++ b/sources/shiboken2/tests/minimalbinding/brace_pattern_test.py @@ -49,7 +49,7 @@ from shiboken_paths import init_paths init_paths() import shiboken2 -eval("type.__signature__") # trigger bootstrap +_init_pyside_extension() # trigger bootstrap from shibokensupport.signature.lib.tool import build_brace_pattern diff --git a/sources/shiboken2/tests/samplebinding/pointerprimitivetype_test.py b/sources/shiboken2/tests/samplebinding/pointerprimitivetype_test.py index 3abd01cd9..648b35e41 100644 --- a/sources/shiboken2/tests/samplebinding/pointerprimitivetype_test.py +++ b/sources/shiboken2/tests/samplebinding/pointerprimitivetype_test.py @@ -54,7 +54,7 @@ init_paths() from sample import IntArray2, VirtualMethods import shiboken2 -eval("type.__signature__") # trigger init, which does not happen in tests +_init_pyside_extension() # trigger init, which does not happen in tests from shibokensupport.signature import typing |
