diff --git a/.github/workflows/vs16-arm-ci.yml b/.github/workflows/vs16-arm-ci.yml deleted file mode 100644 index f03caae40..000000000 --- a/.github/workflows/vs16-arm-ci.yml +++ /dev/null @@ -1,28 +0,0 @@ -name: VS16-ARM-CI - -on: [push, pull_request] - -permissions: - contents: read - -jobs: - ci: - name: windows-vs16 - runs-on: windows-2019 - strategy: - fail-fast: false - matrix: - include: - - {gen: Visual Studio 16 2019, arch: ARM} - - {gen: Visual Studio 16 2019, arch: ARM64} - steps: - - name: checkout - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - - name: Configure - run: | - mkdir build - cd build && cmake -G "${{matrix.gen}}" -A ${{matrix.arch}} .. - - name: Build - run: cmake --build build --config Release - - name: Build Debug - run: cmake --build build --config Debug \ No newline at end of file diff --git a/.github/workflows/vs16-ci.yml b/.github/workflows/vs16-ci.yml deleted file mode 100644 index 33b1cdfc8..000000000 --- a/.github/workflows/vs16-ci.yml +++ /dev/null @@ -1,36 +0,0 @@ -name: VS16-CI - -on: [push, pull_request] - -permissions: - contents: read - -jobs: - ci: - name: windows-vs16 - runs-on: windows-2019 - strategy: - fail-fast: false - matrix: - include: - - {gen: Visual Studio 16 2019, arch: Win32} - - {gen: Visual Studio 16 2019, arch: x64} - steps: - - name: checkout - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - - name: Configure - run: | - mkdir build - cd build && cmake -DENABLE_ROARING_TESTS=ON -G "${{matrix.gen}}" -A ${{matrix.arch}} .. - - name: Build - run: cmake --build build --config Release - - name: Run basic tests - run: | - cd build - ctest -C Release --output-on-failure - - name: Build Debug - run: cmake --build build --config Debug - - name: Run basic tests in Debug - run: | - cd build - ctest -C Debug --output-on-failure \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index ce31c0294..828a6969c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,9 @@ project(RoaringBitmap DESCRIPTION "Roaring bitmaps in C (and C++)" LANGUAGES CXX C ) +set (CMAKE_C_STANDARD 11) +set (CMAKE_CXX_STANDARD 11) + include(GNUInstallDirs) if (NOT CMAKE_BUILD_TYPE) @@ -110,6 +113,51 @@ if(ENABLE_ROARING_TESTS) endif() add_subdirectory(tests) endif() +find_program(BASH bash) + +if(ENABLE_ROARING_TESTS AND BASH) + message(STATUS "Amalgamation tests enabled") + set(CROARING_SINGLEHEADER_FILES + ${CMAKE_CURRENT_BINARY_DIR}/amalgamation_demo.c + ${CMAKE_CURRENT_BINARY_DIR}/amalgamation_demo.cpp + ${CMAKE_CURRENT_BINARY_DIR}/roaring.c + ${CMAKE_CURRENT_BINARY_DIR}/roaring.h + ${CMAKE_CURRENT_BINARY_DIR}/roaring.hh + ) + set_source_files_properties(${CROARING_SINGLEHEADER_FILES} PROPERTIES GENERATED TRUE) + + add_custom_command( + OUTPUT ${CROARING_SINGLEHEADER_FILES} + COMMAND ${BASH} ${CMAKE_CURRENT_SOURCE_DIR}/amalgamation.sh ${CMAKE_CURRENT_BINARY_DIR} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/amalgamation.sh roaring + ) + set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/amalgamation_demo.c PROPERTIES LANGUAGE C CMAKE_C_STANDARD 11) + set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/amalgamation_demo.cpp PROPERTIES LANGUAGE CXX CXX_STANDARD 11) + add_custom_target(croaring-singleheader-files DEPENDS ${CROARING_SINGLEHEADER_FILES}) + + add_library(croaring-singleheader-include-source INTERFACE) + target_include_directories(croaring-singleheader-include-source INTERFACE $) + add_dependencies(croaring-singleheader-include-source croaring-singleheader-files) + + add_executable(amalgamate_demo $) + target_link_libraries(amalgamate_demo croaring-singleheader-include-source) + add_test(amalgamate_demo amalgamate_demo) + + add_library(croaring-singleheader-source-lib $) + target_include_directories(croaring-singleheader-source-lib PUBLIC $) + + add_executable(amalgamate_demo_cpp $) + target_link_libraries(amalgamate_demo_cpp croaring-singleheader-include-source croaring-singleheader-source-lib) + if(ROARING_EXCEPTIONS) + target_compile_definitions(amalgamate_demo_cpp PUBLIC ROARING_EXCEPTIONS=1) + else() + target_compile_definitions(amalgamate_demo_cpp PUBLIC ROARING_EXCEPTIONS=0) + endif() + add_test(amalgamate_demo_cpp amalgamate_demo_cpp) +else() + message(STATUS "Amalgamation tests disabled") +endif() option(ENABLE_ROARING_MICROBENCHMARKS "Enable microbenchmarks" OFF) if(ENABLE_ROARING_MICROBENCHMARKS) add_subdirectory(microbenchmarks) diff --git a/amalgamation.sh b/amalgamation.sh index ca12b6102..c17524aaf 100755 --- a/amalgamation.sh +++ b/amalgamation.sh @@ -5,6 +5,8 @@ ######################################################################## SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )" +DESTINATION=${1:-.} + case $SCRIPTPATH in (*\ *) echo "Path ($SCRIPTPATH) cannot contain whitespace"; exit 1 ;; esac @@ -141,7 +143,7 @@ echo "Creating ${AMAL_H}..." for h in ${ALL_PUBLIC_H}; do dofile $h done -} > "${AMAL_H}" +} > "${DESTINATION}/${AMAL_H}" echo "Creating ${AMAL_C}..." @@ -163,7 +165,7 @@ echo "Creating ${AMAL_C}..." for h in ${ALL_PRIVATE_H} ${ALL_PRIVATE_C}; do dofile $h done -} > "${AMAL_C}" +} > "${DESTINATION}/${AMAL_C}" echo "Creating ${DEMOC}..." @@ -174,6 +176,25 @@ echo "Creating ${DEMOC}..." #include #include #include "roaring.c" + + +static inline void or_many(void) { + roaring_bitmap_t *r1 = roaring_bitmap_from(500, 1000); + roaring_bitmap_t *r2 = roaring_bitmap_from(1000, 2000); + + const roaring_bitmap_t *bitmap_arr[2] = {r1, r2}; + fprintf(stderr, "Going to or many\n"); + for (int i = 0; i < 10000; i++) { + roaring_bitmap_t *r = roaring_bitmap_or_many(2, bitmap_arr); + roaring_bitmap_free(r); + } + + fprintf(stderr, "Got done\n"); + + roaring_bitmap_free(r2); + roaring_bitmap_free(r1); +} + int main() { roaring_bitmap_t *r1 = roaring_bitmap_create(); for (uint32_t i = 100; i < 1000; i++) roaring_bitmap_add(r1, i); @@ -191,10 +212,11 @@ int main() { } printf("%zu \n", bitset_count(b)); bitset_free(b); + or_many(); return EXIT_SUCCESS; } ' -} > "${DEMOC}" +} > "${DESTINATION}/${DEMOC}" echo "Creating ${AMAL_HH}..." @@ -218,7 +240,7 @@ echo "Creating ${AMAL_HH}..." for hh in ${ALL_PUBLIC_HH}; do dofile $hh done -} > "${AMAL_HH}" +} > "${DESTINATION}/${AMAL_HH}" echo "Creating ${DEMOCPP}..." @@ -229,7 +251,8 @@ echo "Creating ${DEMOCPP}..." cat <<< ' #include #include "roaring.hh" -#include "roaring.c" +//#include "roaring.c" + int main() { roaring::Roaring r1; for (uint32_t i = 100; i < 1000; i++) { @@ -245,14 +268,14 @@ int main() { return 0; } ' -} > "${DEMOCPP}" +} > "${DESTINATION}/${DEMOCPP}" # Print out a directory listing of the output files and their sizes # newline -echo "Files have been written to current directory: $PWD " -ls -la ${AMAL_C} ${AMAL_H} ${AMAL_HH} ${DEMOC} ${DEMOCPP} +echo "Files have been written to ${DESTINATION} " +ls -la ${DESTINATION}/${AMAL_C} ${DESTINATION}/${AMAL_H} ${DESTINATION}/${AMAL_HH} ${DESTINATION}/${DEMOC} ${DESTINATION}/${DEMOCPP} newline CBIN=${DEMOC%%.*} @@ -260,11 +283,12 @@ CPPBIN=${DEMOCPP%%.*} echo "The interface is found in the file 'include/roaring/roaring.h'." newline +echo "Go to ${DESTINATION}/." echo "For C, try:" echo "cc -O3 -std=c11 -o ${CBIN} ${DEMOC} && ./${CBIN} " newline echo "For C++, try:" -echo "c++ -O3 -std=c++11 -o ${CPPBIN} ${DEMOCPP} && ./${CPPBIN} " +echo "c++ -O3 -std=c++11 -o ${CPPBIN} ${DEMOCPP} ${AMAL_C} && ./${CPPBIN} " lowercase(){ echo "$1" | tr 'A-Z' 'a-z' diff --git a/benchmarks/adversarialunions_benchmark.c b/benchmarks/adversarialunions_benchmark.c index 5c0d620d2..3a2e27b84 100644 --- a/benchmarks/adversarialunions_benchmark.c +++ b/benchmarks/adversarialunions_benchmark.c @@ -2,7 +2,7 @@ #include #include #include "benchmark.h" -int quickfull() { +static inline int quickfull() { printf("The naive approach works well when the bitmaps quickly become full\n"); uint64_t cycles_start, cycles_final; size_t bitmapcount = 100; @@ -47,7 +47,7 @@ int quickfull() { return 0; } -int notsofull() { +static inline int notsofull() { printf("The naive approach works less well when the bitmaps do not quickly become full\n"); uint64_t cycles_start, cycles_final; size_t bitmapcount = 100; diff --git a/benchmarks/equals_benchmark.c b/benchmarks/equals_benchmark.c index 6aebce08c..84bee85dc 100644 --- a/benchmarks/equals_benchmark.c +++ b/benchmarks/equals_benchmark.c @@ -8,9 +8,9 @@ #include "benchmark.h" #include "random.h" -int32_t array_container_get_nruns(const array_container_t *c) { (void) c; return -1; } -int32_t bitset_container_get_nruns(const bitset_container_t *c) { (void) c; return -1; } -int32_t run_container_get_nruns(const run_container_t *c) { return c->n_runs; } +static inline int32_t array_container_get_nruns(const array_container_t *c) { (void) c; return -1; } +static inline int32_t bitset_container_get_nruns(const bitset_container_t *c) { (void) c; return -1; } +static inline int32_t run_container_get_nruns(const run_container_t *c) { return c->n_runs; } #define BENCHMARK_CONTAINER(cname1, cname2, fname, n) \ { \ diff --git a/benchmarks/run_container_benchmark.c b/benchmarks/run_container_benchmark.c index e2fdc495a..7401027e4 100644 --- a/benchmarks/run_container_benchmark.c +++ b/benchmarks/run_container_benchmark.c @@ -8,7 +8,7 @@ enum { TESTSIZE = 2048 }; #if defined(CROARING_IS_X64) && !(defined(_MSC_VER) && !defined(__clang__)) // flushes the array from cache -void run_cache_flush(run_container_t* B) { +static inline void run_cache_flush(run_container_t* B) { const int32_t CACHELINESIZE = computecacheline(); // 64 bytes per cache line for (int32_t k = 0; k < B->n_runs * 2; @@ -17,11 +17,11 @@ void run_cache_flush(run_container_t* B) { } } #else -void run_cache_flush(run_container_t* B) { (void)B; } +static inline void run_cache_flush(run_container_t* B) { (void)B; } #endif // tries to put array in cache -void run_cache_prefetch(run_container_t* B) { +static inline void run_cache_prefetch(run_container_t* B) { #if !CROARING_REGULAR_VISUAL_STUDIO #if CROARING_IS_X64 const int32_t CACHELINESIZE = @@ -36,7 +36,7 @@ void run_cache_prefetch(run_container_t* B) { #endif // !CROARING_REGULAR_VISUAL_STUDIO } -int add_test(run_container_t* B) { +static inline int add_test(run_container_t* B) { int x; for (x = 0; x < (1 << 16); x += 3) { run_container_add(B, (uint16_t)x); @@ -44,7 +44,7 @@ int add_test(run_container_t* B) { return 0; } -int remove_test(run_container_t* B) { +static inline int remove_test(run_container_t* B) { int x; for (x = 0; x < (1 << 16); x += 3) { run_container_remove(B, (uint16_t)x); @@ -52,7 +52,7 @@ int remove_test(run_container_t* B) { return 0; } -int contains_test(run_container_t* B) { +static inline int contains_test(run_container_t* B) { int card = 0; int x; for (x = 0; x < (1 << 16); x++) { @@ -61,12 +61,12 @@ int contains_test(run_container_t* B) { return card; } -int union_test(run_container_t* B1, run_container_t* B2, run_container_t* BO) { +static inline int union_test(run_container_t* B1, run_container_t* B2, run_container_t* BO) { run_container_union(B1, B2, BO); return run_container_cardinality(BO); } -int intersection_test(run_container_t* B1, run_container_t* B2, +static inline int intersection_test(run_container_t* B1, run_container_t* B2, run_container_t* BO) { run_container_intersection(B1, B2, BO); return run_container_cardinality(BO); diff --git a/include/roaring/array_util.h b/include/roaring/array_util.h index d9baa2b3b..7d04a5c85 100644 --- a/include/roaring/array_util.h +++ b/include/roaring/array_util.h @@ -11,7 +11,11 @@ #error "CROARING_COMPILER_SUPPORTS_AVX512 needs to be defined." #endif // CROARING_COMPILER_SUPPORTS_AVX512 #endif - +#if defined(__GNUC__) && !defined(__clang__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wuninitialized" +#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" +#endif #ifdef __cplusplus extern "C" { namespace roaring { namespace internal { #endif @@ -259,5 +263,7 @@ bool memequals(const void *s1, const void *s2, size_t n); #ifdef __cplusplus } } } // extern "C" { namespace roaring { namespace internal { #endif - +#if defined(__GNUC__) && !defined(__clang__) +#pragma GCC diagnostic pop +#endif #endif diff --git a/include/roaring/bitset_util.h b/include/roaring/bitset_util.h index 32bc6798a..ac0c09e02 100644 --- a/include/roaring/bitset_util.h +++ b/include/roaring/bitset_util.h @@ -11,7 +11,11 @@ #error "CROARING_COMPILER_SUPPORTS_AVX512 needs to be defined." #endif // CROARING_COMPILER_SUPPORTS_AVX512 #endif - +#if defined(__GNUC__) && !defined(__clang__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wuninitialized" +#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" +#endif #ifdef __cplusplus extern "C" { namespace roaring { namespace internal { #endif @@ -710,5 +714,7 @@ CROARING_UNTARGET_AVX512 #ifdef __cplusplus } } } // extern "C" { namespace roaring { namespace internal #endif - +#if defined(__GNUC__) && !defined(__clang__) +#pragma GCC diagnostic pop +#endif #endif diff --git a/microbenchmarks/bench.h b/microbenchmarks/bench.h index 20904abac..b691d4744 100644 --- a/microbenchmarks/bench.h +++ b/microbenchmarks/bench.h @@ -26,7 +26,11 @@ #error "CROARING_COMPILER_SUPPORTS_AVX512 needs to be defined." #endif // CROARING_COMPILER_SUPPORTS_AVX512 #endif - +#if defined(__GNUC__) && !defined(__clang__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wuninitialized" +#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" +#endif using roaring::Roaring64Map; event_collector collector; @@ -305,5 +309,7 @@ int load(const char *dirname) { if (bitmaps == NULL) return -1; return count; } - #endif +#if defined(__GNUC__) && !defined(__clang__) +#pragma GCC diagnostic pop +#endif \ No newline at end of file diff --git a/src/array_util.c b/src/array_util.c index cddd27fb2..311bd7299 100644 --- a/src/array_util.c +++ b/src/array_util.c @@ -15,6 +15,11 @@ #endif // CROARING_COMPILER_SUPPORTS_AVX512 #endif +#if defined(__GNUC__) && !defined(__clang__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wuninitialized" +#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" +#endif #ifdef __cplusplus using namespace ::roaring::internal; extern "C" { namespace roaring { namespace internal { @@ -2168,3 +2173,6 @@ CROARING_UNTARGET_AVX512 #ifdef __cplusplus } } } // extern "C" { namespace roaring { namespace internal { #endif +#if defined(__GNUC__) && !defined(__clang__) +#pragma GCC diagnostic pop +#endif \ No newline at end of file diff --git a/src/bitset_util.c b/src/bitset_util.c index 3a22e6c03..45b5d2332 100644 --- a/src/bitset_util.c +++ b/src/bitset_util.c @@ -11,7 +11,11 @@ #error "CROARING_COMPILER_SUPPORTS_AVX512 needs to be defined." #endif // CROARING_COMPILER_SUPPORTS_AVX512 #endif - +#if defined(__GNUC__) && !defined(__clang__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wuninitialized" +#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" +#endif #ifdef __cplusplus using namespace ::roaring::internal; extern "C" { namespace roaring { namespace api { @@ -1126,3 +1130,6 @@ void bitset_flip_list(uint64_t *words, const uint16_t *list, uint64_t length) { #ifdef __cplusplus } } } // extern "C" { namespace roaring { namespace api { #endif +#if defined(__GNUC__) && !defined(__clang__) +#pragma GCC diagnostic pop +#endif \ No newline at end of file diff --git a/src/containers/bitset.c b/src/containers/bitset.c index 6e0f871e5..e2ccb0ae3 100644 --- a/src/containers/bitset.c +++ b/src/containers/bitset.c @@ -23,6 +23,11 @@ #endif // CROARING_COMPILER_SUPPORTS_AVX512 #endif +#if defined(__GNUC__) && !defined(__clang__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wuninitialized" +#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" +#endif #ifdef __cplusplus extern "C" { namespace roaring { namespace internal { #endif @@ -1298,3 +1303,6 @@ int bitset_container_index_equalorlarger(const bitset_container_t *container, ui #ifdef __cplusplus } } } // extern "C" { namespace roaring { namespace internal { #endif +#if defined(__GNUC__) && !defined(__clang__) +#pragma GCC diagnostic pop +#endif \ No newline at end of file diff --git a/src/containers/run.c b/src/containers/run.c index 8321c0d11..a6c36f4c0 100644 --- a/src/containers/run.c +++ b/src/containers/run.c @@ -10,7 +10,11 @@ #error "CROARING_COMPILER_SUPPORTS_AVX512 needs to be defined." #endif // CROARING_COMPILER_SUPPORTS_AVX512 #endif - +#if defined(__GNUC__) && !defined(__clang__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wuninitialized" +#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" +#endif #ifdef __cplusplus extern "C" { namespace roaring { namespace internal { #endif @@ -1065,3 +1069,6 @@ int run_container_cardinality(const run_container_t *run) { #ifdef __cplusplus } } } // extern "C" { namespace roaring { namespace internal { #endif +#if defined(__GNUC__) && !defined(__clang__) +#pragma GCC diagnostic pop +#endif \ No newline at end of file diff --git a/tests/format_portability_unit.c b/tests/format_portability_unit.c index a823a9b64..22d4fc004 100644 --- a/tests/format_portability_unit.c +++ b/tests/format_portability_unit.c @@ -16,7 +16,7 @@ #include "test.h" -long filesize(char const* path) { +static inline long filesize(char const* path) { FILE* fp = fopen(path, "rb"); assert_non_null(fp); @@ -25,7 +25,7 @@ long filesize(char const* path) { return ftell(fp); } -char* readfile(char const* path) { +static inline char* readfile(char const* path) { FILE* fp = fopen(path, "rb"); assert_non_null(fp); @@ -42,7 +42,7 @@ char* readfile(char const* path) { return buf; } -int compare(char* x, char* y, size_t size) { +static inline int compare(char* x, char* y, size_t size) { for (size_t i = 0; i < size; ++i) { if (x[i] != y[i]) { return i + 1; @@ -51,7 +51,7 @@ int compare(char* x, char* y, size_t size) { return 0; } -void test_deserialize(char* filename) { +static inline void test_deserialize(char* filename) { char* input_buffer = readfile(filename); assert_non_null(input_buffer); diff --git a/tools/cmake/FindCTargets.cmake b/tools/cmake/FindCTargets.cmake index 243cc848a..3218aab10 100644 --- a/tools/cmake/FindCTargets.cmake +++ b/tools/cmake/FindCTargets.cmake @@ -1,6 +1,3 @@ -if (CMAKE_VERSION VERSION_GREATER 3.0.0) - cmake_policy(VERSION 3.0.0) -endif () include(${PROJECT_SOURCE_DIR}/tools/cmake/Import.cmake) set(BUILD_STATIC_LIB ON) if (ENABLE_ROARING_TESTS) diff --git a/tools/cmake/FindOptions.cmake b/tools/cmake/FindOptions.cmake index f7b8f9675..095031986 100644 --- a/tools/cmake/FindOptions.cmake +++ b/tools/cmake/FindOptions.cmake @@ -34,13 +34,12 @@ endif() endif() if(NOT MSVC) -set(STD_FLAGS "-std=c11 -fPIC") -set(CXXSTD_FLAGS "-std=c++11 -fPIC") -endif() - set(WARNING_FLAGS "-Wall") -if(NOT MSVC) -set(WARNING_FLAGS "${WARNING_FLAGS} -Wextra -Wsign-compare -Wshadow -Wwrite-strings -Wpointer-arith -Winit-self") +if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") +set(WARNING_FLAGS "${WARNING_FLAGS} -Wmissing-braces -Wextra -Wsign-compare -Wshadow -Wwrite-strings -Wpointer-arith -Winit-self") +elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") +set(WARNING_FLAGS "${WARNING_FLAGS} -Wextra -Wsign-compare -Wshadow -Wwrite-strings -Wpointer-arith -Winit-self -Wcast-align") +endif() endif() set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${STD_FLAGS} ${OPT_FLAGS} ${INCLUDE_FLAGS} ${WARNING_FLAGS} ${ROARING_SANITIZE_FLAGS} ")