GNOME Bugzilla – Bug 728504
[patch] Add introspection annotations for gom_resource_class_set_property_transform()
Last modified: 2014-04-26 05:57:01 UTC
Fixes warnings from GIR parser leading to the function being unavailable
Created attachment 274674 [details] [review] Add introspection annotations for gom_resource_class_set_property_transform() Add (scope call) annotations to fix warnings in GIR generation, which causes the above function to be unavailable with introspection.
Review of attachment 274674 [details] [review]: There's only 3 possible scopes, call, async and notify. And all of those seem wrong and I'm not sure how to do that otherwise. https://wiki.gnome.org/Projects/GObjectIntrospection/Annotations#GObject-Introspection_annotations
Yeah, I had a read through the docs and figured "call" was appropriate because there's no user_data attached to the callback -- and so nothing that needs to be kept alive. But perhaps I'm reading it wrong and there should be a closure there for binding purposes -- these functions seem conceptually similar to GBindingTransferFunc, which *does* have a user_data slot (and a GDestroyNotify that's set in g_object_bind_property_full).
Thinking about it some more, the correct way to do this is definitely to include a user_data parameter for binding purposes. So we'd have typedef GBytes * (*GomResourceToBytesFunc) (GValue *value, gpointer user_data); typedef void (*GomResourceFromBytesFunc) (GBytes *bytes, GValue *value, gpointer user_data); and then a set_property_transform_full() which would take two GDestroyNotifys, one for each callback. The implementation would call g_param_spec_set_qdata_full(), which includes setting the GDestroyNotify correctly. Well, that's the idea, but unfortunately it won't work, as the introspection machinery doesn't understand having two GDestroyNotify parameters in one function. To work around this, GBinding (which does something very similar with property transform functions) provides g_object_bind_property_with_closures() which takes two GClosures. An alternative approach (better, IMO) would be keep this function as-is for C convenience, and also provide two separate functions for setting to_bytes and from_bytes functions for introspection purposes, i.e. void gom_resource_class_set_property_to_bytes(GomResourceClass* klass, const char* prop, GomResourceToBytesFunc func, gpointer user_data, GDestroyNotify notify); and a corresponding set_property_from_bytes(). I can go ahead and do this if you want, let me know.
(In reply to comment #4) > > > An alternative approach (better, IMO) would be keep this function as-is for C > convenience, and also provide two separate functions for setting to_bytes and > from_bytes functions for introspection purposes, Yeah, that's what you have to do for now. It would be nice to support multiple callback functions, we just haven't encountered them often enough yet.
Created attachment 275136 [details] [review] gom: Fix introspection of gom_resource_class_set_property_transform() By skipping this function for introspection, and adding two new functions for the bindings to use.
Review of attachment 275136 [details] [review]: Looks good to me!
Attachment 275136 [details] pushed as aa9a38c - gom: Fix introspection of gom_resource_class_set_property_transform()