mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager
synced 2024-10-07 08:40:59 +00:00
shared: add nm_steal_pointer()/nm_clear_free() to "nm-std-aux.h"
There is the team of nm_auto*, nm_clear_pointer() and nm_steal_pointer(). These goes nicely together so that an autovariable owns a resource, to free it (clear) and to transfer ownership (steal). We have these also in glib, but we certainly also need it if we don't have glib because that very much goes together with nm_auto*. Add it.
This commit is contained in:
parent
1d6e208c12
commit
6feab75447
|
@ -520,4 +520,22 @@ NM_AUTO_DEFINE_FCN_VOID0 (void *, _nm_auto_free_impl, free)
|
|||
_changed; \
|
||||
})
|
||||
|
||||
#define nm_clear_free(pp) nm_clear_pointer (pp, free)
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static inline void *
|
||||
_nm_steal_pointer (void *pp)
|
||||
{
|
||||
void **ptr = (void **) pp;
|
||||
void *ref;
|
||||
|
||||
ref = *ptr;
|
||||
*ptr = NULL;
|
||||
return ref;
|
||||
}
|
||||
|
||||
#define nm_steal_pointer(pp) \
|
||||
((typeof (*(pp))) _nm_steal_pointer (pp))
|
||||
|
||||
#endif /* __NM_STD_AUX_H__ */
|
||||
|
|
Loading…
Reference in a new issue