Error building project with make command, use of undeclared identifier '__compar_fn_t'

Viewed 296

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

1 Answers

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;
}
Related