GNOME Bugzilla – Bug 729543
[girepository] Add support for "throws" flag to callbacks
Last modified: 2015-07-11 23:10:29 UTC
The callback field for vfuncs correctly uses the "throws" attribute in gir, but this does not seem to translate through to the typelib/repository API: For instance, looking at Gio-2.0.gir we see the following vfunc setup: <interface name="Initable" ... <method name="init" c:identifier="g_initable_init" version="2.22" throws="1"> <virtual-method name="init" invoker="init" version="2.22" throws="1"> </interface> <record name="InitableIface" <field name="init"> <callback name="init" throws="1"> ... </record> All three of the invoker, vfunc, and callback field infos correctly contain throws="1". But interacting with the typelib from Python, can_throw_gerror returns False for the CallbackInfo. # Invoker: >>> from gi.repository import Gio >>> invoker = Gio.Initable.init >>> invoker.can_throw_gerror() True # VFunc: >>> vfunc = invoker.get_vfunc() >>> vfunc.can_throw_gerror() True # Callback Field: >>> iface = Gio.InitableIface.__info__ >>> iface StructInfo(InitableIface) >>> field = iface.get_fields()[1] >>> field gi.FieldInfo(init) >>> callback = field.get_type().get_interface() >>> callback gi.CallbackInfo(init) >>> callback.get_arguments() # Note the GError is correctly not included as an arg (gi.ArgInfo(initable), gi.ArgInfo(cancellable)) >>> callback.can_throw_gerror() False We can see in the implementation of g_callable_info_can_throw_gerror [1], callbacks and signals always return false for this. The information is either not included in the typelib or the implementation needs to be updated to look for this. [1] https://git.gnome.org/browse/gobject-introspection/tree/girepository/gicallableinfo.c?id=GOBJECT_INTROSPECTION_1_40_0#n94
Created attachment 275859 [details] [review] girepository: Add g_struct_info_find_field function Add find_field utility function for finding a field info by name. Beyond convenience, this should be faster than manually using the get_n_fields and get_field calls because get_field has an additional iteration for each field to calculate offsets O(n^2). find_field combines the offset and comparison computations into a single loop O(n).
Created attachment 275860 [details] [review] tests: Convert gitestthrows to use GTest framework
Created attachment 275861 [details] [review] tests: Add failing test for g_callable_info_can_throw_gerror
Created attachment 275862 [details] [review] girepository: Support GError exceptions on callbacks Generalize "throws" attribute to SignatureBlob which can be used by all callable blob types. Keep FunctionBlob and VFuncBlob throw attributes around and functional for compatibility. Refactor girwriter.c to write out throws attribute for all callable types.
[Mass-moving gobject-introspection tickets to its own Bugzilla product - see bug 708029. Mass-filter your bugmail for this message: introspection20150207 ]
Created attachment 304517 [details] [review] girepository: Add g_struct_info_find_field() v2 Add find_field utility function for finding a field info by name. Beyond convenience, this should be faster than manually using the get_n_fields and get_field functions because get_field does an additional iteration for each field to calculate offsets O(n^2). Thus find_field combines the offset and comparison computations into a single loop O(n).
Created attachment 304518 [details] [review] girepository: Support GError exceptions on callbacks v2 Generalize "throws" attribute to SignatureBlob which can be used by all callable blob types. Keep FunctionBlob and VFuncBlob throw attributes around and functional for compatibility. Refactor girwriter.c to write out throws attribute for all callable types.
Review of attachment 304517 [details] [review]: It looks good to me. Maybe we should also get a find_method(), since get_method() calls get_field() as well. ::: girepository/gistructinfo.c @@ +125,3 @@ + * + * Returns: (transfer full): the #GIFieldInfo or %NULL if not found, + * free it with g_base_info_unref() when done. Should probably add a Since: ::: girepository/gistructinfo.h @@ +49,3 @@ gint n); GI_AVAILABLE_IN_ALL Do we have versioned macros yet? If we don't, then it doesn't matter.
Review of attachment 304518 [details] [review]: Looks generally good to me.
Created attachment 304523 [details] [review] girepository: Add g_struct_info_find_field() v3 (In reply to Emmanuele Bassi (:ebassi) from comment #8) > Review of attachment 304517 [details] [review] [review]: > > It looks good to me. > > Maybe we should also get a find_method(), since get_method() calls > get_field() as well. > g_struct_info_find_method() already exists. > ::: girepository/gistructinfo.c > @@ +125,3 @@ > + * > + * Returns: (transfer full): the #GIFieldInfo or %NULL if not found, > + * free it with g_base_info_unref() when done. > > Should probably add a Since: > Done. > ::: girepository/gistructinfo.h > @@ +49,3 @@ > gint n); > > GI_AVAILABLE_IN_ALL > > Do we have versioned macros yet? If we don't, then it doesn't matter. Fixed.
Review of attachment 304523 [details] [review]: Looks good.
This problem has been fixed in the unstable development version. The fix will be available in the next major software release. You may need to upgrade your Linux distribution to obtain that newer version.
Garret, Emmanuele, Thanks for updating the patches and getting them committed. Although I would have preferred if you kept myself as the primary commit author since I did the majority of work (it looks like only minimal formatting and build system stuff was changed). Then add yourself using a "Co-Authored-By:" label (or vise versa depending on where the majority of the code came from). Or is this not how it should work? In any event, I'm glad this stuff is finally committed.