From 6fbd280b35d4f5b903857ff332739dabb21989d5 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 15 Nov 2017 15:39:50 +0100 Subject: [PATCH 1/9] shared: add nm_hash_static() to get a static hash key When using siphash24(), the hash value depends on the hashed input and the key from _get_hash_key(). If the input is static, so is also the result of siphash24(), albeit the bits are scrabbled more. Add a nm_hash_static() to get such a static key, but without actually doing siphash24(). The static key is also xored with a static_seed. For that, also mangle the first byte of the hash key using siphash24() itself. That is, because nm_hash_static() only uses the first guint of the random key. Hence, we want that this first guint has all the entropy of the entire key. We use siphash24() itself, to mangle all bits of the 16 byte key into the first guint. --- libnm-core/tests/test-general.c | 3 ++ shared/nm-utils/nm-hash-utils.c | 69 ++++++++++++++++++++++++--------- shared/nm-utils/nm-hash-utils.h | 2 + 3 files changed, 56 insertions(+), 18 deletions(-) diff --git a/libnm-core/tests/test-general.c b/libnm-core/tests/test-general.c index 9f134583b3..59da6b0c34 100644 --- a/libnm-core/tests/test-general.c +++ b/libnm-core/tests/test-general.c @@ -168,6 +168,9 @@ _test_hash_str (const char *str) static void test_nm_hash (void) { + g_assert (nm_hash_static (0)); + g_assert (nm_hash_static (777)); + _test_hash_str (""); _test_hash_str ("a"); _test_hash_str ("aa"); diff --git a/shared/nm-utils/nm-hash-utils.c b/shared/nm-utils/nm-hash-utils.c index c563140e3a..f1e4bd9f9e 100644 --- a/shared/nm-utils/nm-hash-utils.c +++ b/shared/nm-utils/nm-hash-utils.c @@ -39,29 +39,62 @@ static const guint8 * _get_hash_key (void) { static const guint8 *volatile global_seed = NULL; + /* the returned hash is aligned to guin64, hence, it is safe + * to use it as guint* or guint64* pointer. */ + static union { + guint8 v8[HASH_KEY_SIZE]; + } g_arr _nm_alignas (guint64); + static gsize g_lock; const guint8 *g; + struct siphash siph_state; + uint64_t h; + guint *p; g = global_seed; - if (G_UNLIKELY (g == NULL)) { - /* the returned hash is aligned to guin64, hence, it is save - * to use it as guint* or guint64* pointer. */ - static union { - guint8 v8[HASH_KEY_SIZE]; - } g_arr _nm_alignas (guint64); - static gsize g_lock; - - if (g_once_init_enter (&g_lock)) { - nm_utils_random_bytes (g_arr.v8, sizeof (g_arr.v8)); - g_atomic_pointer_compare_and_exchange (&global_seed, NULL, g_arr.v8); - g = g_arr.v8; - g_once_init_leave (&g_lock, 1); - } else { - g = global_seed; - nm_assert (g); - } + if (G_LIKELY (g != NULL)) { + nm_assert (g == g_arr.v8); + return g; } - return g; + if (g_once_init_enter (&g_lock)) { + + nm_utils_random_bytes (g_arr.v8, sizeof (g_arr.v8)); + + /* use siphash() of the key-size, to mangle the first guint. Otherwise, + * the first guint has only the entropy that nm_utils_random_bytes() + * generated for the first 4 bytes and relies on a good random generator. */ + siphash24_init (&siph_state, g_arr.v8); + siphash24_compress (g_arr.v8, sizeof (g_arr.v8), &siph_state); + h = siphash24_finalize (&siph_state); + p = (guint *) g_arr.v8; + if (sizeof (guint) < sizeof (h)) + *p = *p ^ ((guint) (h & 0xFFFFFFFFu)) ^ ((guint) (h >> 32)); + else + *p = *p ^ ((guint) (h & 0xFFFFFFFFu)); + + g_atomic_pointer_compare_and_exchange (&global_seed, NULL, g_arr.v8); + g_once_init_leave (&g_lock, 1); + } + + nm_assert (global_seed == g_arr.v8); + return g_arr.v8; +} + +guint +nm_hash_static (guint static_seed) +{ + /* note that we only xor the static_seed with the key. + * We don't use siphash24(), which would mix the bits better. + * Note that this doesn't matter, because static_seed is not + * supposed to be a value that you are hashing (for that, use + * full siphash24()). + * Instead, different callers may set a different static_seed + * so that nm_hash_str(NULL) != nm_hash_ptr(NULL). + * + * Also, ensure that we don't return zero. + */ + return ((*((const guint *) _get_hash_key ())) ^ static_seed) + ?: static_seed ?: 3679500967u; } void diff --git a/shared/nm-utils/nm-hash-utils.h b/shared/nm-utils/nm-hash-utils.h index 276e1ebe02..21396f2814 100644 --- a/shared/nm-utils/nm-hash-utils.h +++ b/shared/nm-utils/nm-hash-utils.h @@ -31,6 +31,8 @@ struct _NMHashState { typedef struct _NMHashState NMHashState; +guint nm_hash_static (guint static_seed); + void nm_hash_init (NMHashState *state, guint static_seed); static inline guint From 3751cceeec2bdf246c04e5bd846086e6feeeb7b6 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 16 Nov 2017 11:40:19 +0100 Subject: [PATCH 2/9] shared: inline fast-path for hash _get_hash_key() --- shared/nm-utils/nm-hash-utils.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/shared/nm-utils/nm-hash-utils.c b/shared/nm-utils/nm-hash-utils.c index f1e4bd9f9e..4cfb62bd50 100644 --- a/shared/nm-utils/nm-hash-utils.c +++ b/shared/nm-utils/nm-hash-utils.c @@ -35,10 +35,11 @@ G_STATIC_ASSERT (sizeof (guint) * HASH_KEY_SIZE_GUINT >= HASH_KEY_SIZE); +static const guint8 *volatile global_seed = NULL; + static const guint8 * -_get_hash_key (void) +_get_hash_key_init (void) { - static const guint8 *volatile global_seed = NULL; /* the returned hash is aligned to guin64, hence, it is safe * to use it as guint* or guint64* pointer. */ static union { @@ -80,6 +81,16 @@ _get_hash_key (void) return g_arr.v8; } +#define _get_hash_key() \ + ({ \ + const guint8 *_g; \ + \ + _g = global_seed; \ + if (G_UNLIKELY (_g == NULL)) \ + _g = _get_hash_key_init (); \ + _g; \ + }) + guint nm_hash_static (guint static_seed) { From c3d98a3df6432f3d9d143dec6d328feec0873b4a Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 15 Nov 2017 15:14:19 +0100 Subject: [PATCH 3/9] shared: optimize nm_hash_str() for NULL to not use siphash24() --- libnm-core/tests/test-general.c | 4 ++++ shared/nm-utils/nm-hash-utils.c | 9 ++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/libnm-core/tests/test-general.c b/libnm-core/tests/test-general.c index 59da6b0c34..0529d07d1f 100644 --- a/libnm-core/tests/test-general.c +++ b/libnm-core/tests/test-general.c @@ -171,6 +171,10 @@ test_nm_hash (void) g_assert (nm_hash_static (0)); g_assert (nm_hash_static (777)); + g_assert (nm_hash_str (NULL)); + g_assert (nm_hash_str ("")); + g_assert (nm_hash_str ("a")); + _test_hash_str (""); _test_hash_str ("a"); _test_hash_str ("aa"); diff --git a/shared/nm-utils/nm-hash-utils.c b/shared/nm-utils/nm-hash-utils.c index 4cfb62bd50..0d0ba373a1 100644 --- a/shared/nm-utils/nm-hash-utils.c +++ b/shared/nm-utils/nm-hash-utils.c @@ -127,11 +127,10 @@ nm_hash_str (const char *str) { NMHashState h; - if (str) { - nm_hash_init (&h, 1867854211u); - nm_hash_update_str (&h, str); - } else - nm_hash_init (&h, 842995561u); + if (!str) + return nm_hash_static (1867854211u); + nm_hash_init (&h, 1867854211u); + nm_hash_update_str (&h, str); return nm_hash_complete (&h); } From ecd106101bcdd9ac56aac8765bf828f7137cc7e3 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 15 Nov 2017 15:33:32 +0100 Subject: [PATCH 4/9] shared: use siphash24() for nm_hash_ptr() siphash24() mixes the bits much better then our naive xor. Don't bypass siphash24(). We supposedly use it for the better hashing properties, so use it also for pointers. --- libnm-core/tests/test-general.c | 4 ++++ shared/nm-utils/nm-hash-utils.c | 15 ++++++--------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/libnm-core/tests/test-general.c b/libnm-core/tests/test-general.c index 0529d07d1f..4294e5e833 100644 --- a/libnm-core/tests/test-general.c +++ b/libnm-core/tests/test-general.c @@ -175,6 +175,10 @@ test_nm_hash (void) g_assert (nm_hash_str ("")); g_assert (nm_hash_str ("a")); + g_assert (nm_hash_ptr (NULL)); + g_assert (nm_hash_ptr ("")); + g_assert (nm_hash_ptr ("a")); + _test_hash_str (""); _test_hash_str ("a"); _test_hash_str ("aa"); diff --git a/shared/nm-utils/nm-hash-utils.c b/shared/nm-utils/nm-hash-utils.c index 0d0ba373a1..e4daf1a07c 100644 --- a/shared/nm-utils/nm-hash-utils.c +++ b/shared/nm-utils/nm-hash-utils.c @@ -143,16 +143,13 @@ nm_str_hash (gconstpointer str) guint nm_hash_ptr (gconstpointer ptr) { - guint h; + NMHashState h; - h = ((const guint *) _get_hash_key ())[0]; - - if (sizeof (ptr) <= sizeof (guint)) - h = h ^ ((guint) ((uintptr_t) ptr)); - else - h = h ^ ((guint) (((guint64) (uintptr_t) ptr) >> 32)) ^ ((guint) ((uintptr_t) ptr)); - - return h ?: 2907677551u; + if (!ptr) + return nm_hash_static (2907677551u); + nm_hash_init (&h, 2907677551u); + nm_hash_update (&h, &ptr, sizeof (ptr)); + return nm_hash_complete (&h); } guint From 3ee8de20c452955b30c28d4c5080a976d77f507c Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 15 Nov 2017 15:26:51 +0100 Subject: [PATCH 5/9] all: include "nm-utils/nm-hash-utils.h" by default Next we will use siphash24() instead of the glib version g_direct_hash() or g_str_hash(). Hence, the "nm-utils/nm-hash-utils.h" header becomes very fundamental and will be needed basically everywhere. Instead of requiring the users to include them, let it be included via "nm-default.h" header. --- clients/cli/common.c | 1 - clients/cli/connections.c | 2 -- clients/cli/nmcli.c | 2 -- clients/common/nm-meta-setting-desc.c | 1 - clients/common/nm-secret-agent-simple.c | 2 -- clients/common/tests/test-general.c | 2 -- clients/tui/nmt-connect-connection-list.c | 2 -- libnm-core/nm-utils.c | 1 - libnm-core/tests/test-general.c | 1 - shared/nm-default.h | 4 ++++ src/devices/bluetooth/nm-bluez4-adapter.c | 1 - src/nm-auth-utils.c | 1 - src/nm-core-utils.h | 2 -- src/settings/plugins/ifnet/nms-ifnet-wpa-parser.c | 1 - 14 files changed, 4 insertions(+), 19 deletions(-) diff --git a/clients/cli/common.c b/clients/cli/common.c index 0f5aea575c..4f369f458b 100644 --- a/clients/cli/common.c +++ b/clients/cli/common.c @@ -31,7 +31,6 @@ #include #include -#include "nm-utils/nm-hash-utils.h" #include "nm-vpn-helpers.h" #include "nm-client-utils.h" diff --git a/clients/cli/connections.c b/clients/cli/connections.c index d85901e6fd..91f96b262c 100644 --- a/clients/cli/connections.c +++ b/clients/cli/connections.c @@ -31,8 +31,6 @@ #include #include -#include "nm-utils/nm-hash-utils.h" - #include "nm-client-utils.h" #include "nm-vpn-helpers.h" #include "nm-meta-setting-access.h" diff --git a/clients/cli/nmcli.c b/clients/cli/nmcli.c index ee621ca3bb..b0b31261c0 100644 --- a/clients/cli/nmcli.c +++ b/clients/cli/nmcli.c @@ -36,8 +36,6 @@ #include "nm-client-utils.h" -#include "nm-utils/nm-hash-utils.h" - #include "polkit-agent.h" #include "utils.h" #include "common.h" diff --git a/clients/common/nm-meta-setting-desc.c b/clients/common/nm-meta-setting-desc.c index 142aab81dd..4835b0fb56 100644 --- a/clients/common/nm-meta-setting-desc.c +++ b/clients/common/nm-meta-setting-desc.c @@ -25,7 +25,6 @@ #include #include "nm-common-macros.h" -#include "nm-utils/nm-hash-utils.h" #include "nm-utils/nm-enum-utils.h" #include "NetworkManager.h" diff --git a/clients/common/nm-secret-agent-simple.c b/clients/common/nm-secret-agent-simple.c index 4ef1be239a..21aaf99540 100644 --- a/clients/common/nm-secret-agent-simple.c +++ b/clients/common/nm-secret-agent-simple.c @@ -33,8 +33,6 @@ #include -#include "nm-utils/nm-hash-utils.h" - #include "NetworkManager.h" #include "nm-vpn-service-plugin.h" diff --git a/clients/common/tests/test-general.c b/clients/common/tests/test-general.c index 64efd14d2a..e6a06ca535 100644 --- a/clients/common/tests/test-general.c +++ b/clients/common/tests/test-general.c @@ -21,8 +21,6 @@ #include "NetworkManager.h" -#include "nm-utils/nm-hash-utils.h" - #include "nm-meta-setting-access.h" #include "nm-utils/nm-test-utils.h" diff --git a/clients/tui/nmt-connect-connection-list.c b/clients/tui/nmt-connect-connection-list.c index 6e69a04b8f..263bc96c8d 100644 --- a/clients/tui/nmt-connect-connection-list.c +++ b/clients/tui/nmt-connect-connection-list.c @@ -30,8 +30,6 @@ #include "NetworkManager.h" -#include "nm-utils/nm-hash-utils.h" - #include "nmtui.h" #include "nmt-connect-connection-list.h" diff --git a/libnm-core/nm-utils.c b/libnm-core/nm-utils.c index a3c363c52a..52e320421e 100644 --- a/libnm-core/nm-utils.c +++ b/libnm-core/nm-utils.c @@ -36,7 +36,6 @@ #include "nm-utils/nm-jansson.h" #include "nm-utils/nm-enum-utils.h" -#include "nm-utils/nm-hash-utils.h" #include "nm-common-macros.h" #include "nm-utils-private.h" #include "nm-setting-private.h" diff --git a/libnm-core/tests/test-general.c b/libnm-core/tests/test-general.c index 4294e5e833..59af87d324 100644 --- a/libnm-core/tests/test-general.c +++ b/libnm-core/tests/test-general.c @@ -26,7 +26,6 @@ #include #include "nm-utils/c-list-util.h" -#include "nm-utils/nm-hash-utils.h" #include "nm-utils.h" #include "nm-setting-private.h" diff --git a/shared/nm-default.h b/shared/nm-default.h index 9e2377cf80..eb4fbc9e17 100644 --- a/shared/nm-default.h +++ b/shared/nm-default.h @@ -178,6 +178,10 @@ _nm_g_return_if_fail_warning (const char *log_domain, #include "nm-utils/nm-macros-internal.h" #include "nm-utils/nm-shared-utils.h" +#if ((NETWORKMANAGER_COMPILATION) & NM_NETWORKMANAGER_COMPILATION_LIB_LEGACY) == 0 +#include "nm-utils/nm-hash-utils.h" +#endif + #include "nm-version.h" /*****************************************************************************/ diff --git a/src/devices/bluetooth/nm-bluez4-adapter.c b/src/devices/bluetooth/nm-bluez4-adapter.c index 0f19f9981a..c8ef7a2716 100644 --- a/src/devices/bluetooth/nm-bluez4-adapter.c +++ b/src/devices/bluetooth/nm-bluez4-adapter.c @@ -25,7 +25,6 @@ #include #include "nm-dbus-interface.h" -#include "nm-utils/nm-hash-utils.h" #include "nm-bluez-device.h" #include "nm-bluez-common.h" #include "nm-core-internal.h" diff --git a/src/nm-auth-utils.c b/src/nm-auth-utils.c index f1aff43029..f4279b1dfa 100644 --- a/src/nm-auth-utils.c +++ b/src/nm-auth-utils.c @@ -24,7 +24,6 @@ #include -#include "nm-utils/nm-hash-utils.h" #include "nm-setting-connection.h" #include "nm-auth-subject.h" #include "nm-auth-manager.h" diff --git a/src/nm-core-utils.h b/src/nm-core-utils.h index cc78472442..7078153e99 100644 --- a/src/nm-core-utils.h +++ b/src/nm-core-utils.h @@ -25,8 +25,6 @@ #include #include -#include "nm-utils/nm-hash-utils.h" - #include "nm-connection.h" /*****************************************************************************/ diff --git a/src/settings/plugins/ifnet/nms-ifnet-wpa-parser.c b/src/settings/plugins/ifnet/nms-ifnet-wpa-parser.c index 2b62e88659..9253a2aa10 100644 --- a/src/settings/plugins/ifnet/nms-ifnet-wpa-parser.c +++ b/src/settings/plugins/ifnet/nms-ifnet-wpa-parser.c @@ -26,7 +26,6 @@ #include #include -#include "nm-utils/nm-hash-utils.h" #include "settings/nm-settings-plugin.h" #include "nms-ifnet-net-parser.h" From b58481b31ec5785d208a7b11df5b05fc50c158e2 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 15 Nov 2017 16:03:33 +0100 Subject: [PATCH 6/9] all: don't use g_direct_equal() for hash table equality function GHashTable optimizes a NULL equality function to use direct pointer comparison. That saves the overhead of calling g_direct_equal(). This is also documented behavior for g_hash_table_new(). While at it, also don't pass g_direct_hash() but use the default of %NULL. The behavior is the same, but consistently don't use g_direct_hash(). --- libnm-glib/nm-client.c | 2 +- libnm/nm-manager.c | 2 +- src/devices/nm-arping-manager.c | 2 +- src/devices/nm-device-factory.c | 2 +- src/devices/nm-device.c | 6 +++--- src/dhcp/nm-dhcp-manager.c | 2 +- src/nm-bus-manager.c | 2 +- src/nm-checkpoint.c | 2 +- src/nm-dispatcher.c | 4 ++-- src/nm-exported-object.c | 4 ++-- src/nm-manager.c | 4 ++-- src/nm-session-monitor.c | 2 +- src/platform/nm-platform.c | 2 +- src/settings/nm-inotify-helper.c | 2 +- 14 files changed, 19 insertions(+), 19 deletions(-) diff --git a/libnm-glib/nm-client.c b/libnm-glib/nm-client.c index f14c8e49bc..183cdc933f 100644 --- a/libnm-glib/nm-client.c +++ b/libnm-glib/nm-client.c @@ -157,7 +157,7 @@ nm_client_init (NMClient *client) priv->state = NM_STATE_UNKNOWN; - priv->permissions = g_hash_table_new (g_direct_hash, g_direct_equal); + priv->permissions = g_hash_table_new (NULL, NULL); } static void diff --git a/libnm/nm-manager.c b/libnm/nm-manager.c index aa749232be..dd689895c1 100644 --- a/libnm/nm-manager.c +++ b/libnm/nm-manager.c @@ -192,7 +192,7 @@ nm_manager_init (NMManager *manager) priv->state = NM_STATE_UNKNOWN; priv->connectivity = NM_CONNECTIVITY_UNKNOWN; - priv->permissions = g_hash_table_new (g_direct_hash, g_direct_equal); + priv->permissions = g_hash_table_new (NULL, NULL); priv->devices = g_ptr_array_new (); priv->all_devices = g_ptr_array_new (); priv->active_connections = g_ptr_array_new (); diff --git a/src/devices/nm-arping-manager.c b/src/devices/nm-arping-manager.c index 51f80e08e4..30e1cf1028 100644 --- a/src/devices/nm-arping-manager.c +++ b/src/devices/nm-arping-manager.c @@ -428,7 +428,7 @@ nm_arping_manager_init (NMArpingManager *self) { NMArpingManagerPrivate *priv = NM_ARPING_MANAGER_GET_PRIVATE (self); - priv->addresses = g_hash_table_new_full (g_direct_hash, g_direct_equal, + priv->addresses = g_hash_table_new_full (NULL, NULL, NULL, destroy_address_info); priv->state = STATE_INIT; } diff --git a/src/devices/nm-device-factory.c b/src/devices/nm-device-factory.c index 97f011c5e9..86af75e643 100644 --- a/src/devices/nm-device-factory.c +++ b/src/devices/nm-device-factory.c @@ -351,7 +351,7 @@ nm_device_factory_manager_load_factories (NMDeviceFactoryManagerFactoryFunc call g_return_if_fail (factories_by_link == NULL); g_return_if_fail (factories_by_setting == NULL); - factories_by_link = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_object_unref); + factories_by_link = g_hash_table_new_full (NULL, NULL, NULL, g_object_unref); factories_by_setting = g_hash_table_new_full (nm_str_hash, g_str_equal, NULL, (GDestroyNotify) factories_list_unref); #define _ADD_INTERNAL(get_type_fcn) \ diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 81d8884283..5da88db3d9 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -6217,7 +6217,7 @@ shared4_new_config (NMDevice *self, NMConnection *connection) guint32 count = 0; if (G_UNLIKELY (!shared_ips)) - shared_ips = g_hash_table_new (g_direct_hash, g_direct_equal); + shared_ips = g_hash_table_new (NULL, NULL); else { while (g_hash_table_lookup (shared_ips, GUINT_TO_POINTER (start + count))) { count += ntohl (0x100); @@ -12072,7 +12072,7 @@ nm_device_recheck_available_connections (NMDevice *self) priv = NM_DEVICE_GET_PRIVATE(self); if (g_hash_table_size (priv->available_connections) > 0) { - prune_list = g_hash_table_new (g_direct_hash, g_direct_equal); + prune_list = g_hash_table_new (NULL, NULL); g_hash_table_iter_init (&h_iter, priv->available_connections); while (g_hash_table_iter_next (&h_iter, (gpointer *) &connection, NULL)) g_hash_table_add (prune_list, connection); @@ -14131,7 +14131,7 @@ nm_device_init (NMDevice *self) priv->rfkill_type = RFKILL_TYPE_UNKNOWN; priv->unmanaged_flags = NM_UNMANAGED_PLATFORM_INIT; priv->unmanaged_mask = priv->unmanaged_flags; - priv->available_connections = g_hash_table_new_full (g_direct_hash, g_direct_equal, g_object_unref, NULL); + priv->available_connections = g_hash_table_new_full (NULL, NULL, g_object_unref, NULL); priv->ip6_saved_properties = g_hash_table_new_full (nm_str_hash, g_str_equal, NULL, g_free); priv->sys_iface_state = NM_DEVICE_SYS_IFACE_STATE_EXTERNAL; diff --git a/src/dhcp/nm-dhcp-manager.c b/src/dhcp/nm-dhcp-manager.c index f5c7c84b76..c6f0a24d5d 100644 --- a/src/dhcp/nm-dhcp-manager.c +++ b/src/dhcp/nm-dhcp-manager.c @@ -429,7 +429,7 @@ nm_dhcp_manager_init (NMDhcpManager *self) nm_log_info (LOGD_DHCP, "dhcp-init: Using DHCP client '%s'", client_factory->name); priv->client_factory = client_factory; - priv->clients = g_hash_table_new_full (g_direct_hash, g_direct_equal, + priv->clients = g_hash_table_new_full (NULL, NULL, NULL, (GDestroyNotify) g_object_unref); } diff --git a/src/nm-bus-manager.c b/src/nm-bus-manager.c index f6b86e903f..d506f9f300 100644 --- a/src/nm-bus-manager.c +++ b/src/nm-bus-manager.c @@ -307,7 +307,7 @@ private_server_new (const char *path, g_signal_connect (server, "new-connection", G_CALLBACK (private_server_new_connection), s); - s->obj_managers = g_hash_table_new_full (g_direct_hash, g_direct_equal, + s->obj_managers = g_hash_table_new_full (NULL, NULL, (GDestroyNotify) private_server_manager_destroy, g_free); s->manager = manager; diff --git a/src/nm-checkpoint.c b/src/nm-checkpoint.c index c3a2e74360..2a2a174909 100644 --- a/src/nm-checkpoint.c +++ b/src/nm-checkpoint.c @@ -466,7 +466,7 @@ nm_checkpoint_init (NMCheckpoint *self) { NMCheckpointPrivate *priv = NM_CHECKPOINT_GET_PRIVATE (self); - priv->devices = g_hash_table_new_full (g_direct_hash, g_direct_equal, + priv->devices = g_hash_table_new_full (NULL, NULL, NULL, device_checkpoint_destroy); } diff --git a/src/nm-dispatcher.c b/src/nm-dispatcher.c index 237afdefe7..b90176416e 100644 --- a/src/nm-dispatcher.c +++ b/src/nm-dispatcher.c @@ -345,8 +345,8 @@ static void _ensure_requests (void) { if (G_UNLIKELY (requests == NULL)) { - requests = g_hash_table_new_full (g_direct_hash, - g_direct_equal, + requests = g_hash_table_new_full (NULL, + NULL, NULL, (GDestroyNotify) dispatcher_info_free); } diff --git a/src/nm-exported-object.c b/src/nm-exported-object.c index 94264caa6e..cf28946398 100644 --- a/src/nm-exported-object.c +++ b/src/nm-exported-object.c @@ -501,8 +501,8 @@ nm_exported_object_create_skeletons (NMExportedObject *self, ifdata->property_changed_signal_id = g_signal_lookup ("properties-changed", G_OBJECT_TYPE (ifdata->interface)); - ifdata->pending_notifies = g_hash_table_new_full (g_direct_hash, - g_direct_equal, + ifdata->pending_notifies = g_hash_table_new_full (NULL, + NULL, NULL, (GDestroyNotify) g_variant_unref); } diff --git a/src/nm-manager.c b/src/nm-manager.c index 06423603b7..e2e7499f86 100644 --- a/src/nm-manager.c +++ b/src/nm-manager.c @@ -3016,7 +3016,7 @@ find_slaves (NMManager *manager, s_con = nm_connection_get_setting_connection (NM_CONNECTION (connection)); g_return_val_if_fail (s_con, NULL); - devices = g_hash_table_new (g_direct_hash, g_direct_equal); + devices = g_hash_table_new (NULL, NULL); /* Search through all connections, not only inactive ones, because * even if a slave was already active, it might be deactivated during @@ -6233,7 +6233,7 @@ nm_manager_init (NMManager *self) priv->timestamp_update_id = g_timeout_add_seconds (300, (GSourceFunc) periodic_update_active_connection_timestamps, self); priv->metered = NM_METERED_UNKNOWN; - priv->sleep_devices = g_hash_table_new (g_direct_hash, g_direct_equal); + priv->sleep_devices = g_hash_table_new (NULL, NULL); } static gboolean diff --git a/src/nm-session-monitor.c b/src/nm-session-monitor.c index 20781bd45d..045c29af4c 100644 --- a/src/nm-session-monitor.c +++ b/src/nm-session-monitor.c @@ -258,7 +258,7 @@ ck_init (NMSessionMonitor *monitor) if (g_file_query_exists (file, NULL)) { if ((monitor->ck.monitor = g_file_monitor_file (file, G_FILE_MONITOR_NONE, NULL, &error))) { - monitor->ck.cache = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_free); + monitor->ck.cache = g_hash_table_new_full (NULL, NULL, NULL, g_free); g_signal_connect (monitor->ck.monitor, "changed", G_CALLBACK (ck_changed), diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c index f94d93e257..d6332648e4 100644 --- a/src/platform/nm-platform.c +++ b/src/platform/nm-platform.c @@ -594,7 +594,7 @@ nm_platform_link_get_all (NMPlatform *self, gboolean sort_by_name) * further by moving children/slaves to the end. */ g_ptr_array_sort_with_data (links, _link_get_all_presort, GINT_TO_POINTER (sort_by_name)); - unseen = g_hash_table_new (g_direct_hash, g_direct_equal); + unseen = g_hash_table_new (NULL, NULL); for (i = 0; i < links->len; i++) { item = NMP_OBJECT_CAST_LINK (links->pdata[i]); nm_assert (item->ifindex > 0); diff --git a/src/settings/nm-inotify-helper.c b/src/settings/nm-inotify-helper.c index 4c65b02da5..5d190b11a9 100644 --- a/src/settings/nm-inotify-helper.c +++ b/src/settings/nm-inotify-helper.c @@ -172,7 +172,7 @@ nm_inotify_helper_init (NMInotifyHelper *self) { NMInotifyHelperPrivate *priv = NM_INOTIFY_HELPER_GET_PRIVATE (self); - priv->wd_refs = g_hash_table_new (g_direct_hash, g_direct_equal); + priv->wd_refs = g_hash_table_new (NULL, NULL); } static void From 93adadbdcbbccfeafb8523b129f103bb5b23f7d5 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 15 Nov 2017 16:06:43 +0100 Subject: [PATCH 7/9] all: use nm_direct_hash() instead of g_direct_hash() We also do this for libnm, where it causes visible changes in behavior. But if somebody would rely on the hashing implementation for hash tables, it would be seriously flawed. --- clients/cli/connections.c | 2 +- clients/common/tests/test-general.c | 2 +- libnm/nm-manager.c | 2 +- src/devices/nm-arping-manager.c | 2 +- src/devices/nm-device-factory.c | 2 +- src/devices/nm-device.c | 6 +++--- src/dhcp/nm-dhcp-listener.c | 2 +- src/dhcp/nm-dhcp-manager.c | 2 +- src/nm-bus-manager.c | 2 +- src/nm-checkpoint.c | 2 +- src/nm-dispatcher.c | 2 +- src/nm-exported-object.c | 2 +- src/nm-manager.c | 6 +++--- src/nm-policy.c | 6 +++--- src/nm-session-monitor.c | 2 +- src/platform/nm-linux-platform.c | 2 +- src/platform/nm-platform.c | 4 ++-- src/settings/nm-inotify-helper.c | 2 +- src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-plugin.c | 2 +- src/settings/plugins/keyfile/nms-keyfile-plugin.c | 2 +- src/tests/test-general-with-expect.c | 2 +- 21 files changed, 28 insertions(+), 28 deletions(-) diff --git a/clients/cli/connections.c b/clients/cli/connections.c index 91f96b262c..f34eec8fc9 100644 --- a/clients/cli/connections.c +++ b/clients/cli/connections.c @@ -3308,7 +3308,7 @@ _dynamic_options_set (const NMMetaAbstractInfo *abstract_info, PropertyInfFlags v, v2; if (G_UNLIKELY (!cache)) - cache = g_hash_table_new (NULL, NULL); + cache = g_hash_table_new (nm_direct_hash, NULL); if (g_hash_table_lookup_extended (cache, (gpointer) abstract_info, NULL, &p)) v = GPOINTER_TO_UINT (p); diff --git a/clients/common/tests/test-general.c b/clients/common/tests/test-general.c index e6a06ca535..77ff4cea33 100644 --- a/clients/common/tests/test-general.c +++ b/clients/common/tests/test-general.c @@ -102,7 +102,7 @@ test_client_meta_check (void) if (info->valid_parts) { gsize i, l; - gs_unref_hashtable GHashTable *dup = g_hash_table_new (NULL, NULL); + gs_unref_hashtable GHashTable *dup = g_hash_table_new (nm_direct_hash, NULL); l = NM_PTRARRAY_LEN (info->valid_parts); g_assert (l >= 2); diff --git a/libnm/nm-manager.c b/libnm/nm-manager.c index dd689895c1..2f00545d9d 100644 --- a/libnm/nm-manager.c +++ b/libnm/nm-manager.c @@ -192,7 +192,7 @@ nm_manager_init (NMManager *manager) priv->state = NM_STATE_UNKNOWN; priv->connectivity = NM_CONNECTIVITY_UNKNOWN; - priv->permissions = g_hash_table_new (NULL, NULL); + priv->permissions = g_hash_table_new (nm_direct_hash, NULL); priv->devices = g_ptr_array_new (); priv->all_devices = g_ptr_array_new (); priv->active_connections = g_ptr_array_new (); diff --git a/src/devices/nm-arping-manager.c b/src/devices/nm-arping-manager.c index 30e1cf1028..eb5b0574e1 100644 --- a/src/devices/nm-arping-manager.c +++ b/src/devices/nm-arping-manager.c @@ -428,7 +428,7 @@ nm_arping_manager_init (NMArpingManager *self) { NMArpingManagerPrivate *priv = NM_ARPING_MANAGER_GET_PRIVATE (self); - priv->addresses = g_hash_table_new_full (NULL, NULL, + priv->addresses = g_hash_table_new_full (nm_direct_hash, NULL, NULL, destroy_address_info); priv->state = STATE_INIT; } diff --git a/src/devices/nm-device-factory.c b/src/devices/nm-device-factory.c index 86af75e643..9bfdd8e099 100644 --- a/src/devices/nm-device-factory.c +++ b/src/devices/nm-device-factory.c @@ -351,7 +351,7 @@ nm_device_factory_manager_load_factories (NMDeviceFactoryManagerFactoryFunc call g_return_if_fail (factories_by_link == NULL); g_return_if_fail (factories_by_setting == NULL); - factories_by_link = g_hash_table_new_full (NULL, NULL, NULL, g_object_unref); + factories_by_link = g_hash_table_new_full (nm_direct_hash, NULL, NULL, g_object_unref); factories_by_setting = g_hash_table_new_full (nm_str_hash, g_str_equal, NULL, (GDestroyNotify) factories_list_unref); #define _ADD_INTERNAL(get_type_fcn) \ diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 5da88db3d9..be3f760e14 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -6217,7 +6217,7 @@ shared4_new_config (NMDevice *self, NMConnection *connection) guint32 count = 0; if (G_UNLIKELY (!shared_ips)) - shared_ips = g_hash_table_new (NULL, NULL); + shared_ips = g_hash_table_new (nm_direct_hash, NULL); else { while (g_hash_table_lookup (shared_ips, GUINT_TO_POINTER (start + count))) { count += ntohl (0x100); @@ -12072,7 +12072,7 @@ nm_device_recheck_available_connections (NMDevice *self) priv = NM_DEVICE_GET_PRIVATE(self); if (g_hash_table_size (priv->available_connections) > 0) { - prune_list = g_hash_table_new (NULL, NULL); + prune_list = g_hash_table_new (nm_direct_hash, NULL); g_hash_table_iter_init (&h_iter, priv->available_connections); while (g_hash_table_iter_next (&h_iter, (gpointer *) &connection, NULL)) g_hash_table_add (prune_list, connection); @@ -14131,7 +14131,7 @@ nm_device_init (NMDevice *self) priv->rfkill_type = RFKILL_TYPE_UNKNOWN; priv->unmanaged_flags = NM_UNMANAGED_PLATFORM_INIT; priv->unmanaged_mask = priv->unmanaged_flags; - priv->available_connections = g_hash_table_new_full (NULL, NULL, g_object_unref, NULL); + priv->available_connections = g_hash_table_new_full (nm_direct_hash, NULL, g_object_unref, NULL); priv->ip6_saved_properties = g_hash_table_new_full (nm_str_hash, g_str_equal, NULL, g_free); priv->sys_iface_state = NM_DEVICE_SYS_IFACE_STATE_EXTERNAL; diff --git a/src/dhcp/nm-dhcp-listener.c b/src/dhcp/nm-dhcp-listener.c index a0449816cd..4dda0b5a05 100644 --- a/src/dhcp/nm-dhcp-listener.c +++ b/src/dhcp/nm-dhcp-listener.c @@ -300,7 +300,7 @@ nm_dhcp_listener_init (NMDhcpListener *self) NMDhcpListenerPrivate *priv = NM_DHCP_LISTENER_GET_PRIVATE (self); /* Maps GDBusConnection :: signal-id */ - priv->connections = g_hash_table_new (NULL, NULL); + priv->connections = g_hash_table_new (nm_direct_hash, NULL); priv->dbus_mgr = nm_bus_manager_get (); diff --git a/src/dhcp/nm-dhcp-manager.c b/src/dhcp/nm-dhcp-manager.c index c6f0a24d5d..118950aff9 100644 --- a/src/dhcp/nm-dhcp-manager.c +++ b/src/dhcp/nm-dhcp-manager.c @@ -429,7 +429,7 @@ nm_dhcp_manager_init (NMDhcpManager *self) nm_log_info (LOGD_DHCP, "dhcp-init: Using DHCP client '%s'", client_factory->name); priv->client_factory = client_factory; - priv->clients = g_hash_table_new_full (NULL, NULL, + priv->clients = g_hash_table_new_full (nm_direct_hash, NULL, NULL, (GDestroyNotify) g_object_unref); } diff --git a/src/nm-bus-manager.c b/src/nm-bus-manager.c index d506f9f300..a1aca26136 100644 --- a/src/nm-bus-manager.c +++ b/src/nm-bus-manager.c @@ -307,7 +307,7 @@ private_server_new (const char *path, g_signal_connect (server, "new-connection", G_CALLBACK (private_server_new_connection), s); - s->obj_managers = g_hash_table_new_full (NULL, NULL, + s->obj_managers = g_hash_table_new_full (nm_direct_hash, NULL, (GDestroyNotify) private_server_manager_destroy, g_free); s->manager = manager; diff --git a/src/nm-checkpoint.c b/src/nm-checkpoint.c index 2a2a174909..54b577642e 100644 --- a/src/nm-checkpoint.c +++ b/src/nm-checkpoint.c @@ -466,7 +466,7 @@ nm_checkpoint_init (NMCheckpoint *self) { NMCheckpointPrivate *priv = NM_CHECKPOINT_GET_PRIVATE (self); - priv->devices = g_hash_table_new_full (NULL, NULL, + priv->devices = g_hash_table_new_full (nm_direct_hash, NULL, NULL, device_checkpoint_destroy); } diff --git a/src/nm-dispatcher.c b/src/nm-dispatcher.c index b90176416e..c465adf258 100644 --- a/src/nm-dispatcher.c +++ b/src/nm-dispatcher.c @@ -345,7 +345,7 @@ static void _ensure_requests (void) { if (G_UNLIKELY (requests == NULL)) { - requests = g_hash_table_new_full (NULL, + requests = g_hash_table_new_full (nm_direct_hash, NULL, NULL, (GDestroyNotify) dispatcher_info_free); diff --git a/src/nm-exported-object.c b/src/nm-exported-object.c index cf28946398..c52a38b700 100644 --- a/src/nm-exported-object.c +++ b/src/nm-exported-object.c @@ -501,7 +501,7 @@ nm_exported_object_create_skeletons (NMExportedObject *self, ifdata->property_changed_signal_id = g_signal_lookup ("properties-changed", G_OBJECT_TYPE (ifdata->interface)); - ifdata->pending_notifies = g_hash_table_new_full (NULL, + ifdata->pending_notifies = g_hash_table_new_full (nm_direct_hash, NULL, NULL, (GDestroyNotify) g_variant_unref); diff --git a/src/nm-manager.c b/src/nm-manager.c index e2e7499f86..1ab6e39e01 100644 --- a/src/nm-manager.c +++ b/src/nm-manager.c @@ -3016,7 +3016,7 @@ find_slaves (NMManager *manager, s_con = nm_connection_get_setting_connection (NM_CONNECTION (connection)); g_return_val_if_fail (s_con, NULL); - devices = g_hash_table_new (NULL, NULL); + devices = g_hash_table_new (nm_direct_hash, NULL); /* Search through all connections, not only inactive ones, because * even if a slave was already active, it might be deactivated during @@ -5105,7 +5105,7 @@ nm_manager_write_device_state (NMManager *self) gs_unref_hashtable GHashTable *seen_ifindexes = NULL; gint nm_owned; - seen_ifindexes = g_hash_table_new (NULL, NULL); + seen_ifindexes = g_hash_table_new (nm_direct_hash, NULL); for (devices = priv->devices; devices; devices = devices->next) { NMDevice *device = NM_DEVICE (devices->data); @@ -6233,7 +6233,7 @@ nm_manager_init (NMManager *self) priv->timestamp_update_id = g_timeout_add_seconds (300, (GSourceFunc) periodic_update_active_connection_timestamps, self); priv->metered = NM_METERED_UNKNOWN; - priv->sleep_devices = g_hash_table_new (NULL, NULL); + priv->sleep_devices = g_hash_table_new (nm_direct_hash, NULL); } static gboolean diff --git a/src/nm-policy.c b/src/nm-policy.c index 17bbfbd621..7353d635af 100644 --- a/src/nm-policy.c +++ b/src/nm-policy.c @@ -333,7 +333,7 @@ device_ip6_prefix_delegated (NMDevice *device, /* Allocate a delegation delegation for new prefix. */ g_array_set_size (priv->ip6_prefix_delegations, i + 1); delegation = &g_array_index (priv->ip6_prefix_delegations, IP6PrefixDelegation, i); - delegation->subnets = g_hash_table_new (NULL, NULL); + delegation->subnets = g_hash_table_new (nm_direct_hash, NULL); delegation->next_subnet = 0; } @@ -2484,8 +2484,8 @@ nm_policy_init (NMPolicy *self) else /* default - full mode */ priv->hostname_mode = NM_POLICY_HOSTNAME_MODE_FULL; - priv->devices = g_hash_table_new (NULL, NULL); - priv->pending_active_connections = g_hash_table_new (NULL, NULL); + priv->devices = g_hash_table_new (nm_direct_hash, NULL); + priv->pending_active_connections = g_hash_table_new (nm_direct_hash, NULL); priv->ip6_prefix_delegations = g_array_new (FALSE, FALSE, sizeof (IP6PrefixDelegation)); g_array_set_clear_func (priv->ip6_prefix_delegations, clear_ip6_prefix_delegation); } diff --git a/src/nm-session-monitor.c b/src/nm-session-monitor.c index 045c29af4c..bbf27acdbb 100644 --- a/src/nm-session-monitor.c +++ b/src/nm-session-monitor.c @@ -258,7 +258,7 @@ ck_init (NMSessionMonitor *monitor) if (g_file_query_exists (file, NULL)) { if ((monitor->ck.monitor = g_file_monitor_file (file, G_FILE_MONITOR_NONE, NULL, &error))) { - monitor->ck.cache = g_hash_table_new_full (NULL, NULL, NULL, g_free); + monitor->ck.cache = g_hash_table_new_full (nm_direct_hash, NULL, NULL, g_free); g_signal_connect (monitor->ck.monitor, "changed", G_CALLBACK (ck_changed), diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c index 359c3baf3a..0e7d74e270 100644 --- a/src/platform/nm-linux-platform.c +++ b/src/platform/nm-linux-platform.c @@ -6696,7 +6696,7 @@ nm_linux_platform_init (NMLinuxPlatform *self) priv->delayed_action.list_master_connected = g_ptr_array_new (); priv->delayed_action.list_refresh_link = g_ptr_array_new (); priv->delayed_action.list_wait_for_nl_response = g_array_new (FALSE, TRUE, sizeof (DelayedActionWaitForNlResponseData)); - priv->wifi_data = g_hash_table_new_full (NULL, NULL, NULL, (GDestroyNotify) wifi_utils_deinit); + priv->wifi_data = g_hash_table_new_full (nm_direct_hash, NULL, NULL, (GDestroyNotify) wifi_utils_deinit); } static void diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c index d6332648e4..f61355a084 100644 --- a/src/platform/nm-platform.c +++ b/src/platform/nm-platform.c @@ -594,7 +594,7 @@ nm_platform_link_get_all (NMPlatform *self, gboolean sort_by_name) * further by moving children/slaves to the end. */ g_ptr_array_sort_with_data (links, _link_get_all_presort, GINT_TO_POINTER (sort_by_name)); - unseen = g_hash_table_new (NULL, NULL); + unseen = g_hash_table_new (nm_direct_hash, NULL); for (i = 0; i < links->len; i++) { item = NMP_OBJECT_CAST_LINK (links->pdata[i]); nm_assert (item->ifindex > 0); @@ -3175,7 +3175,7 @@ ip4_addr_subnets_build_index (const GPtrArray *addresses, nm_assert (addresses && addresses->len); - subnets = g_hash_table_new (NULL, NULL); + subnets = g_hash_table_new (nm_direct_hash, NULL); /* Build a hash table of all addresses per subnet */ for (i = 0; i < addresses->len; i++) { diff --git a/src/settings/nm-inotify-helper.c b/src/settings/nm-inotify-helper.c index 5d190b11a9..51b180b233 100644 --- a/src/settings/nm-inotify-helper.c +++ b/src/settings/nm-inotify-helper.c @@ -172,7 +172,7 @@ nm_inotify_helper_init (NMInotifyHelper *self) { NMInotifyHelperPrivate *priv = NM_INOTIFY_HELPER_GET_PRIVATE (self); - priv->wd_refs = g_hash_table_new (NULL, NULL); + priv->wd_refs = g_hash_table_new (nm_direct_hash, NULL); } static void diff --git a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-plugin.c b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-plugin.c index da0920ef7c..1ebdeafa7f 100644 --- a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-plugin.c +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-plugin.c @@ -515,7 +515,7 @@ read_connections (SettingsPluginIfcfg *plugin) return; } - alive_connections = g_hash_table_new (NULL, NULL); + alive_connections = g_hash_table_new (nm_direct_hash, NULL); filenames = g_ptr_array_new_with_free_func (g_free); while ((item = g_dir_read_name (dir))) { diff --git a/src/settings/plugins/keyfile/nms-keyfile-plugin.c b/src/settings/plugins/keyfile/nms-keyfile-plugin.c index ee4db32048..dfc311af33 100644 --- a/src/settings/plugins/keyfile/nms-keyfile-plugin.c +++ b/src/settings/plugins/keyfile/nms-keyfile-plugin.c @@ -435,7 +435,7 @@ read_connections (NMSettingsPlugin *config) return; } - alive_connections = g_hash_table_new (NULL, NULL); + alive_connections = g_hash_table_new (nm_direct_hash, NULL); filenames = g_ptr_array_new_with_free_func (g_free); while ((item = g_dir_read_name (dir))) { diff --git a/src/tests/test-general-with-expect.c b/src/tests/test-general-with-expect.c index 2911d84d6e..5bbe5a25c5 100644 --- a/src/tests/test-general-with-expect.c +++ b/src/tests/test-general-with-expect.c @@ -432,7 +432,7 @@ test_nm_utils_array_remove_at_indexes (void) idx = g_array_new (FALSE, FALSE, sizeof (guint)); array = g_array_new (FALSE, FALSE, sizeof (gssize)); - unique = g_hash_table_new (NULL, NULL); + unique = g_hash_table_new (nm_direct_hash, NULL); for (i_len = 1; i_len < 20; i_len++) { for (i_idx_len = 1; i_idx_len <= i_len; i_idx_len++) { for (i_rnd = 0; i_rnd < 20; i_rnd++) { From a6be2f4aa9070e7f423b7c9992dbae51f092071e Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 15 Nov 2017 16:06:43 +0100 Subject: [PATCH 8/9] all: use nm_str_hash() instead of g_str_hash() We also do this for libnm and libnm-core, where it causes visible changes in behavior. But if somebody would rely on the hashing implementation for hash tables, it would be seriously flawed. --- libnm-core/nm-connection.c | 6 +++--- libnm-core/nm-keyfile-reader.c | 2 +- libnm-core/nm-setting-bond.c | 2 +- libnm-core/nm-setting-ip-config.c | 4 ++-- libnm-core/nm-setting-user.c | 2 +- libnm-core/nm-setting-vpn.c | 4 ++-- libnm-core/nm-setting-wired.c | 2 +- libnm-core/nm-setting.c | 6 +++--- libnm-core/nm-utils.c | 10 +++++----- libnm-core/tests/test-general.c | 4 ++-- libnm/nm-device.c | 2 +- libnm/nm-dhcp-config.c | 2 +- libnm/nm-manager.c | 2 +- libnm/nm-object.c | 2 +- libnm/nm-vpn-plugin-old.c | 4 ++-- libnm/nm-vpn-service-plugin.c | 4 ++-- 16 files changed, 29 insertions(+), 29 deletions(-) diff --git a/libnm-core/nm-connection.c b/libnm-core/nm-connection.c index d5e28f7b3e..5d03295edc 100644 --- a/libnm-core/nm-connection.c +++ b/libnm-core/nm-connection.c @@ -587,7 +587,7 @@ nm_connection_diff (NMConnection *a, if (a == b) return TRUE; - diffs = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_hash_table_destroy); + diffs = g_hash_table_new_full (nm_str_hash, g_str_equal, g_free, (GDestroyNotify) g_hash_table_destroy); /* Diff A to B, then B to A to capture keys in B that aren't in A */ if (diff_one_connection (a, b, flags, FALSE, diffs)) @@ -1370,7 +1370,7 @@ nm_connection_verify_secrets (NMConnection *connection, GError **error) * @parameters: (allow-none) (element-type utf8 gpointer): a #GHashTable with * normalization parameters to allow customization of the normalization by providing * specific arguments. Unknown arguments will be ignored and the default will be - * used. The keys must be strings, hashed by g_str_hash() and g_str_equal() functions. + * used. The keys must be strings compared with g_str_equal() function. * The values are opaque and depend on the parameter name. * @modified: (out) (allow-none): outputs whether any settings were modified. * @error: location to store error, or %NULL. Contains the reason, @@ -2716,7 +2716,7 @@ nm_connection_get_private (NMConnection *connection) priv, (GDestroyNotify) nm_connection_private_free); priv->self = connection; - priv->settings = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_object_unref); + priv->settings = g_hash_table_new_full (nm_str_hash, g_str_equal, NULL, g_object_unref); } return priv; diff --git a/libnm-core/nm-keyfile-reader.c b/libnm-core/nm-keyfile-reader.c index 0ac417cdb4..f40fe60f92 100644 --- a/libnm-core/nm-keyfile-reader.c +++ b/libnm-core/nm-keyfile-reader.c @@ -763,7 +763,7 @@ read_hash_of_string (GKeyFile *file, NMSetting *setting, const char *key) if (NM_IS_SETTING_USER (setting)) { gs_unref_hashtable GHashTable *data = NULL; - data = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); + data = g_hash_table_new_full (nm_str_hash, g_str_equal, g_free, g_free); for (iter = (const char *const*) keys; *iter; iter++) { gs_free char *to_free = NULL; char *value = NULL; diff --git a/libnm-core/nm-setting-bond.c b/libnm-core/nm-setting-bond.c index d12940f6f9..e85d1564ea 100644 --- a/libnm-core/nm-setting-bond.c +++ b/libnm-core/nm-setting-bond.c @@ -892,7 +892,7 @@ nm_setting_bond_init (NMSettingBond *setting) { NMSettingBondPrivate *priv = NM_SETTING_BOND_GET_PRIVATE (setting); - priv->options = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); + priv->options = g_hash_table_new_full (nm_str_hash, g_str_equal, g_free, g_free); /* Default values: */ nm_setting_bond_add_option (setting, NM_SETTING_BOND_OPTION_MODE, "balance-rr"); diff --git a/libnm-core/nm-setting-ip-config.c b/libnm-core/nm-setting-ip-config.c index 41ae0993f6..33664ae93a 100644 --- a/libnm-core/nm-setting-ip-config.c +++ b/libnm-core/nm-setting-ip-config.c @@ -593,7 +593,7 @@ nm_ip_address_set_attribute (NMIPAddress *address, const char *name, GVariant *v g_return_if_fail (strcmp (name, "address") != 0 && strcmp (name, "prefix") != 0); if (!address->attributes) { - address->attributes = g_hash_table_new_full (g_str_hash, g_str_equal, + address->attributes = g_hash_table_new_full (nm_str_hash, g_str_equal, g_free, (GDestroyNotify) g_variant_unref); } @@ -1227,7 +1227,7 @@ nm_ip_route_set_attribute (NMIPRoute *route, const char *name, GVariant *value) && strcmp (name, "next-hop") != 0 && strcmp (name, "metric") != 0); if (!route->attributes) { - route->attributes = g_hash_table_new_full (g_str_hash, g_str_equal, + route->attributes = g_hash_table_new_full (nm_str_hash, g_str_equal, g_free, (GDestroyNotify) g_variant_unref); } diff --git a/libnm-core/nm-setting-user.c b/libnm-core/nm-setting-user.c index 049607e146..526bbd2073 100644 --- a/libnm-core/nm-setting-user.c +++ b/libnm-core/nm-setting-user.c @@ -210,7 +210,7 @@ nm_setting_user_check_val (const char *val, GError **error) static GHashTable * _create_data_hash (void) { - return g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); + return g_hash_table_new_full (nm_str_hash, g_str_equal, g_free, g_free); } /** diff --git a/libnm-core/nm-setting-vpn.c b/libnm-core/nm-setting-vpn.c index 6b42e0c7a6..343bd9aa30 100644 --- a/libnm-core/nm-setting-vpn.c +++ b/libnm-core/nm-setting-vpn.c @@ -722,8 +722,8 @@ nm_setting_vpn_init (NMSettingVpn *setting) { NMSettingVpnPrivate *priv = NM_SETTING_VPN_GET_PRIVATE (setting); - priv->data = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); - priv->secrets = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, destroy_one_secret); + priv->data = g_hash_table_new_full (nm_str_hash, g_str_equal, g_free, g_free); + priv->secrets = g_hash_table_new_full (nm_str_hash, g_str_equal, g_free, destroy_one_secret); } static void diff --git a/libnm-core/nm-setting-wired.c b/libnm-core/nm-setting-wired.c index 9d255e1d07..09ed8949d0 100644 --- a/libnm-core/nm-setting-wired.c +++ b/libnm-core/nm-setting-wired.c @@ -829,7 +829,7 @@ nm_setting_wired_init (NMSettingWired *setting) { NMSettingWiredPrivate *priv = NM_SETTING_WIRED_GET_PRIVATE (setting); - priv->s390_options = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); + priv->s390_options = g_hash_table_new_full (nm_str_hash, g_str_equal, g_free, g_free); /* We use GArray rather than GPtrArray so it will automatically be NULL-terminated */ priv->mac_address_blacklist = g_array_new (TRUE, FALSE, sizeof (char *)); diff --git a/libnm-core/nm-setting.c b/libnm-core/nm-setting.c index 9c8e53aeac..297887411d 100644 --- a/libnm-core/nm-setting.c +++ b/libnm-core/nm-setting.c @@ -95,7 +95,7 @@ _ensure_registered (void) { if (G_UNLIKELY (registered_settings == NULL)) { nm_g_type_init (); - registered_settings = g_hash_table_new (g_str_hash, g_str_equal); + registered_settings = g_hash_table_new (nm_str_hash, g_str_equal); registered_settings_by_type = g_hash_table_new (_nm_gtype_hash, _nm_gtype_equal); } } @@ -807,7 +807,7 @@ _nm_setting_new_from_dbus (GType setting_type, GVariant *entry, *entry_key; char *key; - keys = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); + keys = g_hash_table_new_full (nm_str_hash, g_str_equal, g_free, NULL); g_variant_iter_init (&iter, setting_dict); while ((entry = g_variant_iter_next_value (&iter))) { @@ -1359,7 +1359,7 @@ nm_setting_diff (NMSetting *a, } if (*results == NULL) { - *results = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); + *results = g_hash_table_new_full (nm_str_hash, g_str_equal, g_free, NULL); results_created = TRUE; } diff --git a/libnm-core/nm-utils.c b/libnm-core/nm-utils.c index 52e320421e..c3001ab5d1 100644 --- a/libnm-core/nm-utils.c +++ b/libnm-core/nm-utils.c @@ -144,7 +144,7 @@ init_lang_to_encodings_hash (void) if (G_UNLIKELY (langToEncodings5 == NULL)) { /* Five-letter codes */ enc = (struct IsoLangToEncodings *) &isoLangEntries5[0]; - langToEncodings5 = g_hash_table_new (g_str_hash, g_str_equal); + langToEncodings5 = g_hash_table_new (nm_str_hash, g_str_equal); while (enc->lang) { g_hash_table_insert (langToEncodings5, (gpointer) enc->lang, (gpointer) enc->encodings); @@ -155,7 +155,7 @@ init_lang_to_encodings_hash (void) if (G_UNLIKELY (langToEncodings2 == NULL)) { /* Two-letter codes */ enc = (struct IsoLangToEncodings *) &isoLangEntries2[0]; - langToEncodings2 = g_hash_table_new (g_str_hash, g_str_equal); + langToEncodings2 = g_hash_table_new (nm_str_hash, g_str_equal); while (enc->lang) { g_hash_table_insert (langToEncodings2, (gpointer) enc->lang, (gpointer) enc->encodings); @@ -512,7 +512,7 @@ _nm_utils_strdict_from_dbus (GVariant *dbus_value, const char *key, *value; GHashTable *hash; - hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); + hash = g_hash_table_new_full (nm_str_hash, g_str_equal, g_free, g_free); g_variant_iter_init (&iter, dbus_value); while (g_variant_iter_next (&iter, "{&s&s}", &key, &value)) g_hash_table_insert (hash, g_strdup (key), g_strdup (value)); @@ -527,7 +527,7 @@ _nm_utils_copy_strdict (GHashTable *strdict) GHashTableIter iter; gpointer key, value; - copy = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); + copy = g_hash_table_new_full (nm_str_hash, g_str_equal, g_free, g_free); if (strdict) { g_hash_table_iter_init (&iter, strdict); while (g_hash_table_iter_next (&iter, &key, &value)) @@ -4861,7 +4861,7 @@ nm_utils_parse_variant_attributes (const char *string, g_return_val_if_fail (key_value_separator, NULL); g_return_val_if_fail (!error || !*error, NULL); - ht = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_variant_unref); + ht = g_hash_table_new_full (nm_str_hash, g_str_equal, g_free, (GDestroyNotify) g_variant_unref); while (TRUE) { gs_free char *name = NULL, *value = NULL; diff --git a/libnm-core/tests/test-general.c b/libnm-core/tests/test-general.c index 59af87d324..28724e7fd5 100644 --- a/libnm-core/tests/test-general.c +++ b/libnm-core/tests/test-general.c @@ -6098,7 +6098,7 @@ test_g_ptr_array_insert (void) static void test_g_hash_table_get_keys_as_array (void) { - GHashTable *table = g_hash_table_new (g_str_hash, g_str_equal); + GHashTable *table = g_hash_table_new (nm_str_hash, g_str_equal); guint length = 0; char **keys; @@ -6752,7 +6752,7 @@ test_route_attributes_format (void) gs_unref_hashtable GHashTable *ht = NULL; char *str; - ht = g_hash_table_new_full (g_str_hash, g_str_equal, + ht = g_hash_table_new_full (nm_str_hash, g_str_equal, NULL, (GDestroyNotify) g_variant_unref); str = nm_utils_format_variant_attributes (NULL, ' ', '='); diff --git a/libnm/nm-device.c b/libnm/nm-device.c index 65afd078dc..5e4c789394 100644 --- a/libnm/nm-device.c +++ b/libnm/nm-device.c @@ -2570,7 +2570,7 @@ nm_lldp_neighbor_new (void) neigh = g_new0 (NMLldpNeighbor, 1); neigh->refcount = 1; - neigh->attrs = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, + neigh->attrs = g_hash_table_new_full (nm_str_hash, g_str_equal, g_free, (GDestroyNotify) g_variant_unref); return neigh; diff --git a/libnm/nm-dhcp-config.c b/libnm/nm-dhcp-config.c index 3161e2960f..33b99ed04b 100644 --- a/libnm/nm-dhcp-config.c +++ b/libnm/nm-dhcp-config.c @@ -51,7 +51,7 @@ nm_dhcp_config_init (NMDhcpConfig *config) { NMDhcpConfigPrivate *priv = NM_DHCP_CONFIG_GET_PRIVATE (config); - priv->options = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); + priv->options = g_hash_table_new_full (nm_str_hash, g_str_equal, g_free, g_free); } static gboolean diff --git a/libnm/nm-manager.c b/libnm/nm-manager.c index 2f00545d9d..a8752d682d 100644 --- a/libnm/nm-manager.c +++ b/libnm/nm-manager.c @@ -1458,7 +1458,7 @@ checkpoint_rollback_cb (GObject *object, &variant, result, &error)) { - hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); + hash = g_hash_table_new_full (nm_str_hash, g_str_equal, g_free, NULL); g_variant_iter_init (&iter, variant); while (g_variant_iter_next (&iter, "{&su}", &path, &r)) g_hash_table_insert (hash, g_strdup (path), GUINT_TO_POINTER (r)); diff --git a/libnm/nm-object.c b/libnm/nm-object.c index c344a08dca..8297259d40 100644 --- a/libnm/nm-object.c +++ b/libnm/nm-object.c @@ -955,7 +955,7 @@ _nm_object_register_properties (NMObject *object, G_CALLBACK (properties_changed), object); g_ptr_array_add (priv->proxies, proxy); - instance = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); + instance = g_hash_table_new_full (nm_str_hash, g_str_equal, g_free, g_free); priv->property_tables = g_slist_prepend (priv->property_tables, instance); for (tmp = (NMPropertiesInfo *) info; tmp->name; tmp++) { diff --git a/libnm/nm-vpn-plugin-old.c b/libnm/nm-vpn-plugin-old.c index 2b5922b925..1892c394b7 100644 --- a/libnm/nm-vpn-plugin-old.c +++ b/libnm/nm-vpn-plugin-old.c @@ -728,8 +728,8 @@ nm_vpn_plugin_old_read_vpn_details (int fd, if (out_secrets) g_return_val_if_fail (*out_secrets == NULL, FALSE); - data = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); - secrets = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, free_secret); + data = g_hash_table_new_full (nm_str_hash, g_str_equal, g_free, g_free); + secrets = g_hash_table_new_full (nm_str_hash, g_str_equal, g_free, free_secret); line = g_string_new (NULL); diff --git a/libnm/nm-vpn-service-plugin.c b/libnm/nm-vpn-service-plugin.c index 31e1295488..79bd0f8193 100644 --- a/libnm/nm-vpn-service-plugin.c +++ b/libnm/nm-vpn-service-plugin.c @@ -750,8 +750,8 @@ nm_vpn_service_plugin_read_vpn_details (int fd, if (out_secrets) g_return_val_if_fail (*out_secrets == NULL, FALSE); - data = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); - secrets = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, free_secret); + data = g_hash_table_new_full (nm_str_hash, g_str_equal, g_free, g_free); + secrets = g_hash_table_new_full (nm_str_hash, g_str_equal, g_free, free_secret); line = g_string_new (NULL); From ac95f7da0bdf46f1ebce6ef3d5afa4beeec094d8 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 16 Nov 2017 10:47:54 +0100 Subject: [PATCH 9/9] build: include "siphash24.c" source in "nm-hash-utils.c" This allows the compiler to inline the siphash24*() functions for nm_hash_ptr() and nm_hash_str() (even without LTO). This of course only applies to nm_hash_ptr() and nm_hash_str(), which are implemented in "nm-hash-utils.c" itself. All other nm_hash_*() functions are inline functions in "nm-hash-utils.h", and thus these functions can be inlined instead. That is, in other cases, the nm_hash_*() function instead can be inlined. For nm_hash_ptr() and nm_hash_str() instead we want to inline the siphash24*() functions. So, no longer compile "siphash24.c" directly. Instead, only build "nm-hash-utils.c" which internally #include "siphash24.c". --- Makefile.am | 6 +++--- shared/nm-utils/nm-hash-utils.c | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Makefile.am b/Makefile.am index 449f77474a..4a8cd35292 100644 --- a/Makefile.am +++ b/Makefile.am @@ -460,7 +460,6 @@ libnm_core_lib_c_real = \ shared/nm-utils/nm-shared-utils.c \ shared/nm-utils/nm-random-utils.c \ shared/nm-utils/nm-udev-utils.c \ - shared/nm-utils/siphash24.c \ shared/nm-meta-setting.c \ libnm-core/crypto.c \ libnm-core/nm-connection.c \ @@ -3131,7 +3130,7 @@ $(src_tests_test_utils_OBJECTS): $(libnm_core_lib_h_pub_mkenums) src_tests_test_systemd_CPPFLAGS = $(src_libsystemd_nm_la_cppflags) src_tests_test_systemd_SOURCES = \ - shared/nm-utils/siphash24.c \ + shared/nm-utils/nm-hash-utils.c \ src/tests/test-systemd.c src_tests_test_systemd_LDADD = \ src/libsystemd-nm.la \ @@ -3324,7 +3323,6 @@ clients_common_libnmc_base_la_SOURCES = \ shared/nm-utils/nm-random-utils.h \ shared/nm-utils/nm-shared-utils.c \ shared/nm-utils/nm-shared-utils.h \ - shared/nm-utils/siphash24.c \ shared/nm-utils/siphash24.h \ \ clients/common/nm-secret-agent-simple.c \ @@ -4578,6 +4576,8 @@ EXTRA_DIST += \ shared/nm-utils/nm-vpn-plugin-macros.h \ shared/nm-utils/nm-vpn-plugin-utils.c \ shared/nm-utils/nm-vpn-plugin-utils.h \ + shared/nm-utils/siphash24.c \ + shared/nm-utils/siphash24.h \ shared/nm-utils/unaligned.h \ shared/nm-version-macros.h.in \ \ diff --git a/shared/nm-utils/nm-hash-utils.c b/shared/nm-utils/nm-hash-utils.c index e4daf1a07c..b096be692c 100644 --- a/shared/nm-utils/nm-hash-utils.c +++ b/shared/nm-utils/nm-hash-utils.c @@ -28,6 +28,8 @@ #include "nm-shared-utils.h" #include "nm-random-utils.h" +#include "siphash24.c" + /*****************************************************************************/ #define HASH_KEY_SIZE 16u