glib-aux: swap arguments for nm_array_find_bsearch()

Have "len" before "elem_size". That is consistent with g_qsort_with_data()
and bsearch(), and is also what I would expect.

Note that the previous commit just renamed the function. If a user
of the new, changed API gets backported to an older branch, we will
get a compilation error and note that the arguments need to be adjusted.
This commit is contained in:
Thomas Haller 2022-09-27 09:14:30 +02:00
parent 2953ebccba
commit f786b05479
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728
13 changed files with 16 additions and 16 deletions

View file

@ -7905,8 +7905,8 @@ nm_manager_set_capability(NMManager *self, NMCapability cap)
priv = NM_MANAGER_GET_PRIVATE(self);
idx = nm_array_find_bsearch(nm_g_array_index_p(priv->capabilities, guint32, 0),
sizeof(guint32),
priv->capabilities->len,
sizeof(guint32),
&cap_i,
nm_cmp_uint32_p_with_data,
NULL);

View file

@ -1081,8 +1081,8 @@ nms_ifcfg_well_known_key_find_info(const char *key, gssize *out_idx)
G_STATIC_ASSERT(G_STRUCT_OFFSET(NMSIfcfgKeyTypeInfo, key_name) == 0);
idx = nm_array_find_bsearch(nms_ifcfg_well_known_keys,
sizeof(nms_ifcfg_well_known_keys[0]),
G_N_ELEMENTS(nms_ifcfg_well_known_keys),
sizeof(nms_ifcfg_well_known_keys[0]),
&key,
nm_strcmp_p_with_data,
NULL);

View file

@ -280,8 +280,8 @@ nm_supplicant_settings_verify_setting(const char *key, const char *value, const
}
opt_idx = nm_array_find_bsearch(opt_table,
sizeof(opt_table[0]),
G_N_ELEMENTS(opt_table),
sizeof(opt_table[0]),
&key,
nm_strcmp_p_with_data,
NULL);

View file

@ -272,8 +272,8 @@ nm_ethtool_data_get_by_optname(const char *optname)
_ASSERT_data();
idx = nm_array_find_bsearch((gconstpointer *) _by_name,
sizeof(_by_name[0]),
_NM_ETHTOOL_ID_NUM,
sizeof(_by_name[0]),
optname,
_by_name_cmp,
NULL);

View file

@ -776,8 +776,8 @@ nml_dbus_meta_property_get(const NMLDBusMetaIface *meta_iface,
nm_assert(dbus_property_name);
idx = nm_array_find_bsearch(meta_iface->dbus_properties,
sizeof(meta_iface->dbus_properties[0]),
meta_iface->n_dbus_properties,
sizeof(meta_iface->dbus_properties[0]),
&dbus_property_name,
nm_strcmp_p_with_data,
NULL);

View file

@ -350,8 +350,8 @@ nm_auth_permission_from_string(const char *str)
if (!NM_STR_HAS_PREFIX(str, AUTH_PERMISSION_PREFIX))
return NM_CLIENT_PERMISSION_NONE;
idx = nm_array_find_bsearch(nm_auth_permission_sorted,
sizeof(nm_auth_permission_sorted[0]),
G_N_ELEMENTS(nm_auth_permission_sorted),
sizeof(nm_auth_permission_sorted[0]),
&str[NM_STRLEN(AUTH_PERMISSION_PREFIX)],
_nm_auth_permission_from_string_cmp,
NULL);

View file

@ -694,8 +694,8 @@ nm_meta_setting_infos_by_name(const char *name)
G_STATIC_ASSERT_EXPR(G_STRUCT_OFFSET(NMMetaSettingInfo, setting_name) == 0);
idx = nm_array_find_bsearch(nm_meta_setting_infos,
sizeof(NMMetaSettingInfo),
_NM_META_SETTING_TYPE_NUM,
sizeof(NMMetaSettingInfo),
&name,
nm_strcmp_p_with_data,
NULL);

View file

@ -2935,8 +2935,8 @@ _rr_dbus_attr_from_name(const char *name)
}
idx = nm_array_find_bsearch(rr_dbus_data,
sizeof(rr_dbus_data[0]),
_RR_DBUS_ATTR_NUM,
sizeof(rr_dbus_data[0]),
&name,
nm_strcmp_p_with_data,
NULL);

View file

@ -478,8 +478,8 @@ _nm_sett_info_setting_get_property_info(const NMSettInfoSetting *sett_info,
G_STATIC_ASSERT_EXPR(G_STRUCT_OFFSET(NMSettInfoProperty, name) == 0);
idx = nm_array_find_bsearch(sett_info->property_infos,
sizeof(NMSettInfoProperty),
sett_info->property_infos_len,
sizeof(NMSettInfoProperty),
&property_name,
nm_strcmp_p_with_data,
NULL);

View file

@ -8858,8 +8858,8 @@ _test_find_binary_search_do_uint32(const int *int_array, gsize len)
}
idx = nm_array_find_bsearch(array,
sizeof(guint32),
len,
sizeof(guint32),
&NEEDLE,
nm_cmp_uint32_p_with_data,
NULL);
@ -8967,8 +8967,8 @@ test_nm_utils_ptrarray_find_binary_search_with_duplicates(void)
idx_first2 = nm_utils_ptrarray_find_first(arr, i_len, p);
idx2 = nm_array_find_bsearch(arr,
sizeof(gpointer),
i_len,
sizeof(gpointer),
&p,
_test_bin_search2_cmp_p,
NULL);

View file

@ -3094,8 +3094,8 @@ nm_utils_named_value_list_find(const NMUtilsNamedValue *arr,
if (sorted) {
return nm_array_find_bsearch(arr,
sizeof(NMUtilsNamedValue),
len,
sizeof(NMUtilsNamedValue),
&name,
nm_strcmp_p_with_data,
NULL);
@ -3906,8 +3906,8 @@ nm_ptrarray_find_bsearch_range(gconstpointer *list,
/**
* nm_array_find_bsearch:
* @list: the list to search. It must be sorted according to @cmpfcn ordering.
* @elem_size: the size in bytes of each element in the list
* @len: the number of elements in @list
* @elem_size: the size in bytes of each element in the list
* @needle: the value that is searched
* @cmpfcn: the compare function. The elements @list are passed as first
* argument to @cmpfcn, while @needle is passed as second. Usually, the
@ -3929,8 +3929,8 @@ nm_ptrarray_find_bsearch_range(gconstpointer *list,
*/
gssize
nm_array_find_bsearch(gconstpointer list,
gsize elem_size,
gsize len,
gsize elem_size,
gconstpointer needle,
GCompareDataFunc cmpfcn,
gpointer user_data)

View file

@ -2134,8 +2134,8 @@ gssize nm_ptrarray_find_bsearch_range(gconstpointer *list,
})
gssize nm_array_find_bsearch(gconstpointer list,
gsize elem_size,
gsize len,
gsize elem_size,
gconstpointer needle,
GCompareDataFunc cmpfcn,
gpointer user_data);

View file

@ -694,8 +694,8 @@ nm_meta_setting_infos_by_name(const char *name)
G_STATIC_ASSERT_EXPR(G_STRUCT_OFFSET(NMMetaSettingInfo, setting_name) == 0);
idx = nm_array_find_bsearch(nm_meta_setting_infos,
sizeof(NMMetaSettingInfo),
_NM_META_SETTING_TYPE_NUM,
sizeof(NMMetaSettingInfo),
&name,
nm_strcmp_p_with_data,
NULL);