GNOME Bugzilla – Bug 678229
Introspection fixes for Vala bindings
Last modified: 2019-02-22 11:45:53 UTC
Created attachment 216592 [details] [review] introspection: some minor fixes to avoid Vala regressions Add the C include file name, change the "data" argument to "user_data" in GnomeKeyringOperation*Callback, and make GnomeKeyringOperationGetStringCallback's string argument nullable. Once this is pushed I can either push the bindings to Vala or submit a patch to distribute them with libgnome-keyring... which would you prefer?
It's worth noting that the async libgnome-keyring API isn't introspected currently. It's not easily useable from most languages other than C. Can vala reliably use the async stuff?
Yes. We have to un-skip all the functions in metadata so the API gets exposed, but something like this works: private static int main (string[] args) { GLib.MainLoop loop = new GLib.MainLoop (); void* req = GnomeKeyring.get_default_keyring ((r, k) => { GLib.debug ("default keyring: %s (#%d: %s)", k, r, GnomeKeyring.Result.to_message (r)); loop.quit (); }); // Cancelling works to, just uncomment // GnomeKeyring.cancel_request (req); loop.run (); return 0; } AFAIK the only reason other languages can't work is that they don't handle the void* return value. It should be possible to get them to work by exposing GkrOperation as a boxed type and having all the async methods return that instead of void* (by using the type annotation--no need to change the C API). It would actually be possible to make this type-safe in Vala without any changes to libgnome-keyring by creating (in the Vala bindings) a SimpleType struct with a cname of "void*", then have all the async methods return that and make cancel_request a method of that type... basically faking what I mentioned about GkrOperation without having to change libgnome-keyring. The problem is that doing so would break backwards-compatibility with the existing bindings, so I've just left them as returning void*. After doing something about the void* return value the only problematic part for other langauges would be the functions that take a GnomeKeyringOperationGetListCallback. The updated Vala bindings use a generic delegate, so it looks something like this (which works quite well and is type-safe, unless you count the void* return value): public delegate void OperationGetListCallback<T> (GnomeKeyring.Result result, GLib.List<T> list); public static void* find_items (GnomeKeyring.ItemType type, GnomeKeyring.AttributeList attributes, owned GnomeKeyring.OperationGetListCallback<GnomeKeyring.Found> callback); For other languages to work you would need to create a typedef for each different type (i.e., GnomeKeyringOperationGetStringListCallback for a list of strings, GnomeKeyringOperationGetFoundListCallback for a list of GnomeKeyringFound, etc.), then use the type annotation to have introspection use those instead of GnomeKeyringOperationGetListCallback.
Comment on attachment 216592 [details] [review] introspection: some minor fixes to avoid Vala regressions Okay thanks. This patch looks good to me.