returning PyObject*, not propogating NULL?
Dynamic Python binding for Qt Applications
Brought to you by:
florianlink,
marcusbarann
Hi,
I have a method that uses the python api directly, something like this:
// this is a public slot
PyObject* SomeClass::someMethod() {
// some code
// …
// problematic bit:
PyErr_SetString(this->error, "SomeException");
return NULL;
}
First off, this is obviously a special case - just assume this makes sense for my use-case ;-)
I'm delighted PythonQt automatically detects the PyObject* and returns it as-is. However, when the exception is set, python doesn't throw the exception immediately. This typically happens when the given function does not return NULL. Thus, I'm leaping to the conclusion that even tho my method returns NULL, the PythonQt SLOT call is not? Can this be fixed?
Yes, error propagation from called slots to Python are not yet supported.
This is because I developed PythonQt for a software that supports both JavaScript and Python, so it was never an option to let a slot do something Python-specific.
I think there are two things that would need to be addressed:
1. PythonQt clears the Python error state at some places, I think the problem was that I got errors using the Python C-API and used a general PyErr_Clear() to fix that. Those places would need reviewing and checking, which C-API calls can induce errors
2. When a slot is called using qt_metacall, the error state should be checked before and after the call and if there is an error after the call which was not present before the call, the PythonQtSlot object could return NULL for the call.
It is not really a lot of work, but requires sorrow testing why those PyErr_Clear calls where needed.
If you submit a patch, I will review and integrate it.
regards,
Florian
OK, thanks. This is not a big issue for me at the moment, but if it gets annoying I'll get motivated and create a patch ;-)