diff --git a/libnm-core/nm-core-internal.h b/libnm-core/nm-core-internal.h index e491bce6da..111b26d588 100644 --- a/libnm-core/nm-core-internal.h +++ b/libnm-core/nm-core-internal.h @@ -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); diff --git a/libnm-core/nm-utils.c b/libnm-core/nm-utils.c index df75d56557..c55e4ba81f 100644 --- a/libnm-core/nm-utils.c +++ b/libnm-core/nm-utils.c @@ -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; diff --git a/libnm-core/tests/test-general.c b/libnm-core/tests/test-general.c index 5dfc897114..8d5997ad2c 100644 --- a/libnm-core/tests/test-general.c +++ b/libnm-core/tests/test-general.c @@ -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); diff --git a/src/nm-route-manager.c b/src/nm-route-manager.c index 2d4c7d9595..95113f8c84 100644 --- a/src/nm-route-manager.c +++ b/src/nm-route-manager.c @@ -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; diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c index c30eed9447..cedc220a75 100644 --- a/src/platform/nm-linux-platform.c +++ b/src/platform/nm-linux-platform.c @@ -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: