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 604658 - [annotation] Meta annotations for types
[annotation] Meta annotations for types
Status: RESOLVED WONTFIX
Product: gobject-introspection
Classification: Platform
Component: g-ir-scanner
unspecified
Other All
: Normal enhancement
: ---
Assigned To: gobject-introspection Maintainer(s)
gobject-introspection Maintainer(s)
Depends on:
Blocks:
 
 
Reported: 2009-12-15 22:43 UTC by Colin Walters
Modified: 2018-01-25 14:54 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Assume allow-none for GCancellable (10.03 KB, patch)
2009-12-15 22:43 UTC, Colin Walters
committed Details | Review

Description Colin Walters 2009-12-15 22:43:33 UTC
All GCancellables are allow-none, this allows us to remove a lot
of custom annotations.
Comment 1 Colin Walters 2009-12-15 22:43:34 UTC
Created attachment 149806 [details] [review]
Assume allow-none for GCancellable
Comment 2 Johan (not receiving bugmail) Dahlin 2009-12-15 23:18:08 UTC
Review of attachment 149806 [details] [review]:

::: giscanner/annotationparser.py
@@ +559,3 @@
+            node.allow_none = True
+            node.type.ctype == 'GCancellable*'):
+        if (OPT_ALLOW_NONE in options or

What about introducing something like meta-annotations, where we can add an annotation
for the GCancellable-struct saying that the default value is to allow none.

And if we're defaulting to allow-none, is there a way to revert that? I might have a reason to write a library where a GCancellable is required, either consciously or not.
Comment 3 Colin Walters 2009-12-17 17:20:56 UTC
(In reply to comment #2)
> Review of attachment 149806 [details] [review]:
> 
> ::: giscanner/annotationparser.py
> @@ +559,3 @@
> +            node.allow_none = True
> +            node.type.ctype == 'GCancellable*'):
> +        if (OPT_ALLOW_NONE in options or
> 
> What about introducing something like meta-annotations, where we can add an
> annotation
> for the GCancellable-struct saying that the default value is to allow none.

If meta-annotations were just "apply this annotation at every argument using this type" it seems relatively straightforward, but I think what we really want is plugins for the scanner, so you can say g-ir-scanner --plugin=myplugin.py

Or you could just post-process the .gir which is fairly easy.

> And if we're defaulting to allow-none, is there a way to revert that? I might
> have a reason to write a library where a GCancellable is required, either
> consciously or not.

Hmm...I can't think of a scenario in which it would make sense to require a cancellable deliberately; and accidentally seems like it'd always be a bug.  In other words it really does seem like it's part of the API contract for GCancellable, like the rules around GError.
Comment 4 Colin Walters 2009-12-17 17:21:59 UTC
(In reply to comment #3)
> (In reply to comment #2)
> > Review of attachment 149806 [details] [review] [details]:
> > 
> > ::: giscanner/annotationparser.py
> > @@ +559,3 @@
> > +            node.allow_none = True
> > +            node.type.ctype == 'GCancellable*'):
> > +        if (OPT_ALLOW_NONE in options or
> > 
> > What about introducing something like meta-annotations, where we can add an
> > annotation
> > for the GCancellable-struct saying that the default value is to allow none.
> 
> If meta-annotations were just "apply this annotation at every argument using
> this type" it seems relatively straightforward

With regards to this - can you think of any other annotations of this form?
Comment 5 Dan Winship 2009-12-17 18:29:47 UTC
(In reply to comment #3)
> Hmm...I can't think of a scenario in which it would make sense to require a
> cancellable deliberately

g_cancellable_push_current() for instance, and a few other GCancellable methods, though some of those might be bugs.

> In other words it really does seem like it's part of the API contract for
> GCancellable, like the rules around GError.

which has the same issues with, eg, g_propagate_error() taking a GError** which does not mean "throws an error". But it's much less likely that you'd work directly with GError methods from a binding, so probably not worth fixing there.

The answer might be "ignore the special automatic-annotation rule in the type's own methods"?

(In reply to comment #4)
> With regards to this - can you think of any other annotations of this form?

the GAsyncReadyCallback ones we just did. There might be other always-allow-none types...
Comment 6 Dan Winship 2009-12-18 10:18:34 UTC
bug 601425 changed all GtkIconSize params to (type int), and Johan mentioned that GtkResponse has the same problem. This could be another case for meta-annotations; being able to specify that a particular type should always be converted to another type in function calls.
Comment 7 Colin Walters 2010-02-12 20:55:26 UTC
Comment on attachment 149806 [details] [review]
Assume allow-none for GCancellable

I accidentally committed this while looking at patches...going to keep it in since meta-annotations would be hard and it's better to have something here.
Comment 8 André Klapper 2015-02-07 17:16:03 UTC
[Mass-moving gobject-introspection tickets to its own Bugzilla product - see bug 708029. Mass-filter your bugmail for this message: introspection20150207 ]
Comment 9 Emmanuele Bassi (:ebassi) 2018-01-25 14:54:09 UTC
Hasn't happened in 9 years, it's unlikely it'll happen now.

I'm fairly comfortable with the idea of adding heuristics based on GLib/GObject/GIO types inside gobject-introspection. If other projects wish to add additional heuristics, we can revisit the idea of having annotations for default behaviours.