diff options
author | Thomas Haller <thaller@redhat.com> | 2019-06-25 17:19:01 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2019-06-26 09:53:54 +0200 |
commit | b9587008fcebb5255119a457f708c7f7d1232fa1 (patch) | |
tree | fc3035a9c5a953426626321071adf0fc4f0dc7dd /shared/nm-glib-aux | |
parent | 03b8eb124e00f163d0c4baa8285f088727ef08e2 (diff) | |
download | NetworkManager-b9587008fcebb5255119a457f708c7f7d1232fa1.tar.gz |
shared: add nm_clear_error() and patch g_clear_error() to use this inlinable variant
Diffstat (limited to 'shared/nm-glib-aux')
-rw-r--r-- | shared/nm-glib-aux/nm-macros-internal.h | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/shared/nm-glib-aux/nm-macros-internal.h b/shared/nm-glib-aux/nm-macros-internal.h index 5b594a2ab5..d2210db006 100644 --- a/shared/nm-glib-aux/nm-macros-internal.h +++ b/shared/nm-glib-aux/nm-macros-internal.h @@ -1160,6 +1160,30 @@ nm_g_object_unref (gpointer obj) #define nm_clear_g_object(pp) \ nm_clear_pointer (pp, g_object_unref) +/** + * nm_clear_error: + * @err: a pointer to pointer to a #GError. + * + * This is like g_clear_error(). The only difference is + * that this is an inline function. + */ +static inline void +nm_clear_error (GError **err) +{ + if (err && *err) { + g_error_free (*err); + *err = NULL; + } +} + +/* Patch g_clear_error() to use nm_clear_error(), which is inlineable + * and visible to the compiler. For example gs_free_error attribute only + * frees the error after checking that it's not %NULL. So, in many cases + * the compiler knows that gs_free_error has no effect and can optimize + * the call away. By making g_clear_error() inlineable, we give the compiler + * more chance to detect that the function actually has no effect. */ +#define g_clear_error(ptr) nm_clear_error(ptr) + static inline gboolean nm_clear_g_source (guint *id) { |