Skip to content

Commit

Permalink
Fix a handful of compilation issues with older C standards (#480)
Browse files Browse the repository at this point in the history
* portability.h: include missing `<assert.h>`

The assertion added via 264b188 (Using atomic counters on shared
containers (#473), 2023-05-15) does not explicitly include <assert.h>
causing GCC to fail compilation when invoked with
`-Werror=implicit-function-declaration`.

In C++ this is OK, since there `assert()` refers to its macro
definition. But in C the only way to get `assert()` is by including
<assert.h>.

Signed-off-by: Taylor Blau <[email protected]>

* src: avoid old-style function declarations

A handful of functions with argument arity zero fail when the compiler
is invoked with `-Werror=old-style-definition`. Work around these by
explicitly declaring the parameter list as `void` to clarify that these
functions expect zero arguments.

Signed-off-by: Taylor Blau <[email protected]>

* roaring_array.h: declare `ra_get_container()`

This function dates all the way back to 3d12719 (some more untested
code, plus some files that had not been tracked hitherto, 2016-01-19),
but never had a prototype.

This causes compilers building with `-Werror=missing-prototypes` to fail
compilation. Declare a prototype for that function in the corresponding
header accordingly.

Signed-off-by: Taylor Blau <[email protected]>

* containers/bitset.h: declare `bitset_container_union_nocard()`

In a similar spirit as the previous commit, declare a function prototype
for `bitset_container_union_nocard()` which rounds out the existing set
of function prototypes for the macro expansion of:

    BITSET_CONTAINER_FN(union, |, _mm256_or_si256, vorrq_u64)

Signed-off-by: Taylor Blau <[email protected]>

* containers/bitset.h: declare `bitset_container_intersection_nocard()`

In a similar spirit as the previous commits, declare a function
prototype for `bitset_container_intersection_nocard()` which rounds out
the existing set of function prototypes for the macro expansion of:

    BITSET_CONTAINER_FN(intersection, &, _mm256_and_si256, vandq_u64)

Signed-off-by: Taylor Blau <[email protected]>

---------

Signed-off-by: Taylor Blau <[email protected]>
  • Loading branch information
ttaylorr authored May 23, 2023
1 parent 070f5ac commit 6db7fbc
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 12 deletions.
12 changes: 12 additions & 0 deletions include/roaring/containers/bitset.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,12 @@ int bitset_container_union(const bitset_container_t *src_1,
int bitset_container_union_justcard(const bitset_container_t *src_1,
const bitset_container_t *src_2);

/* Computes the union of bitsets `src_1' and `src_2' into `dst', but does
* not update the cardinality. Provided to optimize chained operations. */
int bitset_container_union_nocard(const bitset_container_t *src_1,
const bitset_container_t *src_2,
bitset_container_t *dst);

/* Computes the union of bitsets `src_1' and `src_2' into `dst', but does not
* update the cardinality. Provided to optimize chained operations. */
int bitset_container_or_nocard(const bitset_container_t *src_1,
Expand Down Expand Up @@ -332,6 +338,12 @@ int bitset_container_intersection(const bitset_container_t *src_1,
int bitset_container_intersection_justcard(const bitset_container_t *src_1,
const bitset_container_t *src_2);

/* Computes the intersection of bitsets `src_1' and `src_2' into `dst', but does
* not update the cardinality. Provided to optimize chained operations. */
int bitset_container_intersection_nocard(const bitset_container_t *src_1,
const bitset_container_t *src_2,
bitset_container_t *dst);

/* Computes the intersection of bitsets `src_1' and `src_2' into `dst', but does
* not update the cardinality. Provided to optimize chained operations. */
int bitset_container_and_nocard(const bitset_container_t *src_1,
Expand Down
2 changes: 1 addition & 1 deletion include/roaring/isadetection.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ enum {
ROARING_SUPPORTS_AVX2 = 1,
ROARING_SUPPORTS_AVX512 = 2,
};
int croaring_hardware_support();
int croaring_hardware_support(void);
#ifdef __cplusplus
} } } // extern "C" { namespace roaring { namespace internal {
#endif
Expand Down
1 change: 1 addition & 0 deletions include/roaring/portability.h
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@ static inline uint32_t croaring_refcount_get(croaring_refcount_t *val) {
return *val;
}
#elif CROARING_ATOMIC_IMPL == CROARING_ATOMIC_IMPL_NONE
#include <assert.h>
typedef uint32_t croaring_refcount_t;

static inline void croaring_refcount_inc(croaring_refcount_t *val) {
Expand Down
2 changes: 2 additions & 0 deletions include/roaring/roaring_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ inline void ra_set_container_at_index(
ra->typecodes[i] = typecode;
}

container_t *ra_get_container(roaring_array_t *ra, uint16_t x, uint8_t *typecode);

/**
* If needed, increase the capacity of the array so that it can fit k values
* (at
Expand Down
2 changes: 1 addition & 1 deletion src/bitset.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ extern "C" { namespace roaring { namespace internal {
#endif

/* Create a new bitset. Return NULL in case of failure. */
bitset_t *bitset_create() {
bitset_t *bitset_create(void) {
bitset_t *bitset = NULL;
/* Allocate the bitset itself. */
if ((bitset = (bitset_t *)roaring_malloc(sizeof(bitset_t))) == NULL) {
Expand Down
2 changes: 1 addition & 1 deletion src/containers/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ array_container_t *array_container_create_given_capacity(int32_t size) {
}

/* Create a new array. Return NULL in case of failure. */
array_container_t *array_container_create() {
array_container_t *array_container_create(void) {
return array_container_create_given_capacity(ARRAY_DEFAULT_INIT_SIZE);
}

Expand Down
18 changes: 9 additions & 9 deletions src/isadetection.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ static inline void cpuid(uint32_t *eax, uint32_t *ebx, uint32_t *ecx,
}


static inline uint64_t xgetbv() {
static inline uint64_t xgetbv(void) {
#if defined(_MSC_VER)
return _xgetbv(0);
#else
Expand All @@ -130,7 +130,7 @@ static inline uint64_t xgetbv() {
* *once* per compilation units. Normally, the CRoaring library is built
* as one compilation unit.
*/
static inline uint32_t dynamic_croaring_detect_supported_architectures() {
static inline uint32_t dynamic_croaring_detect_supported_architectures(void) {
uint32_t eax, ebx, ecx, edx;
uint32_t host_isa = 0x0;
// Can be found on Intel ISA Reference for CPUID
Expand Down Expand Up @@ -228,13 +228,13 @@ static inline uint32_t dynamic_croaring_detect_supported_architectures() {
#if defined(__x86_64__) || defined(_M_AMD64) // x64

#if CROARING_ATOMIC_IMPL == CROARING_ATOMIC_IMPL_CPP
static inline uint32_t croaring_detect_supported_architectures() {
static inline uint32_t croaring_detect_supported_architectures(void) {
// thread-safe as per the C++11 standard.
static uint32_t buffer = dynamic_croaring_detect_supported_architectures();
return buffer;
}
#elif CROARING_ATOMIC_IMPL == CROARING_ATOMIC_IMPL_C
static uint32_t croaring_detect_supported_architectures() {
static uint32_t croaring_detect_supported_architectures(void) {
// we use an atomic for thread safety
static _Atomic uint32_t buffer = CROARING_UNINITIALIZED;
if (buffer == CROARING_UNINITIALIZED) {
Expand All @@ -245,7 +245,7 @@ static uint32_t croaring_detect_supported_architectures() {
}
#else
// If we do not have atomics, we do the best we can.
static inline uint32_t croaring_detect_supported_architectures() {
static inline uint32_t croaring_detect_supported_architectures(void) {
static uint32_t buffer = CROARING_UNINITIALIZED;
if (buffer == CROARING_UNINITIALIZED) {
buffer = dynamic_croaring_detect_supported_architectures();
Expand All @@ -256,17 +256,17 @@ static inline uint32_t croaring_detect_supported_architectures() {

#ifdef ROARING_DISABLE_AVX

int croaring_hardware_support() {
int croaring_hardware_support(void) {
return 0;
}

#elif defined(__AVX512F__) && defined(__AVX512DQ__) && defined(__AVX512BW__) && defined(__AVX512VBMI2__) && defined(__AVX512BITALG__) && defined(__AVX512VPOPCNTDQ__)
int croaring_hardware_support() {
int croaring_hardware_support(void) {
return ROARING_SUPPORTS_AVX2 | ROARING_SUPPORTS_AVX512;
}
#elif defined(__AVX2__)

int croaring_hardware_support() {
int croaring_hardware_support(void) {
static int support = 0xFFFFFFF;
if(support == 0xFFFFFFF) {
bool avx512_support = false;
Expand All @@ -280,7 +280,7 @@ int croaring_hardware_support() {
}
#else

int croaring_hardware_support() {
int croaring_hardware_support(void) {
static int support = 0xFFFFFFF;
if(support == 0xFFFFFFF) {
bool has_avx2 = (croaring_detect_supported_architectures() & CROARING_AVX2) == CROARING_AVX2;
Expand Down

0 comments on commit 6db7fbc

Please sign in to comment.