After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 642715 - Can't have a GError out parameter to a Python callback without throwing exception.
Can't have a GError out parameter to a Python callback without throwing excep...
Status: RESOLVED FIXED
Product: pygobject
Classification: Bindings
Component: introspection
Git master
Other Linux
: Normal normal
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
Depends on:
Blocks:
 
 
Reported: 2011-02-18 21:24 UTC by Laszlo Pandy
Modified: 2011-02-19 08:51 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
[GI] Marshal Py_None to NULL for GError**. (995 bytes, patch)
2011-02-18 21:27 UTC, Laszlo Pandy
rejected Details | Review
[GI] Skip GError out parameters in Python closure. (1.45 KB, patch)
2011-02-18 21:53 UTC, Laszlo Pandy
accepted-commit_now Details | Review

Description Laszlo Pandy 2011-02-18 21:24:01 UTC
Right now we can't marshal GErrors, so a NotImplementedException is thrown. This is a problem for callbacks such as GdkPixbufSaveFunc, which has a GError as an out parameter.

GdkPixbufSaveFunc requires the return value (True/False) as well as the one out parameter to be returned from the Python callback. If you do "return True", an assertion fails because there are not enough out parameters for the closure marshaller. However if you do "return (True, None)" a NotImplementedException is thrown because we don't support marshalling GErrors.

It should be that if Py_None is passed, the GError is set to NULL. Any other Python value should still throw NotImplementedException until we can marshal them properly.
Comment 1 Laszlo Pandy 2011-02-18 21:27:03 UTC
Created attachment 181280 [details] [review]
[GI] Marshal Py_None to NULL for GError**.
Comment 2 johnp 2011-02-18 21:32:11 UTC
In order to keep ABI consistent I propose we always return NULL for callbacks that return GErrors.  The user should never be returning GErrors but should instead raise python or glib errors.  Since we can not marshal a python error to a GError yet the proposed solution is to simply return NULL for now in the GI callback return marshallers. This way the ABI for returning from such a function would always be:

return boolean

instead of 

return (boolean, None) for now and then

return boolean some version later
Comment 3 johnp 2011-02-18 21:34:53 UTC
Comment on attachment 181280 [details] [review]
[GI] Marshal Py_None to NULL for GError**.

I don't think we should ever support manipulating GErrors.  This should be fixed by treating GError returns as special and returning NULL always for right now.  They should not be treated as out values.
Comment 4 Laszlo Pandy 2011-02-18 21:53:56 UTC
Created attachment 181281 [details] [review]
[GI] Skip GError out parameters in Python closure.

Python code should have never have to explicitely return a GError.
Once we are able to marshal exceptions the Python code should
throw an exception instead. Until then, set GError to NULL, and
don't complain if a Python function doesn't return an arg for it.
Comment 5 johnp 2011-02-18 21:58:51 UTC
Comment on attachment 181281 [details] [review]
[GI] Skip GError out parameters in Python closure.

looks good, commit to both branches