mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-03-02 01:30:32 +01:00
glib-aux: merge branch 'th/g-clear-pointer'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1475
This commit is contained in:
commit
08262ce372
2 changed files with 32 additions and 20 deletions
|
|
@ -17891,7 +17891,7 @@ dispose(GObject *object)
|
|||
priv->sriov.next = NULL;
|
||||
}
|
||||
|
||||
g_clear_object(&priv->l3cfg);
|
||||
g_clear_object(&priv->l3cfg_);
|
||||
g_clear_object(&priv->l3ipdata_4.ip_config);
|
||||
g_clear_object(&priv->l3ipdata_6.ip_config);
|
||||
|
||||
|
|
|
|||
|
|
@ -45,28 +45,40 @@ __g_type_ensure(GType type)
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
#if !GLIB_CHECK_VERSION(2, 34, 0)
|
||||
/* glib 2.58+ defines an improved, type-safe variant of g_clear_pointer(). Reimplement
|
||||
* that.
|
||||
*
|
||||
* Note that we also have nm_clear_pointer() which is similar to g_clear_pointer()
|
||||
* and also preferred throughout. However, we do use g_clear_object(), which is
|
||||
* implemented via g_clear_pointer(). So while there are no immediate users of
|
||||
* g_clear_pointer() (use nm_clear_pointer() instead), there are indirect users
|
||||
* via g_clear_object().
|
||||
*
|
||||
* Anyway. So the glib 2.58+ version of g_clear_pointer() is only used if GLIB_VERSION_MAX_ALLOWED
|
||||
* is set, which we don't do.
|
||||
*
|
||||
* To get the type-safe variant, reimplement g_clear_pointer() below. This aims to
|
||||
* be identical to the version of the macro in glib 2.58.
|
||||
*
|
||||
* Still, don't use g_clear_pointer() directly (use nm_clear_pointer()). This compat
|
||||
* implementation exists only for g_clear_object().
|
||||
*/
|
||||
#undef g_clear_pointer
|
||||
|
||||
#define g_clear_pointer(pp, destroy) \
|
||||
G_STMT_START \
|
||||
{ \
|
||||
G_STATIC_ASSERT(sizeof *(pp) == sizeof(gpointer)); \
|
||||
/* Only one access, please */ \
|
||||
gpointer *_pp = (gpointer *) (pp); \
|
||||
gpointer _p; \
|
||||
/* This assignment is needed to avoid a gcc warning */ \
|
||||
GDestroyNotify _destroy = (GDestroyNotify) (destroy); \
|
||||
\
|
||||
_p = *_pp; \
|
||||
if (_p) { \
|
||||
*_pp = NULL; \
|
||||
_destroy(_p); \
|
||||
} \
|
||||
} \
|
||||
#define g_clear_pointer(pp, destroy) \
|
||||
G_STMT_START \
|
||||
{ \
|
||||
typeof((pp)) _pp = (pp); \
|
||||
typeof(*_pp) _ptr = *_pp; \
|
||||
\
|
||||
G_STATIC_ASSERT(sizeof *(pp) == sizeof(gpointer)); \
|
||||
\
|
||||
*_pp = NULL; \
|
||||
if (_ptr) \
|
||||
(destroy)(_ptr); \
|
||||
} \
|
||||
G_STMT_END
|
||||
|
||||
#endif
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#if !GLIB_CHECK_VERSION(2, 34, 0)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue