Details
-
Bug
-
Resolution: Done
-
P3: Somewhat important
-
None
-
6.3.1
-
None
-
Python 3.9.6
Windows 10
-
-
1b0134fd10 (pyside/pyside-setup/dev) 1b0134fd10 (pyside/tqtc-pyside-setup/dev)
Description
I enabled exceptions for my shiboken bindings and everything works great, except in one function. There exceptions where silently ignored. I noticed it has to do with the ownership transfer. Here is how the function is defined in the XML:
<object-type name="Engine" disable-wrapper="yes" exception-handling="auto-on"> <modify-function signature="add_element(Element *)" exception-handling="on"> <modify-argument index="1"> <define-ownership owner="c++" /> </modify-argument> </modify-function> </object-type>
Here is the generated C++ code "engine_wrapper.cpp"
if (!PyErr_Occurred()) { // add_element(Element*) try { cppSelf->add_element(cppArg0); } catch (const std::exception &e) { std::cout << "catch exception " << e.what() << std::endl; PyErr_SetString(PyExc_RuntimeError, e.what()); } catch (...) { PyErr_SetString(PyExc_RuntimeError, "An unknown exception was caught"); } std::cout << PyErr_Occurred() << std::endl; // Ownership transferences. Shiboken::Object::releaseOwnership(pyArg); std::cout << PyErr_Occurred() << std::endl; } } if (PyErr_Occurred()) { return {}; }
I added some instrumentation. Here is the output:
catch exception test
00007FFE9ED05D70
0000000000000000
As you can see the exception is caught. The PyErr_SetString is set. However it resets in the releaseOwnership code.
I don't think its a good idea to ignore the error, so it should be properly propagate.
Still open is of course what happens with the ownership in this case. I would still transfer it, and leave the responsibility to the caller.
Let me know what you think.