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 574284 - Add support for a 'closure' and 'destroy' annotations
Add support for a 'closure' and 'destroy' annotations
Status: RESOLVED FIXED
Product: gobject-introspection
Classification: Platform
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: gobject-introspection Maintainer(s)
gobject-introspection Maintainer(s)
Depends on:
Blocks:
 
 
Reported: 2009-03-05 16:42 UTC by Andreas Rottmann
Modified: 2015-02-07 16:53 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Add support for a 'closure' and 'destroy' annotations (9.12 KB, patch)
2009-03-05 16:43 UTC, Andreas Rottmann
accepted-commit_now Details | Review

Description Andreas Rottmann 2009-03-05 16:42:19 UTC
In some cases the heuristics don't work, creating a need for explicit
annotations.

I propose adding these annotations:

For function parameters:

(closure ARG-NAME): Indicates that this argument (which is assumed to
                    be of callback type) has ARG-NAME as closure
                    argument.
(destroy ARG-NAME): Ditto, for the destroy notficiation.

For callbacks types:

(closure): Indicates that this argument is the user_data/closure
           argument.
Comment 1 Andreas Rottmann 2009-03-05 16:43:12 UTC
Created attachment 130138 [details] [review]
Add support for a 'closure' and 'destroy' annotations

This allows to annotate cases where the heuristics don't work.

Signed-off-by: Andreas Rottmann <a.rottmann@gmx.at>
Comment 2 Colin Walters 2009-03-17 21:06:43 UTC
Maybe we could annotate a callback definition as (destroy), instead of individual uses?   I'm fine with the individual annotations though too.

What library is this for?

Note that at least my bindings assume that a destroy function has the same signature as GDestroyNotify (as does your example), we should probably hard require this.
Comment 3 Colin Walters 2009-03-17 21:10:05 UTC
Also:

* What do you think about calling it (user-data) instead of (closure)?  It feels a bit more precise to me, though (closure) is ok too.
* We really need docs for the growing number of annotations (not in the scope of this bug).  Maybe just a quick comment above the two you added would be good, or just link to this bug.

Anyways feel free to commit without change, but any fixes/responses to these review comments is good of course.
Comment 4 Andreas Rottmann 2009-03-18 20:33:39 UTC
(In reply to comment #2)
> Maybe we could annotate a callback definition as (destroy), instead of
> individual uses?   I'm fine with the individual annotations though too.
>
Sorry, I don't understand. Can you elaborate?

> What library is this for?
> 
gir/glib-2.0.c: (from a not-yet-filed patch):

/**
 * GSourceFunc:
 * @data: (closure):
 */

/**
 * GIOFunc:
 * @data: (closure):
 */

I thought I'd need the others for libsoup (which has fancy things going on with its SoupBuffer), but it turned out that you have to put manual hacks in your bindings to deal with that mess^W anyway, so currently, I don't actually use them.

> Note that at least my bindings assume that a destroy function has the same
> signature as GDestroyNotify (as does your example), we should probably hard
> require this.
> 
My bindings doesn't require this (due to libffi's magic and the C calling convention, which allows calling a "void (*func)()" with any number of args, IIRC), but this is an implementation detail, and not hard-requiring it will constrain a binding-implementors freedom, so I'd agree on that point. Do you suggest I add a corresponding check into the code?
Comment 5 Andreas Rottmann 2009-03-18 20:34:39 UTC
(In reply to comment #3)
> Also:
> 
> * What do you think about calling it (user-data) instead of (closure)?  It
> feels a bit more precise to me, though (closure) is ok too.
>
I don't really mind.
Comment 6 Colin Walters 2009-03-23 20:44:45 UTC
(In reply to comment #4)
> (In reply to comment #2)
> > Maybe we could annotate a callback definition as (destroy), instead of
> > individual uses?   I'm fine with the individual annotations though too.
> >
> Sorry, I don't understand. Can you elaborate?

What I meant is that we'd do:

/**
 * FooDestroyFunc:
 * Destroy: true
 */
void (*FooDestroyFunc)(gpointer obj);

Or something, and then the scanner would know that all uses of that type were a destroy notify, rather than annotating each call.

It's not a big deal though, really we want libraries to use GDestroyNotify and not custom functions.

Feel free to commit unchanged.
Comment 7 Andreas Rottmann 2009-03-23 23:30:06 UTC
Committed as cf7621f..
Comment 8 André Klapper 2015-02-07 16:53:24 UTC
[Mass-moving gobject-introspection tickets to its own Bugzilla product - see bug 708029. Mass-filter your bugmail for this message: introspection20150207 ]