GNOME Bugzilla – Bug 650176
Use (skip) annotation on return-val/args where appropriate
Last modified: 2015-02-07 16:45:23 UTC
In bug 649657 we added support for using the (skip) annotation on return values and parameters. We should convert all of GLib (and everything else but those are separate bugs) to use this annotation everywhere where appropriate. For example, as pointed out in bug 649657 comment 5, g_file_get_contents() should use this so python programmers can write e.g. [contents, len] = GLib.file_get_contents('/etc/hosts') instead of [success, contents, len] = GLib.file_get_contents('/etc/hosts') where the success return value is True unless an exception was raised (e.g. rendering success useless which is why we want to skip it). (Btw, another problem is that the returned contents variable probably shouldn't be of Python type 'str' since that won't work with embedded NUL bytes. Maybe g_file_get_contents() should a guchar* (or guint8*) instead of gchar* and then the binding would just DTRT - this would be an API break but not an ABI break. So I guess it's fine doing this in GLib.) Obviously, this breaks the Introspectable ABI of GLib but in a way it's really not different from all the other annotation additions that has been added to fix bugs. Well, maybe it is. So probably want to wait until the next ABI break. I don't know. I don't know how much change this is but I don't think it's too hard to do.
This sounds like a tedious task to do manually. Perhaps a silent assumption can be made for gboolean return values that they are redundant for throwing functions, and the fact of no-throw can itself indicate success in the binding. There might need to be an annotation to mark out non-redundant boolean returns, though. For one binding, Rust's would use a generically defined algebraic type `Result<RetType, Error>` for return values of throwing functions, which would carry an `Ok` value wrapping the return value in the no-error case, or an `Err` value with a wrapped `GError` in case of the `GError*` being set. The out parameter slots would be passed by mutable reference. So, no problem with the return signature there: if the error slot is not set, a Ok(false) will be returned.
*** This bug has been marked as a duplicate of bug 708301 ***
[Mass-moving gobject-introspection tickets to its own Bugzilla product - see bug 708029. Mass-filter your bugmail for this message: introspection20150207 ]