From 4eed309f00d678d2aeb48f73061a4be7b8457e87 Mon Sep 17 00:00:00 2001 From: Steven Roberts Date: Thu, 16 May 2024 07:24:48 -0700 Subject: [PATCH] Fix casting warnings identified with -Wcast-qual flag (#482) --- src/sundials/sundials_hashmap.c | 12 +++++++----- src/sundials/sundials_hashmap_impl.h | 3 ++- src/sundials/sundials_profiler.c | 4 ++-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/sundials/sundials_hashmap.c b/src/sundials/sundials_hashmap.c index 55c786b34f..a2a2fc3764 100644 --- a/src/sundials/sundials_hashmap.c +++ b/src/sundials/sundials_hashmap.c @@ -140,7 +140,8 @@ SUNErrCode SUNHashMap_Destroy(SUNHashMap* map, void (*freevalue)(void* ptr)) * ``<-1`` -- an error occurred */ int SUNHashMap_Iterate(SUNHashMap map, int start, - int (*yieldfn)(int, SUNHashMapKeyValue, void*), void* ctx) + int (*yieldfn)(int, SUNHashMapKeyValue, const void*), + const void* ctx) { int i; @@ -159,7 +160,8 @@ int SUNHashMap_Iterate(SUNHashMap map, int start, return (map->max_size); } -static int sunHashMapLinearProbeInsert(int idx, SUNHashMapKeyValue kv, void* ctx) +static int sunHashMapLinearProbeInsert(int idx, SUNHashMapKeyValue kv, + const void* ctx) { /* find the next open spot */ if (kv == NULL) { return (idx); /* open spot found at idx */ } @@ -216,7 +218,8 @@ int SUNHashMap_Insert(SUNHashMap map, const char* key, void* value) return (0); } -static int sunHashMapLinearProbeGet(int idx, SUNHashMapKeyValue kv, void* key) +static int sunHashMapLinearProbeGet(int idx, SUNHashMapKeyValue kv, + const void* key) { /* target key cannot be NULL */ if (key == NULL) { return (-2); } @@ -260,8 +263,7 @@ int SUNHashMap_GetValue(SUNHashMap map, const char* key, void** value) if (strcmp(map->buckets[idx]->key, key)) { /* Keys did not match, so we have a collision and need to probe */ - retval = SUNHashMap_Iterate(map, idx + 1, sunHashMapLinearProbeGet, - (void*)key); + retval = SUNHashMap_Iterate(map, idx + 1, sunHashMapLinearProbeGet, key); if (retval < 0) { return (-1); /* error occurred */ } if (retval == map->max_size) { return (-2); /* not found */ } } diff --git a/src/sundials/sundials_hashmap_impl.h b/src/sundials/sundials_hashmap_impl.h index 7fc743a2f3..235947ed71 100644 --- a/src/sundials/sundials_hashmap_impl.h +++ b/src/sundials/sundials_hashmap_impl.h @@ -43,7 +43,8 @@ struct SUNHashMap_ SUNErrCode SUNHashMap_New(int max_size, SUNHashMap* map); SUNErrCode SUNHashMap_Destroy(SUNHashMap* map, void (*freevalue)(void* ptr)); int SUNHashMap_Iterate(SUNHashMap map, int start, - int (*yieldfn)(int, SUNHashMapKeyValue, void*), void* ctx); + int (*yieldfn)(int, SUNHashMapKeyValue, const void*), + const void* ctx); int SUNHashMap_Insert(SUNHashMap map, const char* key, void* value); int SUNHashMap_GetValue(SUNHashMap map, const char* key, void** value); SUNErrCode SUNHashMap_Sort(SUNHashMap map, SUNHashMapKeyValue** sorted, diff --git a/src/sundials/sundials_profiler.c b/src/sundials/sundials_profiler.c index 4a2e12e783..1ac2b30aee 100644 --- a/src/sundials/sundials_profiler.c +++ b/src/sundials/sundials_profiler.c @@ -543,8 +543,8 @@ int sunCompareTimes(const void* l, const void* r) double left_max; double right_max; - const SUNHashMapKeyValue left = *((SUNHashMapKeyValue*)l); - const SUNHashMapKeyValue right = *((SUNHashMapKeyValue*)r); + const SUNHashMapKeyValue left = *((const SUNHashMapKeyValue*)l); + const SUNHashMapKeyValue right = *((const SUNHashMapKeyValue*)r); if (left == NULL && right == NULL) { return 0; } if (left == NULL) { return 1; }