diff options
author | Alexandru Croitor <alexandru.croitor@qt.io> | 2017-02-16 14:53:39 +0100 |
---|---|---|
committer | Alexandru Croitor <alexandru.croitor@qt.io> | 2017-03-06 10:38:42 +0000 |
commit | 5c2d3e42ec548f66a8fe9ce2d53b7aa452be82b6 (patch) | |
tree | e8eadea605f2020cc381a1086fbcdc4256ef627e | |
parent | ab092d79915fcd795a606130b58cb3a061f66f8c (diff) |
Handle possible Python errors when invoking a global receiver callback
Previously the GlobalReceiverV2 instance did not check for the
occurrence of an error when calling its Python callback. This led to
to skipping all processing of QEvents as described in PYSIDE-478.
The fix is to check if a Python error ocurred, and print it (thus
handling it, and clearing the current active error).
Task-number: PYSIDE-360
Change-Id: Idc49dc6fc18da27e92043df8fbc46072efc73f72
Reviewed-by: Christian Tismer <tismer@stackless.com>
-rw-r--r-- | libpyside/globalreceiverv2.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/libpyside/globalreceiverv2.cpp b/libpyside/globalreceiverv2.cpp index 335b7eb1..a79d43c2 100644 --- a/libpyside/globalreceiverv2.cpp +++ b/libpyside/globalreceiverv2.cpp @@ -341,5 +341,18 @@ int GlobalReceiverV2::qt_metacall(QMetaObject::Call call, int id, void** args) SignalManager::callPythonMetaMethod(slot, args, callback, isShortCuit); } + // SignalManager::callPythonMetaMethod might have failed, in that case we have to print the + // error so it considered "handled". + if (PyErr_Occurred()) { + int reclimit = Py_GetRecursionLimit(); + // Inspired by Python's errors.c: PyErr_GivenExceptionMatches() function. + // Temporarily bump the recursion limit, so that PyErr_Print will not raise a recursion + // error again. Don't do it when the limit is already insanely high, to avoid overflow. + if (reclimit < (1 << 30)) + Py_SetRecursionLimit(reclimit + 5); + PyErr_Print(); + Py_SetRecursionLimit(reclimit); + } + return -1; } |