From 904e8b8ca007ab1874dfcedc8ca09bcca410ef7b Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 13 Jul 2018 16:42:52 +0200 Subject: [PATCH] shared/gsystem-local-alloc: rename unused gs_* cleanup macros These cleanup macros are unused by NetworkManager code. Note that since "shared/nm-utils" is used by applet and VPN plugins, theoretically, they could be used there. I didn't check that, but breaking API of "shared/nm-utils" is fine (as long as we catch it with a compilation error). Historically, we use libgsystem's gsystem-local-alloc header and their "gs_*" macros. However, they are not really our style and don't have a nm-prefix (like the rest of our code). We keep the gs_ names, because they are wildly used and because we wanted to keep gsystem-local-alloc in sync with upstream (which is no longer the case). Our own cleanup macros are always called "nm_auto_*". So, at least for the unused "gs_*" macros, rename them to "nm_auto_*". Don't drop them, despite they being unused. The reason is, that we should make use of cleanup functions more eagerly. Dropping them now -- because they are momentarily unused -- hampers using them in the future. We often don't use the cleanup macros at places where I think we should, so by dropping them, we hamper future use. --- shared/nm-utils/gsystem-local-alloc.h | 37 --------------------------- shared/nm-utils/nm-macros-internal.h | 12 +++++++++ 2 files changed, 12 insertions(+), 37 deletions(-) diff --git a/shared/nm-utils/gsystem-local-alloc.h b/shared/nm-utils/gsystem-local-alloc.h index 9e2174b1d7..81cbb3c3a1 100644 --- a/shared/nm-utils/gsystem-local-alloc.h +++ b/shared/nm-utils/gsystem-local-alloc.h @@ -87,24 +87,6 @@ GS_DEFINE_CLEANUP_FUNCTION_VOID0 (GObject *, gs_local_obj_unref, g_object_unref) #define gs_unref_variant __attribute__ ((cleanup(gs_local_variant_unref))) GS_DEFINE_CLEANUP_FUNCTION0 (GVariant *, gs_local_variant_unref, g_variant_unref) -/** - * gs_free_variant_iter: - * - * Call g_variant_iter_free() on a variable location when it goes out of - * scope. - */ -#define gs_free_variant_iter __attribute__ ((cleanup(gs_local_variant_iter_free))) -GS_DEFINE_CLEANUP_FUNCTION0 (GVariantIter *, gs_local_variant_iter_free, g_variant_iter_free) - -/** - * gs_free_variant_builder: - * - * Call g_variant_builder_unref() on a variable location when it goes out of - * scope. - */ -#define gs_unref_variant_builder __attribute__ ((cleanup(gs_local_variant_builder_unref))) -GS_DEFINE_CLEANUP_FUNCTION0 (GVariantBuilder *, gs_local_variant_builder_unref, g_variant_builder_unref) - /** * gs_unref_array: * @@ -137,15 +119,6 @@ GS_DEFINE_CLEANUP_FUNCTION0 (GPtrArray *, gs_local_ptrarray_unref, g_ptr_array_u #define gs_unref_hashtable __attribute__ ((cleanup(gs_local_hashtable_unref))) GS_DEFINE_CLEANUP_FUNCTION0 (GHashTable *, gs_local_hashtable_unref, g_hash_table_unref) -/** - * gs_free_list: - * - * Call g_list_free() on a variable location when it goes out - * of scope. - */ -#define gs_free_list __attribute__ ((cleanup(gs_local_free_list))) -GS_DEFINE_CLEANUP_FUNCTION (GList *, gs_local_free_list, g_list_free) - /** * gs_free_slist: * @@ -155,16 +128,6 @@ GS_DEFINE_CLEANUP_FUNCTION (GList *, gs_local_free_list, g_list_free) #define gs_free_slist __attribute__ ((cleanup(gs_local_free_slist))) GS_DEFINE_CLEANUP_FUNCTION (GSList *, gs_local_free_slist, g_slist_free) -/** - * gs_free_checksum: - * - * Call g_checksum_free() on a variable location when it goes out - * of scope. Note that unlike g_checksum_free(), the variable may - * be %NULL. - */ -#define gs_free_checksum __attribute__ ((cleanup(gs_local_checksum_free))) -GS_DEFINE_CLEANUP_FUNCTION0 (GChecksum *, gs_local_checksum_free, g_checksum_free) - /** * gs_unref_bytes: * diff --git a/shared/nm-utils/nm-macros-internal.h b/shared/nm-utils/nm-macros-internal.h index 259b650181..a9ea7487d3 100644 --- a/shared/nm-utils/nm-macros-internal.h +++ b/shared/nm-utils/nm-macros-internal.h @@ -84,6 +84,18 @@ static inline int nm_close (int fd); GS_DEFINE_CLEANUP_FUNCTION_VOID (void *, _nm_auto_free_impl, free) #define nm_auto_free nm_auto(_nm_auto_free_impl) +GS_DEFINE_CLEANUP_FUNCTION0 (GVariantIter *, _nm_auto_free_variant_iter, g_variant_iter_free) +#define nm_auto_free_variant_iter __attribute__ ((cleanup(_nm_auto_free_variant_iter))) + +GS_DEFINE_CLEANUP_FUNCTION0 (GVariantBuilder *, _nm_auto_unref_variant_builder, g_variant_builder_unref) +#define nm_auto_unref_variant_builder __attribute__ ((cleanup(_nm_auto_unref_variant_builder))) + +GS_DEFINE_CLEANUP_FUNCTION (GList *, _nm_auto_free_list, g_list_free) +#define nm_auto_free_list __attribute__ ((cleanup(_nm_auto_free_list))) + +GS_DEFINE_CLEANUP_FUNCTION0 (GChecksum *, _nm_auto_checksum_free, g_checksum_free) +#define nm_auto_free_checksum __attribute__ ((cleanup(_nm_auto_checksum_free))) + static inline void nm_free_secret (char *secret) {