From c275d24637ce5c35c312fbff76b9adac4cbb099f Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 19 May 2023 10:53:13 +0200 Subject: [PATCH] clang-format: reformat code with clang-format 16.0.2-1.fc38 This is the version shipped in Fedora 38. As Fedora 38 is now out, the core developers switch to it. Our gitlab-ci will also use that as base image for the check-{patch.tree} tests and to generate the pages. There is a need that everybody agrees on which clang-format version to use, and that version should be the one of the currently used Fedora release. Also update the used Fedora image in "contrib/scripts/nm-code-format-container.sh" script. The gitlab-ci still needs update in the following commit. This change in isolation will break the "check-tree" test. --- contrib/scripts/nm-code-format-container.sh | 2 +- src/core/devices/nm-device-factory.h | 3 +- src/core/devices/nm-device-logging.h | 8 +- src/core/nm-core-utils.h | 23 ++-- src/libnm-glib-aux/nm-glib.h | 2 +- src/libnm-glib-aux/nm-hash-utils.h | 8 +- src/libnm-glib-aux/nm-macros-internal.h | 145 ++++++++++---------- src/libnm-glib-aux/nm-shared-utils.h | 2 +- src/libnm-glib-aux/nm-test-utils.h | 3 +- src/libnm-platform/nm-netlink.h | 20 +-- src/libnm-std-aux/nm-std-aux.h | 6 +- 11 files changed, 107 insertions(+), 115 deletions(-) diff --git a/contrib/scripts/nm-code-format-container.sh b/contrib/scripts/nm-code-format-container.sh index 9d9643832..d447e203b 100755 --- a/contrib/scripts/nm-code-format-container.sh +++ b/contrib/scripts/nm-code-format-container.sh @@ -10,7 +10,7 @@ die() { DIR="$(realpath "$(dirname "$0")/../../")" cd "$DIR" -FEDORA_VERSION=37 +FEDORA_VERSION=38 PODNAME="nm-code-format-f$FEDORA_VERSION" diff --git a/src/core/devices/nm-device-factory.h b/src/core/devices/nm-device-factory.h index ac5ae05f5..fc3d9dd43 100644 --- a/src/core/devices/nm-device-factory.h +++ b/src/core/devices/nm-device-factory.h @@ -208,8 +208,7 @@ NMDevice *nm_device_factory_create_device(NMDeviceFactory *factory, \ NM_DEVICE_FACTORY_DECLARE_TYPES(st_code) \ \ - static void nm_##lower##_device_factory_init(NM##mixed##DeviceFactory *self) \ - {} \ + static void nm_##lower##_device_factory_init(NM##mixed##DeviceFactory *self) {} \ \ static void nm_##lower##_device_factory_class_init(NM##mixed##DeviceFactoryClass *klass) \ { \ diff --git a/src/core/devices/nm-device-logging.h b/src/core/devices/nm-device-logging.h index ffc90c2d7..0ea332d8f 100644 --- a/src/core/devices/nm-device-logging.h +++ b/src/core/devices/nm-device-logging.h @@ -11,12 +11,10 @@ #if !_NM_CC_SUPPORT_GENERIC #define _NM_DEVICE_CAST(self) ((NMDevice *) (self)) #elif !defined(_NMLOG_DEVICE_TYPE) -#define _NM_DEVICE_CAST(self) _Generic((self), NMDevice * : ((NMDevice *) (self))) +#define _NM_DEVICE_CAST(self) _Generic((self), NMDevice *: ((NMDevice *) (self))) #else -#define _NM_DEVICE_CAST(self) \ - _Generic((self), _NMLOG_DEVICE_TYPE * \ - : ((NMDevice *) (self)), NMDevice * \ - : ((NMDevice *) (self))) +#define _NM_DEVICE_CAST(self) \ + _Generic((self), _NMLOG_DEVICE_TYPE *: ((NMDevice *) (self)), NMDevice *: ((NMDevice *) (self))) #endif #undef _NMLOG_ENABLED diff --git a/src/core/nm-core-utils.h b/src/core/nm-core-utils.h index bc9364963..87d3559e1 100644 --- a/src/core/nm-core-utils.h +++ b/src/core/nm-core-utils.h @@ -262,18 +262,17 @@ _nmtst_auto_utils_host_id_context_pop(const char *const *unused) nmtst_utils_host_id_pop(); } -#define _NMTST_UTILS_HOST_ID_CONTEXT(uniq, host_id) \ - _nm_unused nm_auto(_nmtst_auto_utils_host_id_context_pop) const char *const NM_UNIQ_T( \ - _host_id_context_, \ - uniq) = ({ \ - const gint64 _timestamp_ns = 1631000672; \ - \ - nmtst_utils_host_id_push((const guint8 *) "" host_id "", \ - NM_STRLEN(host_id), \ - TRUE, \ - &_timestamp_ns); \ - "" host_id ""; \ - }) +#define _NMTST_UTILS_HOST_ID_CONTEXT(uniq, host_id) \ + _nm_unused nm_auto(_nmtst_auto_utils_host_id_context_pop) \ + const char *const NM_UNIQ_T(_host_id_context_, uniq) = ({ \ + const gint64 _timestamp_ns = 1631000672; \ + \ + nmtst_utils_host_id_push((const guint8 *) "" host_id "", \ + NM_STRLEN(host_id), \ + TRUE, \ + &_timestamp_ns); \ + "" host_id ""; \ + }) #define NMTST_UTILS_HOST_ID_CONTEXT(host_id) _NMTST_UTILS_HOST_ID_CONTEXT(NM_UNIQ, host_id) diff --git a/src/libnm-glib-aux/nm-glib.h b/src/libnm-glib-aux/nm-glib.h index 0436d1355..9c90d4299 100644 --- a/src/libnm-glib-aux/nm-glib.h +++ b/src/libnm-glib-aux/nm-glib.h @@ -500,7 +500,7 @@ _nm_g_variant_new_take_string(char *string) return value; #elif !GLIB_CHECK_VERSION(2, 38, 0) GVariant *value; - GBytes *bytes; + GBytes *bytes; g_return_val_if_fail(string != NULL, NULL); g_return_val_if_fail(g_utf8_validate(string, -1, NULL), NULL); diff --git a/src/libnm-glib-aux/nm-hash-utils.h b/src/libnm-glib-aux/nm-hash-utils.h index e2707fc21..c1306200b 100644 --- a/src/libnm-glib-aux/nm-hash-utils.h +++ b/src/libnm-glib-aux/nm-hash-utils.h @@ -185,10 +185,10 @@ nm_hash_update_str(NMHashState *state, const char *str) /* Like nm_hash_update_str(), but restricted to arrays only. nm_hash_update_str() only works * with a @str argument that cannot be NULL. If you have a string pointer, that is never NULL, use * nm_hash_update() instead. */ -#define nm_hash_update_strarr(state, str) \ - (_Generic(&(str), const char(*)[sizeof(str)] \ - : nm_hash_update_str((state), (str)), char(*)[sizeof(str)] \ - : nm_hash_update_str((state), (str)))) +#define nm_hash_update_strarr(state, str) \ + (_Generic(&(str), \ + const char(*)[sizeof(str)]: nm_hash_update_str((state), (str)), \ + char(*)[sizeof(str)]: nm_hash_update_str((state), (str)))) #else #define nm_hash_update_strarr(state, str) nm_hash_update_str((state), (str)) #endif diff --git a/src/libnm-glib-aux/nm-macros-internal.h b/src/libnm-glib-aux/nm-macros-internal.h index 03eff1cbf..b74d73240 100644 --- a/src/libnm-glib-aux/nm-macros-internal.h +++ b/src/libnm-glib-aux/nm-macros-internal.h @@ -259,41 +259,41 @@ NM_G_ERROR_MSG(GError *error) #if _NM_CC_SUPPORT_GENERIC #define _NM_CONSTCAST_FULL_1(type, obj_expr, obj) \ - (_Generic ((obj_expr), \ - const void *: ((const type *) (obj)), \ - void *: (( type *) (obj)), \ - const type *: ((const type *) (obj)), \ - type *: (( type *) (obj)))) + (_Generic((obj_expr), \ + const void *: ((const type *) (obj)), \ + void *: ((type *) (obj)), \ + const type *: ((const type *) (obj)), \ + type *: ((type *) (obj)))) #define _NM_CONSTCAST_FULL_2(type, obj_expr, obj, alias_type2) \ - (_Generic ((obj_expr), \ - const void *: ((const type *) (obj)), \ - void *: (( type *) (obj)), \ - const alias_type2 *: ((const type *) (obj)), \ - alias_type2 *: (( type *) (obj)), \ - const type *: ((const type *) (obj)), \ - type *: (( type *) (obj)))) + (_Generic((obj_expr), \ + const void *: ((const type *) (obj)), \ + void *: ((type *) (obj)), \ + const alias_type2 *: ((const type *) (obj)), \ + alias_type2 *: ((type *) (obj)), \ + const type *: ((const type *) (obj)), \ + type *: ((type *) (obj)))) #define _NM_CONSTCAST_FULL_3(type, obj_expr, obj, alias_type2, alias_type3) \ - (_Generic ((obj_expr), \ - const void *: ((const type *) (obj)), \ - void *: (( type *) (obj)), \ - const alias_type2 *: ((const type *) (obj)), \ - alias_type2 *: (( type *) (obj)), \ - const alias_type3 *: ((const type *) (obj)), \ - alias_type3 *: (( type *) (obj)), \ - const type *: ((const type *) (obj)), \ - type *: (( type *) (obj)))) + (_Generic((obj_expr), \ + const void *: ((const type *) (obj)), \ + void *: ((type *) (obj)), \ + const alias_type2 *: ((const type *) (obj)), \ + alias_type2 *: ((type *) (obj)), \ + const alias_type3 *: ((const type *) (obj)), \ + alias_type3 *: ((type *) (obj)), \ + const type *: ((const type *) (obj)), \ + type *: ((type *) (obj)))) #define _NM_CONSTCAST_FULL_4(type, obj_expr, obj, alias_type2, alias_type3, alias_type4) \ - (_Generic ((obj_expr), \ - const void *: ((const type *) (obj)), \ - void *: (( type *) (obj)), \ - const alias_type2 *: ((const type *) (obj)), \ - alias_type2 *: (( type *) (obj)), \ - const alias_type3 *: ((const type *) (obj)), \ - alias_type3 *: (( type *) (obj)), \ - const alias_type4 *: ((const type *) (obj)), \ - alias_type4 *: (( type *) (obj)), \ - const type *: ((const type *) (obj)), \ - type *: (( type *) (obj)))) + (_Generic((obj_expr), \ + const void *: ((const type *) (obj)), \ + void *: ((type *) (obj)), \ + const alias_type2 *: ((const type *) (obj)), \ + alias_type2 *: ((type *) (obj)), \ + const alias_type3 *: ((const type *) (obj)), \ + alias_type3 *: ((type *) (obj)), \ + const alias_type4 *: ((const type *) (obj)), \ + alias_type4 *: ((type *) (obj)), \ + const type *: ((const type *) (obj)), \ + type *: ((type *) (obj)))) #define _NM_CONSTCAST_FULL_x(type, obj_expr, obj, n, ...) \ (_NM_CONSTCAST_FULL_##n(type, obj_expr, obj, ##__VA_ARGS__)) #define _NM_CONSTCAST_FULL_y(type, obj_expr, obj, n, ...) \ @@ -308,18 +308,18 @@ NM_G_ERROR_MSG(GError *error) #if _NM_CC_SUPPORT_GENERIC #define NM_UNCONST_PTR(type, arg) \ - _Generic((arg), const type * : ((type *) (arg)), type * : ((type *) (arg))) + _Generic((arg), const type *: ((type *) (arg)), type *: ((type *) (arg))) #else #define NM_UNCONST_PTR(type, arg) ((type *) (arg)) #endif #if _NM_CC_SUPPORT_GENERIC -#define NM_UNCONST_PPTR(type, arg) \ - _Generic ((arg), \ - const type * *: ((type **) (arg)), \ - type * *: ((type **) (arg)), \ - const type *const*: ((type **) (arg)), \ - type *const*: ((type **) (arg))) +#define NM_UNCONST_PPTR(type, arg) \ + _Generic((arg), \ + const type **: ((type **) (arg)), \ + type **: ((type **) (arg)), \ + const type *const *: ((type **) (arg)), \ + type *const *: ((type **) (arg))) #else #define NM_UNCONST_PPTR(type, arg) ((type **) (arg)) #endif @@ -377,30 +377,29 @@ NM_G_ERROR_MSG(GError *error) * These macros do the cast, but they only accept a compatible input * type, otherwise they will fail compilation. */ -#define NM_CAST_STRV_MC(value) \ - (_Generic ((value), \ - const char * *: (const char * *) (value), \ - char * *: (const char * *) (value), \ - void *: (const char * *) (value))) -#define NM_CAST_STRV_CC(value) \ - (_Generic ((value), \ - const char *const*: (const char *const*) (value), \ - const char * *: (const char *const*) (value), \ - char *const*: (const char *const*) (value), \ - char * *: (const char *const*) (value), \ - const void *: (const char *const*) (value), \ - void *: (const char *const*) (value))) +#define NM_CAST_STRV_MC(value) \ + (_Generic((value), \ + const char **: (const char **) (value), \ + char **: (const char **) (value), \ + void *: (const char **) (value))) +#define NM_CAST_STRV_CC(value) \ + (_Generic((value), \ + const char *const *: (const char *const *) (value), \ + const char **: (const char *const *) (value), \ + char *const *: (const char *const *) (value), \ + char **: (const char *const *) (value), \ + const void *: (const char *const *) (value), \ + void *: (const char *const *) (value))) #else #define NM_CAST_STRV_MC(value) ((const char **) (value)) #define NM_CAST_STRV_CC(value) ((const char *const *) (value)) #endif #if _NM_CC_SUPPORT_GENERIC -#define NM_PROPAGATE_CONST(test_expr, ptr) \ - (_Generic ((test_expr), \ - const typeof (*(test_expr)) *: ((const typeof (*(ptr)) *) (ptr)), \ - default: (_Generic ((test_expr), \ - typeof (*(test_expr)) *: (ptr))))) +#define NM_PROPAGATE_CONST(test_expr, ptr) \ + (_Generic((test_expr), \ + const typeof(*(test_expr)) *: ((const typeof(*(ptr)) *) (ptr)), \ + default: (_Generic((test_expr), typeof(*(test_expr)) *: (ptr))))) #else #define NM_PROPAGATE_CONST(test_expr, ptr) (ptr) #endif @@ -1499,23 +1498,21 @@ _nm_strndup_a_step(char *s, const char *str, gsize len) * * Instead, this generic macro is supposed to handle all integers correctly. */ #if _NM_CC_SUPPORT_GENERIC -#define nm_strdup_int(val) \ - _Generic((val), char \ - : g_strdup_printf("%d", (int) (val)), \ - \ - signed char \ - : g_strdup_printf("%d", (signed) (val)), signed short \ - : g_strdup_printf("%d", (signed) (val)), signed \ - : g_strdup_printf("%d", (signed) (val)), signed long \ - : g_strdup_printf("%ld", (signed long) (val)), signed long long \ - : g_strdup_printf("%lld", (signed long long) (val)), \ - \ - unsigned char \ - : g_strdup_printf("%u", (unsigned) (val)), unsigned short \ - : g_strdup_printf("%u", (unsigned) (val)), unsigned \ - : g_strdup_printf("%u", (unsigned) (val)), unsigned long \ - : g_strdup_printf("%lu", (unsigned long) (val)), unsigned long long \ - : g_strdup_printf("%llu", (unsigned long long) (val))) +#define nm_strdup_int(val) \ + _Generic((val), \ + char: g_strdup_printf("%d", (int) (val)), \ + \ + signed char: g_strdup_printf("%d", (signed) (val)), \ + signed short: g_strdup_printf("%d", (signed) (val)), \ + signed: g_strdup_printf("%d", (signed) (val)), \ + signed long: g_strdup_printf("%ld", (signed long) (val)), \ + signed long long: g_strdup_printf("%lld", (signed long long) (val)), \ + \ + unsigned char: g_strdup_printf("%u", (unsigned) (val)), \ + unsigned short: g_strdup_printf("%u", (unsigned) (val)), \ + unsigned: g_strdup_printf("%u", (unsigned) (val)), \ + unsigned long: g_strdup_printf("%lu", (unsigned long) (val)), \ + unsigned long long: g_strdup_printf("%llu", (unsigned long long) (val))) #else #define nm_strdup_int(val) \ ((sizeof(val) == sizeof(guint64) && ((typeof(val)) -1) > 0) \ diff --git a/src/libnm-glib-aux/nm-shared-utils.h b/src/libnm-glib-aux/nm-shared-utils.h index 60735d3c8..e37cf5e65 100644 --- a/src/libnm-glib-aux/nm-shared-utils.h +++ b/src/libnm-glib-aux/nm-shared-utils.h @@ -79,7 +79,7 @@ G_STATIC_ASSERT(sizeof(int) == sizeof(gint32)); ({ \ _nm_unused typeof(value) _value = (value); \ \ - _Generic((value), int : TRUE); \ + _Generic((value), int: TRUE); \ }) #else #define _NM_INT_LE_MAXINT32(value) \ diff --git a/src/libnm-glib-aux/nm-test-utils.h b/src/libnm-glib-aux/nm-test-utils.h index d4e1e4b1f..de6fd0f1b 100644 --- a/src/libnm-glib-aux/nm-test-utils.h +++ b/src/libnm-glib-aux/nm-test-utils.h @@ -2887,8 +2887,7 @@ _nmtst_variant_new_vardict(int dummy, ...) G_STMT_END #else #define _nmtst_assert_variant_bytestring_cmp_str(_ptr, _ptr2, _len) \ - G_STMT_START \ - {} \ + G_STMT_START {} \ G_STMT_END #endif diff --git a/src/libnm-platform/nm-netlink.h b/src/libnm-platform/nm-netlink.h index 35e296298..efd482adf 100644 --- a/src/libnm-platform/nm-netlink.h +++ b/src/libnm-platform/nm-netlink.h @@ -93,19 +93,19 @@ struct nla_policy { /* static asserts that @tb and @policy are suitable arguments to nla_parse(). */ #if _NM_CC_SUPPORT_GENERIC -#define _nl_static_assert_tb(tb, policy) \ - G_STMT_START \ - { \ - G_STATIC_ASSERT_EXPR(G_N_ELEMENTS(tb) > 0); \ - \ +#define _nl_static_assert_tb(tb, policy) \ + G_STMT_START \ + { \ + G_STATIC_ASSERT_EXPR(G_N_ELEMENTS(tb) > 0); \ + \ /* We allow @policy to be either a C array or NULL. The sizeof() * must either match the expected array size or we check that * "policy" has typeof(NULL). This isn't a perfect compile time check, - * but good enough. */ \ - G_STATIC_ASSERT_EXPR( \ - _Generic((policy), typeof(NULL) : 1, default \ - : (sizeof(policy) == G_N_ELEMENTS(tb) * sizeof(struct nla_policy)))); \ - } \ + * but good enough. */ \ + G_STATIC_ASSERT_EXPR(_Generic((policy), \ + typeof(NULL): 1, \ + default: (sizeof(policy) == G_N_ELEMENTS(tb) * sizeof(struct nla_policy)))); \ + } \ G_STMT_END #else #define _nl_static_assert_tb(tb, policy) G_STATIC_ASSERT_EXPR(G_N_ELEMENTS(tb) > 0) diff --git a/src/libnm-std-aux/nm-std-aux.h b/src/libnm-std-aux/nm-std-aux.h index a146487ef..59e7a6e76 100644 --- a/src/libnm-std-aux/nm-std-aux.h +++ b/src/libnm-std-aux/nm-std-aux.h @@ -327,9 +327,9 @@ typedef uint64_t _nm_bitwise nm_be64_t; * * It's useful to check the let the compiler ensure that @value is * of a certain type. */ -#define _NM_ENSURE_TYPE(type, value) (_Generic((value), type : (value))) +#define _NM_ENSURE_TYPE(type, value) (_Generic((value), type: (value))) #define _NM_ENSURE_TYPE_CONST(type, value) \ - (_Generic((value), const type : ((const type)(value)), type : ((const type)(value)))) + (_Generic((value), const type: ((const type)(value)), type: ((const type)(value)))) #else #define _NM_ENSURE_TYPE(type, value) (value) #define _NM_ENSURE_TYPE_CONST(type, value) ((const type)(value)) @@ -348,7 +348,7 @@ typedef uint64_t _nm_bitwise nm_be64_t; #if _NM_CC_SUPPORT_GENERIC && (!defined(__clang__) || __clang_major__ > 3) #define NM_STRUCT_OFFSET_ENSURE_TYPE(type, container, field) \ - (_Generic((&(((container *) NULL)->field))[0], type : nm_offsetof(container, field))) + (_Generic((&(((container *) NULL)->field))[0], type: nm_offsetof(container, field))) #else #define NM_STRUCT_OFFSET_ENSURE_TYPE(type, container, field) nm_offsetof(container, field) #endif