Skip to content

Commit

Permalink
Fix casting warnings identified with -Wcast-qual flag (#482)
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven-Roberts authored and gardner48 committed Jun 20, 2024
1 parent 65d0b2b commit 4eed309
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
12 changes: 7 additions & 5 deletions src/sundials/sundials_hashmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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 */ }
Expand Down Expand Up @@ -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); }
Expand Down Expand Up @@ -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 */ }
}
Expand Down
3 changes: 2 additions & 1 deletion src/sundials/sundials_hashmap_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/sundials/sundials_profiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down

0 comments on commit 4eed309

Please sign in to comment.