Skip to content

Support autocleanups for exported types

Debarshi Ray requested to merge wip/rishi/autocleanups into master

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:

  • g_auto, g_autofree and g_autoptr with the librest types, or
  • 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.

This is a continuation of: https://bugzilla.gnome.org/show_bug.cgi?id=785811

Edited by Debarshi Ray

Merge request reports