mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-25 03:40:07 +01:00
libnm: sort attribute names in nm_ip_address_get_attribute_names()
The order in which the attribute names are returns should be defined and stable. Sort them and re-use the helper functions. Sorting is good, because it gives a consistent order. Maybe we don't want to commit to this in the API, officially the order is still arbitrary. In practice, we rely on the order of attribute names when converting the attributes to a string. The same configuration should produce the same string representation. That doesn't mean we commit to a fixed order in the string representation. It does not mean, that the order must always be this way, we can still change it. But between multiple runs of the same binary, the order should be stable. Note that our hash tables are seeded with a random number. Hence, their order is not only abitrary, it is also unstable and changes for each run of the application.
This commit is contained in:
parent
bfcbc0063c
commit
17ff856bf4
1 changed files with 4 additions and 14 deletions
|
|
@ -537,22 +537,12 @@ nm_ip_address_set_prefix (NMIPAddress *address,
|
|||
char **
|
||||
nm_ip_address_get_attribute_names (NMIPAddress *address)
|
||||
{
|
||||
GHashTableIter iter;
|
||||
const char *key;
|
||||
GPtrArray *names;
|
||||
const char **names;
|
||||
|
||||
g_return_val_if_fail (address != NULL, NULL);
|
||||
g_return_val_if_fail (address, NULL);
|
||||
|
||||
names = g_ptr_array_new ();
|
||||
|
||||
if (address->attributes) {
|
||||
g_hash_table_iter_init (&iter, address->attributes);
|
||||
while (g_hash_table_iter_next (&iter, (gpointer *) &key, NULL))
|
||||
g_ptr_array_add (names, g_strdup (key));
|
||||
}
|
||||
g_ptr_array_add (names, NULL);
|
||||
|
||||
return (char **) g_ptr_array_free (names, FALSE);
|
||||
names = nm_utils_strdict_get_keys (address->attributes, TRUE, NULL);
|
||||
return nm_utils_strv_make_deep_copied_nonnull (names);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue