Glib-style auto pointer
glib-style auto pointer
The __autoptr() provides a general way of “cleaning up” when going out of scope. Inspired by glib, but simplified a lot (at the expence of flexibility).
-
DEFINE_AUTOPTR
DEFINE_AUTOPTR (t, cleanup)
Defines the appropriate cleanup function for a pointer type
Parameters
t
type name
cleanup
function to be called to cleanup type
Description
Defines a function __autoptr_cleanup_##t
that will call cleanup when
invoked.
-
__autoptr
__autoptr (t)
Helper to declare a pointer variable with automatic cleanup
Parameters
t
type name
Description
Declares a pointer that is cleaned up when the variable goes out of scope. How to clean up the type must have been previously declared using DEFINE_AUTOPTR().