3

I'm trying to build RedisBloom and after running the make command I get the following error.

clang -dynamic -fcommon -g -ggdb -Wall -Wno-unused-function -g -ggdb -O2 -fPIC -std=gnu99 -D_GNU_SOURCE -I/Users/john/workspace/RedisBloom/contrib -I/Users/john/workspace/RedisBloom -I/Users/john/workspace/RedisBloom/src -I/Users/john/workspace/RedisBloom/deps/t-digest-c/src  -c -o /Users/john/workspace/RedisBloom/src/topk.o /Users/john/workspace/RedisBloom/src/topk.c
/Users/john/workspace/RedisBloom/src/topk.c:223:50: error: use of undeclared identifier '__compar_fn_t'
    qsort(heapList, topk->k, sizeof(*heapList), (__compar_fn_t)cmpHeapBucket);
                                                 ^
1 error generated.
make: *** [/Users/dsesma/eclipse-workspace/RedisBloom/src/topk.o] Error 1

I'm using macOS Big Sur

dses
  • 85
  • 1
  • 5
  • 1
    there is a question about this particular error. https://stackoverflow.com/questions/2561697/warning-when-using-qsort-in-c , but unless you want to change the code yourself you may need to report a bug – Effie Sep 14 '21 at 21:04

1 Answers1

2

The RedisBloom project uses an implementation detail (__compar_fn_t) to cast the function signature of cmpHeapBucket from a shortcut-signature to the proper signature. Relying on such implementation details is bad and tends to not be very portable.

I recommend that you download the newest version of RedisBloom. I made a patch to it that has now been merged to master which does the following:

Fix in src/topk.c:

// make the compare function have the correct signature:
int cmpHeapBucket(const void *tmp1, const void *tmp2) {
    const HeapBucket *res1 = tmp1;
    const HeapBucket *res2 = tmp2;
    return res1->count < res2->count ? 1 : res1->count > res2->count ? -1 : 0;
}

HeapBucket *TopK_List(TopK *topk) {
    HeapBucket *heapList = TOPK_CALLOC(topk->k, (sizeof(*heapList)));
    memcpy(heapList, topk->heap, topk->k * sizeof(HeapBucket));

    //                      now, no cast is needed below:
    qsort(heapList, topk->k, sizeof(*heapList), cmpHeapBucket);
    return heapList;
}
Ted Lyngmo
  • 93,841
  • 5
  • 60
  • 108