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 --- examples/scriptableapplication/pythonutils.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'examples/scriptableapplication/pythonutils.cpp') diff --git a/examples/scriptableapplication/pythonutils.cpp b/examples/scriptableapplication/pythonutils.cpp index c5e18f256..920d3e22e 100644 --- a/examples/scriptableapplication/pythonutils.cpp +++ b/examples/scriptableapplication/pythonutils.cpp @@ -68,8 +68,11 @@ extern "C" PyObject *PyInit_AppLib(); #else extern "C" void initAppLib(); +# define PyInit_AppLib initAppLib #endif +static const char moduleName[] = "AppLib"; + // This variable stores all Python types exported by this module. extern PyTypeObject **SbkAppLibTypes; @@ -113,6 +116,11 @@ State init() if (qEnvironmentVariableIsSet(virtualEnvVar)) initVirtualEnvironment(); + if (PyImport_AppendInittab(moduleName, PyInit_AppLib) == -1) { + qWarning("Failed to add the module '%s' to the table of built-in modules.", moduleName); + return state; + } + Py_Initialize(); qAddPostRoutine(cleanup); state = PythonInitialized; -- cgit v1.2.3