From 893f07e845f32c375c65675591df1c0cdaf4cb07 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 2 Nov 2021 13:30:49 +0100 Subject: Handle crash when passing arguments of wrong type in embedded application When passing arguments of wrong type in the scriptableapplication example, PyRun_String() fails and a crash occurs (NameError: name 'AppLib' is not defined). Catch this and return nullptr to get at an error message. Change-Id: Ie22cf81ebb0c390bb31684eadf19b682e4487361 Reviewed-by: Christian Tismer (cherry picked from commit 7d6ea931fdc0d919ac9fa5ddadeb931c2578151f) --- sources/shiboken2/libshiboken/signature/signature.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'sources/shiboken2/libshiboken/signature/signature.cpp') diff --git a/sources/shiboken2/libshiboken/signature/signature.cpp b/sources/shiboken2/libshiboken/signature/signature.cpp index 6880ea1f2..33157f5cb 100644 --- a/sources/shiboken2/libshiboken/signature/signature.cpp +++ b/sources/shiboken2/libshiboken/signature/signature.cpp @@ -453,6 +453,9 @@ static PyObject *adjustFuncName(const char *func_name) // Run `eval` on the type string to get the object. AutoDecRef obtype(PyRun_String(_path, Py_eval_input, ns, ns)); + if (obtype.isNull()) + return nullptr; + if (PyModule_Check(obtype.object())) { // This is a plain function. Return the unmangled name. return String::fromCString(func_name); -- cgit v1.2.3 From a0ef585ef721710e04ed844cf9fcf574725a2a38 Mon Sep 17 00:00:00 2001 From: Christian Tismer Date: Thu, 18 Nov 2021 11:43:27 +0100 Subject: signature: improve error handling for embedded applications Entering something like """ mainWindow.setPointer(None) """ crashes in an old version of scriptableapplication, which shows an omission in the signature interface. The error shows up whenever a builtin module cannot be imported. The error does not show up in PySide 6, because the module is declared as a builtin via `PyImport_AppendInittab`. * add registration of AppLib as a builtin (5.15) * insert builtin modules per default into the mapping module * simple recovery if a module cannot be found in sys.modules [ChangeLog][shiboken6] Error handling was improved for embedded applications and builtin modules are trusted as valid modules. Change-Id: I722212a52a5e3aae924f0b965578485ecaf185a9 Fixes: PYSIDE-1710 Reviewed-by: Friedemann Kleint (cherry picked from commit 2149a45fddeedea317dccbfe5e5b14e13888e5c9) Reviewed-by: Cristian Maureira-Fredes --- sources/shiboken2/libshiboken/signature/signature.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sources/shiboken2/libshiboken/signature/signature.cpp') diff --git a/sources/shiboken2/libshiboken/signature/signature.cpp b/sources/shiboken2/libshiboken/signature/signature.cpp index 33157f5cb..e17a8e08f 100644 --- a/sources/shiboken2/libshiboken/signature/signature.cpp +++ b/sources/shiboken2/libshiboken/signature/signature.cpp @@ -454,7 +454,7 @@ static PyObject *adjustFuncName(const char *func_name) // Run `eval` on the type string to get the object. AutoDecRef obtype(PyRun_String(_path, Py_eval_input, ns, ns)); if (obtype.isNull()) - return nullptr; + return String::fromCString(func_name); if (PyModule_Check(obtype.object())) { // This is a plain function. Return the unmangled name. -- cgit v1.2.3