GNOME Bugzilla – Bug 785811
Support autocleanups for exported types
Last modified: 2021-06-02 15:04:58 UTC
GLib 2.44.0 added some features to: (a) Make it easier to use __attribute__((cleanup)) on compilers that support it (ie. gcc and clang). A type has to define its cleanup function using G_DEFINE_AUTOPTR_CLEANUP_FUNC(), G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC() or G_DEFINE_AUTO_CLEANUP_FREE_FUNC(). Note that defining the cleanup function doesn't add any dependency on __attribute__((cleanup)). (b) Reduce the amount of GObject boilerplate using the G_DECLARE_FINAL_TYPE(), G_DECLARE_DERIVABLE_TYPE() or G_DECLARE_INTERFACE() macros. These declaration macros also define the cleanup function for the GObject (ie. g_object_unref) using G_DEFINE_AUTOPTR_CLEANUP_FUNC(). However, that only works if the parent type also defined a cleanup function. Therefore, users of librest that want to use either: (a) g_auto, g_autofree and g_autoptr with the librest types, or (b) G_DECLARE_* to declare sub-classes of the librest types ... require the cleanup functions to be specified. The easiest option is to use G_DECLARE_* as much as possible in librest itself.
Created attachment 356947 [details] [review] rest-proxy: Use G_DECLARE_DERIVABLE_TYPE
Created attachment 356948 [details] [review] rest-proxy-call: Use G_DECLARE_DERIVABLE_TYPE
Created attachment 356949 [details] [review] rest-xml-parser: Use G_DECLARE_DERIVABLE_TYPE
Created attachment 356950 [details] [review] oauth-proxy-call: Use G_DECLARE_DERIVABLE_TYPE
Created attachment 356951 [details] [review] oauth2-proxy-call: Use G_DECLARE_DERIVABLE_TYPE
Created attachment 356952 [details] [review] lastfm-proxy-call: Use G_DECLARE_DERIVABLE_TYPE
Hi Debarshi, good clean-up. lgtm, please merge. Thanks.
Thanks for the review, Rob. Pushed them to master.
Some classes like RestProxyAuth and OAuth2Proxy can't be ported to G_DECLARE_DERIVABLE_TYPE without breaking ABI. Is that allowed in master? If not then we'll have to manually add the autocleanups. Even if we can break ABI, it might be nice to first add the autocleanups and then use G_DECLARE_* so that the patches can be easily cherry-picked to librest-0-7, if needed. What do you think?
GNOME is going to shut down bugzilla.gnome.org in favor of gitlab.gnome.org. As part of that, we are mass-closing older open tickets in bugzilla.gnome.org which have not seen updates for a longer time (resources are unfortunately quite limited so not every ticket can get handled). If you can still reproduce the situation described in this ticket in a recent and supported software version, then please follow https://wiki.gnome.org/GettingInTouch/BugReportingGuidelines and create a new enhancement request ticket at https://gitlab.gnome.org/GNOME/librest/-/issues/ Thank you for your understanding and your help.
Continued at: https://gitlab.gnome.org/GNOME/librest/-/merge_requests/5