Skip to content

Commit

Permalink
Fix casting for GCC 14+. Fixes #21
Browse files Browse the repository at this point in the history
  • Loading branch information
TomTheBear committed Oct 16, 2024
1 parent 1741d35 commit 8e9f696
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions cachesim/backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -1179,7 +1179,7 @@ Cache* get_cacheSim_from_file(const char* cache_file)
if (line[0] != '\n' && line[0] != '\r' && line[0] != '#')
{
cacheSim[counter] = (Cache*) calloc(1, sizeof(Cache));
if (&cacheSim[counter] == NULL)
if (cacheSim[counter] == NULL)
{
fprintf(file, "allocation of memory for cache object failed\n");
fflush(file);
Expand Down Expand Up @@ -1358,6 +1358,9 @@ Cache* get_cacheSim_from_file(const char* cache_file)

}

#ifndef NO_PYTHON
#define CAST_CACHE_SIM_TO_PYOBJ (PyObject*)
#endif
//link caches
fputs("\nlink caches:\n",file);
fflush(file);
Expand All @@ -1370,17 +1373,17 @@ Cache* get_cacheSim_from_file(const char* cache_file)
if(cacheSim[j]->name != NULL){
if (load_from_buff[i] != NULL && strcmp(load_from_buff[i], cacheSim[j]->name) == 0)
{
cacheSim[i]->load_from = cacheSim[j];
cacheSim[i]->load_from = CAST_CACHE_SIM_TO_PYOBJ cacheSim[j];
++linkcounter[j];
}
if (store_to_buff[i] != NULL && strcmp(store_to_buff[i], cacheSim[j]->name) == 0)
{
cacheSim[i]->store_to = cacheSim[j];
cacheSim[i]->store_to = CAST_CACHE_SIM_TO_PYOBJ cacheSim[j];
++linkcounter[j];
}
if (victims_to_buff[i] != NULL && strcmp(victims_to_buff[i], cacheSim[j]->name) == 0)
{
cacheSim[i]->victims_to = cacheSim[j];
cacheSim[i]->victims_to = CAST_CACHE_SIM_TO_PYOBJ cacheSim[j];
++linkcounter[j];
}
}
Expand Down Expand Up @@ -1434,6 +1437,9 @@ Cache* get_cacheSim_from_file(const char* cache_file)

//has to be left out when using pin, as stdout for some reason cannot be linked in this case
#ifndef USE_PIN
#ifndef NO_PYTHON
#define CAST_PYOBJ_TO_CACHE (Cache*)
#endif
void printStats(Cache* cache)
{
fprintf(stdout, "%s:\n",cache->name);
Expand All @@ -1444,10 +1450,10 @@ void printStats(Cache* cache)
fprintf(stdout, "EVICT: %llu size: %lluB\n",cache->EVICT.count, cache->EVICT.byte);

if (cache->load_from != NULL)
printStats(cache->load_from);
printStats(CAST_PYOBJ_TO_CACHE cache->load_from);
if (cache->store_to != NULL && cache->store_to != cache->load_from)
printStats(cache->store_to);
printStats(CAST_PYOBJ_TO_CACHE cache->store_to);
if (cache->victims_to != NULL && cache->store_to != cache->load_from && cache->store_to != cache->victims_to)
printStats(cache->victims_to);
printStats(CAST_PYOBJ_TO_CACHE cache->victims_to);
}
#endif

0 comments on commit 8e9f696

Please sign in to comment.