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 626721 - [annotation] (success) for functions with (out) args and bool return value
[annotation] (success) for functions with (out) args and bool return value
Status: RESOLVED DUPLICATE of bug 669016
Product: gobject-introspection
Classification: Platform
Component: general
2.25.x
Other Linux
: Normal enhancement
: ---
Assigned To: gobject-introspection Maintainer(s)
gobject-introspection Maintainer(s)
Depends on:
Blocks: 620912
 
 
Reported: 2010-08-12 09:57 UTC by Steve Frécinaux
Modified: 2018-01-25 14:03 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
IRC conversation log (3.52 KB, text/plain)
2013-10-09 21:47 UTC, Phil Clayton
Details

Description Steve Frécinaux 2010-08-12 09:57:45 UTC
Some functions have a gboolean return value and some out args, and the return value is TRUE on success, FALSE on failure. If the return value is FALSE, the out args values are usually undefined, and as such cannot be trusted by bindings: trying to cast an undefined out pointer into a GObject or something else might lead to issues or crashes.

Such a function is gdk_event_get_state().

As a solution, we would like to introduce a new (success) annotation for the return value of such functions. It would indicate that the binding should *not* use the (out) values when the return value is FALSE.

Binding-side (here, pygobject), we would have something like this:

state = some_event.get_state()
if out is not None:
  do_something_with_the_state(state)

instead of the current:

(success, state) = some_event.get_state()
if success:
  do_something_with_the_state(state)
Comment 1 Dan Winship 2010-08-12 13:14:37 UTC
very similar to bug 599698, though that proposal wouldn't include gdk_event_get_state()
Comment 2 Phil Clayton 2013-10-09 21:47:04 UTC
Created attachment 256855 [details]
IRC conversation log
Comment 3 Phil Clayton 2013-10-09 22:47:21 UTC
A while ago (well over a year) on #introspection, I discussed a different idea for indicating whether conditional out parameters are filled with a value for a successful outcome.  See attached log.

In this proposal, the (out) annotation is extended to indicate
 1. whether an out parameter is conditional
 2. the source of the condition

This would be achieved with additional arguments as follows:

  (out cond=PARAM)

    to indicate that the out parameter is 'successfully filled'
    when PARAM is non-zero, i.e. when PARAM not FALSE for a
    gboolean, not NULL for a pointer etc.

  (out cond-ret)

    to indicate that the out parameter is 'successfully filled'
    when the return value is non-zero.

Unlike the (success) annotation for return values proposed in comment #1, this approach does not require all out parameters to have the same conditional behaviour.  So, for example, the (success) annotation would not exactly capture the conditional behaviour of out parameters of
  gtk_tree_selection_get_selected
where
  model is filled irrespective of the return value
  iter  is filled iff the return value is non-zero
Comment 4 Phil Clayton 2013-10-09 22:53:24 UTC
Previous comment should have said comment #0 instead of comment #1.
Comment 5 Dan Winship 2013-10-10 13:12:12 UTC
In many cases, it would be better to just have more-bindable alternative versions of the functions.
Comment 6 André Klapper 2015-02-07 17:21:46 UTC
[Mass-moving gobject-introspection tickets to its own Bugzilla product - see bug 708029. Mass-filter your bugmail for this message: introspection20150207 ]
Comment 7 Emmanuele Bassi (:ebassi) 2018-01-25 14:03:57 UTC

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