Add support for g_auto[s]list(Type)

This lets you do g_autoptr style cleanup of GList that does deep freeing.

https://bugzilla.gnome.org/show_bug.cgi?id=791342
This commit is contained in:
Alexander Larsson
2017-12-19 11:17:09 +01:00
parent bf0be21208
commit f49a93b207
4 changed files with 135 additions and 0 deletions

View File

@@ -2607,6 +2607,62 @@
* Since: 2.44
*/
/**
* g_autolist:
* @TypeName: a supported variable type
*
* Helper to declare a list variable with automatic deep cleanup.
*
* The list is deeply freed, in a way appropriate to the specified type, when the
* variable goes out of scope. The type must support this.
*
* This feature is only supported on GCC and clang. This macro is not
* defined on other compilers and should not be used in programs that
* are intended to be portable to those compilers.
*
* This is meant to be used to declare lists of a type with a cleanup
* function. The type of the variable is a GList *. You
* must not add your own '*'.
*
* This macro can be used to avoid having to do explicit cleanups of
* local variables when exiting functions. It often vastly simplifies
* handling of error conditions, removing the need for various tricks
* such as 'goto out' or repeating of cleanup code. It is also helpful
* for non-error cases.
*
* See also g_autoslist(), g_autoptr() and g_steal_pointer().
*
* Since: 2.56
*/
/**
* g_autoslist:
* @TypeName: a supported variable type
*
* Helper to declare a singly linked list variable with automatic deep cleanup.
*
* The list is deeply freed, in a way appropriate to the specified type, when the
* variable goes out of scope. The type must support this.
*
* This feature is only supported on GCC and clang. This macro is not
* defined on other compilers and should not be used in programs that
* are intended to be portable to those compilers.
*
* This is meant to be used to declare lists of a type with a cleanup
* function. The type of the variable is a GSList *. You
* must not add your own '*'.
*
* This macro can be used to avoid having to do explicit cleanups of
* local variables when exiting functions. It often vastly simplifies
* handling of error conditions, removing the need for various tricks
* such as 'goto out' or repeating of cleanup code. It is also helpful
* for non-error cases.
*
* See also g_autolist(), g_autoptr() and g_steal_pointer().
*
* Since: 2.56
*/
/**
* G_DEFINE_AUTOPTR_CLEANUP_FUNC:
* @TypeName: a type name to define a g_autoptr() cleanup function for