macros: add support for GNUC cleanup __attribute__

Add g_auto() and g_autoptr() as helpers for declaring variables with
automatic cleanup.

Add some macros to help types define cleanup functions for themselves.

Going forward it will be an expectation that people use this macro when
creating a new type, even if they do not intend to use the auto-cleanup
functionality for themselves.

These new macros only work on GCC and clang, which is why we resisted
adding them for so long.  There exist many people who are only
interested in writing programs for these compilers, however, and a
similar API in libgsystem has proven to be extremely popular, so let's
expose this functionality to an even wider audience.

We ignore deprecation warnings when emitting the free functions, which
seems suspicious.  The reason that we do this is not because we want to
call deprecated functions, but just the opposite: sometimes the free
function will be an _unref() function that is only AVAILABLE_IN newer
versions, and these warnings are also implemented as deprecation
warnings.

https://bugzilla.gnome.org/show_bug.cgi?id=743640
This commit is contained in:
Ryan Lortie
2015-01-28 11:27:35 +00:00
parent b5e1ea6fee
commit 2596919c58
3 changed files with 231 additions and 0 deletions

View File

@@ -362,6 +362,13 @@ G_LOG_2_BASE_10
<FILE>macros_misc</FILE>
G_INLINE_FUNC
<SUBSECTION>
g_auto
g_autoptr
G_DEFINE_AUTOPTR_CLEANUP_FUNC
G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC
G_DEFINE_AUTO_CLEANUP_FREE_FUNC
<SUBSECTION>
G_STMT_START
G_STMT_END