Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix casting warnings identified with -Wcast-qual flag #482

Merged
merged 1 commit into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading