GNOME Bugzilla – Bug 708301
Handle 'success' boolean returns more gracefully
Last modified: 2018-01-25 14:03:38 UTC
gobject-introspection should have some notion of when a function like so: gboolean foo_do_stuff (Foo *self, const gchar *stuff, GError **error); is written in the "correct" way, ie: - if returns TRUE, error is never set - if returns FALSE, error is always set Languages like Vala and Python would see this function as a function that always returns TRUE, unless an exception occurred, in which case you would never see the return value. It's clear that it's more appropriate to bind that as a void return value. An even better example: gboolean foo_do_some_stuff (Foo *self, const gchar *stuff, gint *amount_of_stuff_done, /* out */ GError **error); In this case, it would be far better for the lone out parameter to be the return value than to have a tuple returned. Deciding when to apply this new feature will not be easy. There are all kinds of functions that would seemingly be a good fit for this, right off the bat, but it's all kinds of API-incompatibility, so we can't just turn it on. I suggest we add two new annotations: - (broken gerror): for functions where the return value does not indicate the setting of the GError output (like GKeyFile functions) - (version 2): for functions where we want to always have the new version of the way of handling these functions (because the function with this tag was added after this functionality was available so there is no API compatibility concern) Note: (version 2) (broken gerror), combined, would still do nothing special. ie: in this case, the existence of (broken gerror) causes (version 2) to mean nothing. We may have other things that we want to do for (version 2), though... Then, we could have an API on gobject-introspection itself: GLib.Introspection.set_version (2); that, if someone calls it from their program, all functions implicitly get treated as if they were tagged (version 2). This way you could opt-in to the new nicer binding, even for older functions. Instead of version '2' we may want to base it on GLib stable API version numbers, so that each minor cycle (2.38, 2.40, 2.42, ...) is a chance to introduce some new changes to how gobject-introspection works.
There's two phases: 1) Getting this data out to bindings 2) Having bindings optionally make use of it I'd also want to think about batching up other changes in a theoretical "version 2". One major problem with this is that libraries which are adapated to add the annotations *after* we've already released this will break IABI for programs which were using the old v1 for libfoo, but v2 for other things.
note that we already have the opposite of "(broken gerror)"; you can specify (skip) on a gboolean return value. but the ability-to-change-the-ABI stuff would be nice. It would also be nice if you could do something like g-ir-scanner --abi-version 2:2.38 ... to say that all functions "Since: 2.38" or later should automatically get the version 2 semantics.
A related issue is how to handle functions which only return NULL when a GError is set, now that (nullable) return values are supported. IMHO it would be better to *not* annotate them as nullable and luckily there are no backwards compatibility issues with this (unlike bools), but it would be nice to have an official policy in place.
*** Bug 650176 has been marked as a duplicate of this bug. ***
[Mass-moving gobject-introspection tickets to its own Bugzilla product - see bug 708029. Mass-filter your bugmail for this message: introspection20150207 ]
*** This bug has been marked as a duplicate of bug 669016 ***