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.
This commit is contained in:
Thomas Haller 2017-11-15 16:06:43 +01:00
parent 93adadbdcb
commit a6be2f4aa9
16 changed files with 29 additions and 29 deletions

View file

@ -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;

View file

@ -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;

View file

@ -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");

View file

@ -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);
}

View file

@ -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);
}
/**

View file

@ -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

View file

@ -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 *));

View file

@ -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;
}

View file

@ -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;

View file

@ -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, ' ', '=');

View file

@ -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;

View file

@ -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

View file

@ -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));

View file

@ -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++) {

View file

@ -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);

View file

@ -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);