aboutsummaryrefslogtreecommitdiffstats
path: root/examples/scriptableapplication/pythonutils.cpp
diff options
context:
space:
mode:
authorChristian Tismer <tismer@stackless.com>2021-11-18 11:43:27 +0100
committerChristian Tismer <tismer@stackless.com>2021-12-10 17:54:36 +0100
commita0ef585ef721710e04ed844cf9fcf574725a2a38 (patch)
tree2aba793fe76a16d6b53bcbf6a19b7367c61fb491 /examples/scriptableapplication/pythonutils.cpp
parent4b29cc46f5df9194b85bce5e85fd002604e8fcfe (diff)
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 <Friedemann.Kleint@qt.io> (cherry picked from commit 2149a45fddeedea317dccbfe5e5b14e13888e5c9) Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'examples/scriptableapplication/pythonutils.cpp')
-rw-r--r--examples/scriptableapplication/pythonutils.cpp8
1 files changed, 8 insertions, 0 deletions
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;