core: const arguments for _nm_utils_ptrarray_find_*() functions

This commit is contained in:
Thomas Haller 2016-09-23 15:03:41 +02:00
parent e59ed6451f
commit 08f5681b0e
5 changed files with 13 additions and 16 deletions

View file

@ -144,9 +144,9 @@ GPtrArray *_nm_utils_copy_array (const GPtrArray *array,
GDestroyNotify free_func);
GPtrArray *_nm_utils_copy_object_array (const GPtrArray *array);
gssize _nm_utils_ptrarray_find_first (gpointer *list, gssize len, gconstpointer needle);
gssize _nm_utils_ptrarray_find_first (gconstpointer *list, gssize len, gconstpointer needle);
gssize _nm_utils_ptrarray_find_binary_search (gpointer *list, gsize len, gpointer needle, GCompareDataFunc cmpfcn, gpointer user_data);
gssize _nm_utils_ptrarray_find_binary_search (gconstpointer *list, gsize len, gconstpointer needle, GCompareDataFunc cmpfcn, gpointer user_data);
gssize _nm_utils_strv_find_first (char **list, gssize len, const char *needle);

View file

@ -667,10 +667,8 @@ _nm_utils_copy_object_array (const GPtrArray *array)
return _nm_utils_copy_array (array, g_object_ref, g_object_unref);
}
/* have @list of type 'gpointer *' instead of 'gconstpointer *' to
* reduce the necessity for annoying const-casts. */
gssize
_nm_utils_ptrarray_find_first (gpointer *list, gssize len, gconstpointer needle)
_nm_utils_ptrarray_find_first (gconstpointer *list, gssize len, gconstpointer needle)
{
gssize i;
@ -694,7 +692,7 @@ _nm_utils_ptrarray_find_first (gpointer *list, gssize len, gconstpointer needle)
}
gssize
_nm_utils_ptrarray_find_binary_search (gpointer *list, gsize len, gpointer needle, GCompareDataFunc cmpfcn, gpointer user_data)
_nm_utils_ptrarray_find_binary_search (gconstpointer *list, gsize len, gconstpointer needle, GCompareDataFunc cmpfcn, gpointer user_data)
{
gssize imin, imax, imid;
int cmp;

View file

@ -4960,9 +4960,9 @@ _test_find_binary_search_do (const int *array, gsize len)
{
gsize i;
gssize idx;
gs_free gpointer *parray = g_new (gpointer, len);
const int needle = 0;
gpointer pneedle = GINT_TO_POINTER (needle);
gs_free gconstpointer *parray = g_new (gconstpointer, len);
const int NEEDLE = 0;
gconstpointer pneedle = GINT_TO_POINTER (NEEDLE);
gssize expected_result;
for (i = 0; i < len; i++)
@ -5008,14 +5008,13 @@ _test_find_binary_search_do (const int *array, gsize len)
}
#define test_find_binary_search_do(...) \
G_STMT_START { \
const int _array[] = { __VA_ARGS__ } ; \
const int _array[] = { __VA_ARGS__ }; \
_test_find_binary_search_do (_array, G_N_ELEMENTS (_array)); \
} G_STMT_END
static void
test_nm_utils_ptrarray_find_binary_search (void)
{
#define _NOT(idx) (~ ((gssize) (idx)))
test_find_binary_search_do ( 0);
test_find_binary_search_do ( -1, 0);
test_find_binary_search_do ( -2, -1, 0);

View file

@ -296,7 +296,7 @@ _route_index_find (const VTableIP *vtable, const RouteIndex *index, const NMPlat
{
gssize idx, idx2;
idx = _nm_utils_ptrarray_find_binary_search ((gpointer *) index->entries, index->len, (gpointer) needle, (GCompareDataFunc) _vx_route_id_cmp_full, (gpointer) vtable);
idx = _nm_utils_ptrarray_find_binary_search ((gconstpointer *) index->entries, index->len, needle, (GCompareDataFunc) _vx_route_id_cmp_full, (gpointer) vtable);
if (idx < 0)
return idx;

View file

@ -3028,7 +3028,7 @@ delayed_action_handle_one (NMPlatform *platform)
g_ptr_array_remove_index_fast (priv->delayed_action.list_master_connected, 0);
if (priv->delayed_action.list_master_connected->len == 0)
priv->delayed_action.flags &= ~DELAYED_ACTION_TYPE_MASTER_CONNECTED;
nm_assert (_nm_utils_ptrarray_find_first (priv->delayed_action.list_master_connected->pdata, priv->delayed_action.list_master_connected->len, user_data) < 0);
nm_assert (_nm_utils_ptrarray_find_first ((gconstpointer *) priv->delayed_action.list_master_connected->pdata, priv->delayed_action.list_master_connected->len, user_data) < 0);
_LOGt_delayed_action (DELAYED_ACTION_TYPE_MASTER_CONNECTED, user_data, "handle");
delayed_action_handle_MASTER_CONNECTED (platform, GPOINTER_TO_INT (user_data));
@ -3069,7 +3069,7 @@ delayed_action_handle_one (NMPlatform *platform)
g_ptr_array_remove_index_fast (priv->delayed_action.list_refresh_link, 0);
if (priv->delayed_action.list_refresh_link->len == 0)
priv->delayed_action.flags &= ~DELAYED_ACTION_TYPE_REFRESH_LINK;
nm_assert (_nm_utils_ptrarray_find_first (priv->delayed_action.list_refresh_link->pdata, priv->delayed_action.list_refresh_link->len, user_data) < 0);
nm_assert (_nm_utils_ptrarray_find_first ((gconstpointer *) priv->delayed_action.list_refresh_link->pdata, priv->delayed_action.list_refresh_link->len, user_data) < 0);
_LOGt_delayed_action (DELAYED_ACTION_TYPE_REFRESH_LINK, user_data, "handle");
@ -3118,11 +3118,11 @@ delayed_action_schedule (NMPlatform *platform, DelayedActionType action_type, gp
switch (action_type) {
case DELAYED_ACTION_TYPE_REFRESH_LINK:
if (_nm_utils_ptrarray_find_first (priv->delayed_action.list_refresh_link->pdata, priv->delayed_action.list_refresh_link->len, user_data) < 0)
if (_nm_utils_ptrarray_find_first ((gconstpointer *) priv->delayed_action.list_refresh_link->pdata, priv->delayed_action.list_refresh_link->len, user_data) < 0)
g_ptr_array_add (priv->delayed_action.list_refresh_link, user_data);
break;
case DELAYED_ACTION_TYPE_MASTER_CONNECTED:
if (_nm_utils_ptrarray_find_first (priv->delayed_action.list_master_connected->pdata, priv->delayed_action.list_master_connected->len, user_data) < 0)
if (_nm_utils_ptrarray_find_first ((gconstpointer *) priv->delayed_action.list_master_connected->pdata, priv->delayed_action.list_master_connected->len, user_data) < 0)
g_ptr_array_add (priv->delayed_action.list_master_connected, user_data);
break;
case DELAYED_ACTION_TYPE_WAIT_FOR_NL_RESPONSE: