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 708301 - Handle 'success' boolean returns more gracefully
Handle 'success' boolean returns more gracefully
Status: RESOLVED DUPLICATE of bug 669016
Product: gobject-introspection
Classification: Platform
Component: general
unspecified
Other All
: Normal enhancement
: ---
Assigned To: gobject-introspection Maintainer(s)
gobject-introspection Maintainer(s)
: 650176 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2013-09-18 14:38 UTC by Allison Karlitskaya (desrt)
Modified: 2018-01-25 14:03 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Allison Karlitskaya (desrt) 2013-09-18 14:38:04 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.
Comment 1 Colin Walters 2013-09-18 14:53:22 UTC
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.
Comment 2 Dan Winship 2013-09-18 15:06:54 UTC
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.
Comment 3 Evan Nemerson 2014-05-07 23:07:05 UTC
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.
Comment 4 Allison Karlitskaya (desrt) 2014-10-09 13:37:29 UTC
*** Bug 650176 has been marked as a duplicate of this bug. ***
Comment 5 André Klapper 2015-02-07 17:16:41 UTC
[Mass-moving gobject-introspection tickets to its own Bugzilla product - see bug 708029. Mass-filter your bugmail for this message: introspection20150207 ]
Comment 6 Emmanuele Bassi (:ebassi) 2018-01-25 14:03:38 UTC

*** This bug has been marked as a duplicate of bug 669016 ***