Commit 17ff856b authored by Thomas Haller's avatar Thomas Haller

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.
parent bfcbc006
......@@ -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;
g_return_val_if_fail (address != NULL, NULL);
names = g_ptr_array_new ();
const char **names;
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);
g_return_val_if_fail (address, 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);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment