From 86d86462b420f098ee34a022cffd922e3192dabe Mon Sep 17 00:00:00 2001 From: Mitya Selivanov Date: Sun, 1 Jan 2023 20:08:31 +0100 Subject: Remove ANSI C option; add pedantic gcc flag --- CMakeLists.txt | 10 ++++------ source/kit/CMakeLists.txt | 5 ++--- source/kit/async_function.h | 12 ++++++------ source/kit/lower_bound.c | 1 - source/kit/thread.posix.c | 11 ++++++----- source/kit/thread.win32.c | 11 ++++++----- source/test/unittests/async_function.test.c | 22 +++++++++++----------- 7 files changed, 35 insertions(+), 37 deletions(-) delete mode 100644 source/kit/lower_bound.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 33b42fe..770e79d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,16 +7,10 @@ if(NOT DEFINED CMAKE_BUILD_PARALLEL_LEVEL) endif() option(KIT_ENABLE_TESTING "Enable testing" ON) -option(KIT_FORCE_ANSI_C "Force ANSI C" ${KIT_ENABLE_TESTING}) option(KIT_DISABLE_SYSTEM_MALLOC "Disable system memory allocator" OFF) option(KIT_DISABLE_SYSTEM_THREADS "Disable system threads" OFF) -if(KIT_FORCE_ANSI_C) - set(CMAKE_C_STANDARD 90) - set(CMAKE_C_EXTENSIONS OFF) -endif() - project( kit VERSION 0.1.1 @@ -32,6 +26,10 @@ if(WIN32) target_link_libraries(kit PUBLIC Shlwapi) endif() +if(CMAKE_C_COMPILER_ID MATCHES "GNU|Clang") + target_compile_options(kit PUBLIC -pedantic -Wall -Werror) +endif() + include(CheckCSourceRuns) check_c_source_runs( diff --git a/source/kit/CMakeLists.txt b/source/kit/CMakeLists.txt index 101e2a8..4113668 100644 --- a/source/kit/CMakeLists.txt +++ b/source/kit/CMakeLists.txt @@ -3,9 +3,8 @@ target_sources( PRIVATE input_buffer.c bigint.c status.c secure_random.c thread.posix.c atomic.win32.c condition_variable.c thread.win32.c - move_back.c input_stream.c lower_bound.c file.c string_ref.c - async_function.c allocator.c array_ref.c dynamic_array.c mutex.c - mersenne_twister_64.c + move_back.c input_stream.c file.c string_ref.c async_function.c + allocator.c array_ref.c dynamic_array.c mutex.c mersenne_twister_64.c PUBLIC $ $ diff --git a/source/kit/async_function.h b/source/kit/async_function.h index 73e3fee..1791291 100644 --- a/source/kit/async_function.h +++ b/source/kit/async_function.h @@ -190,12 +190,12 @@ typedef struct { ((promise_)._state_machine(&(promise_), kit_af_request_join), \ (promise_).return_value) -#define KIT_AF_JOIN_N(promises_, size_) \ - do { \ - int kit_af_index_; \ - for (kit_af_index_ = 0; kit_af_index_ < (size_); \ - kit_af_index_++) \ - KIT_AF_JOIN((promises_)[kit_af_index_]); \ +#define KIT_AF_JOIN_N(promises_, size_) \ + do { \ + int kit_af_index_; \ + for (kit_af_index_ = 0; kit_af_index_ < (size_); \ + kit_af_index_++) \ + (void) KIT_AF_JOIN((promises_)[kit_af_index_]); \ } while (0) #define KIT_AF_RESUME_AND_JOIN(promise_) \ diff --git a/source/kit/lower_bound.c b/source/kit/lower_bound.c deleted file mode 100644 index 0ae8489..0000000 --- a/source/kit/lower_bound.c +++ /dev/null @@ -1 +0,0 @@ -#include "lower_bound.h" diff --git a/source/kit/thread.posix.c b/source/kit/thread.posix.c index 12bdd05..192dca4 100644 --- a/source/kit/thread.posix.c +++ b/source/kit/thread.posix.c @@ -1,11 +1,12 @@ +#include "thread.h" + +#include "allocator.h" +#include "condition_variable.h" +#include "mutex.h" + #ifndef KIT_DISABLE_SYSTEM_THREADS # if !defined(_WIN32) || defined(__CYGWIN__) -# include "allocator.h" -# include "condition_variable.h" -# include "mutex.h" -# include "thread.h" - # include # include # include diff --git a/source/kit/thread.win32.c b/source/kit/thread.win32.c index e483c4e..94f6e89 100644 --- a/source/kit/thread.win32.c +++ b/source/kit/thread.win32.c @@ -1,3 +1,9 @@ +#include "thread.h" + +#include "allocator.h" +#include "condition_variable.h" +#include "mutex.h" + #ifndef KIT_DISABLE_SYSTEM_THREADS # if defined(_WIN32) && !defined(__CYGWIN__) @@ -8,11 +14,6 @@ # include # include -# include "allocator.h" -# include "condition_variable.h" -# include "mutex.h" -# include "thread.h" - # ifndef WIN32_LEAN_AND_MEAN # define WIN32_LEAN_AND_MEAN 1 # endif diff --git a/source/test/unittests/async_function.test.c b/source/test/unittests/async_function.test.c index 320f323..6ec8825 100644 --- a/source/test/unittests/async_function.test.c +++ b/source/test/unittests/async_function.test.c @@ -142,29 +142,29 @@ TEST("coroutine generator") { TEST("coroutine status finished") { AF_CREATE(promise, test_bar); REQUIRE(!AF_FINISHED(promise)); - AF_RESUME_AND_JOIN(promise); + (void) AF_RESUME_AND_JOIN(promise); REQUIRE(!AF_FINISHED(promise)); - AF_RESUME_AND_JOIN(promise); + (void) AF_RESUME_AND_JOIN(promise); REQUIRE(AF_FINISHED(promise)); } TEST("coroutine task") { AF_CREATE(promise, test_task); - AF_RESUME_AND_JOIN(promise); + (void) AF_RESUME_AND_JOIN(promise); REQUIRE(!AF_FINISHED(promise)); - AF_RESUME_AND_JOIN(promise); + (void) AF_RESUME_AND_JOIN(promise); REQUIRE(!AF_FINISHED(promise)); - AF_RESUME_AND_JOIN(promise); + (void) AF_RESUME_AND_JOIN(promise); REQUIRE(AF_FINISHED(promise)); } TEST("coroutine nested task") { AF_CREATE(promise, test_nest_task); - AF_RESUME_AND_JOIN(promise); + (void) AF_RESUME_AND_JOIN(promise); REQUIRE(!AF_FINISHED(promise)); - AF_RESUME_AND_JOIN(promise); + (void) AF_RESUME_AND_JOIN(promise); REQUIRE(!AF_FINISHED(promise)); - AF_RESUME_AND_JOIN(promise); + (void) AF_RESUME_AND_JOIN(promise); REQUIRE(AF_FINISHED(promise)); } @@ -174,7 +174,7 @@ TEST("coroutine nested generator") { REQUIRE(AF_RESUME_AND_JOIN(promise) == 2); REQUIRE(AF_RESUME_AND_JOIN(promise) == 3); REQUIRE(!AF_FINISHED(promise)); - AF_RESUME_AND_JOIN(promise); + (void) AF_RESUME_AND_JOIN(promise); REQUIRE(AF_FINISHED(promise)); } @@ -198,7 +198,7 @@ TEST("coroutine custom execution context lazy") { AF_RESUME(promise); REQUIRE(promise.return_value == 0); REQUIRE(!AF_FINISHED(promise)); - AF_JOIN(promise); + (void) AF_JOIN(promise); REQUIRE(promise.return_value == 42); REQUIRE(AF_FINISHED(promise)); } @@ -210,7 +210,7 @@ TEST("coroutine custom execution context immediate") { AF_RESUME(promise); REQUIRE(promise.return_value == 42); REQUIRE(AF_FINISHED(promise)); - AF_JOIN(promise); + (void) AF_JOIN(promise); REQUIRE(promise.return_value == 42); REQUIRE(AF_FINISHED(promise)); } -- cgit v1.2.3