diff --git a/CMakeLists.txt b/CMakeLists.txt index 96e093c..3fb7ca7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,7 +41,7 @@ set(GettextTranslate_GMO_BINARY 1) add_definitions(-DCRITERION_BUILDING_DLL=1) if (NOT MSVC) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Werror -g -std=gnu99") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Werror -pedantic -pedantic-errors -Wno-format -std=c99") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror -g -std=c++11") endif () @@ -53,6 +53,10 @@ if (WIN32 AND NOT MSVC) set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-no-undefined") endif() +# Enable standard extensions + +add_definitions(-D_XOPEN_SOURCE=700) + # Compilation options option(MINGW_DEFINE_OFF_T "Define off_t and off64_t ourselves before including io.h" OFF) diff --git a/include/criterion/ordered-set.h b/include/criterion/ordered-set.h index 24044f8..07c5148 100644 --- a/include/criterion/ordered-set.h +++ b/include/criterion/ordered-set.h @@ -37,7 +37,6 @@ struct criterion_ordered_set { struct criterion_ordered_set_node { struct criterion_ordered_set_node *next; - char data[0]; }; CR_BEGIN_C_API @@ -54,6 +53,6 @@ CR_END_C_API # define FOREACH_SET(Elt, Set) \ for (struct criterion_ordered_set_node *n = Set->first; n; n = n->next) \ for (int cond = 1; cond;) \ - for (Elt = (void*) n->data; cond && (cond = 0, 1);) + for (Elt = (void*) (n + 1); cond && (cond = 0, 1);) #endif /* !CRITERION_ORDERED_SET_H_ */ diff --git a/src/core/ordered-set.c b/src/core/ordered-set.c index fa9c5c5..c7c6f38 100644 --- a/src/core/ordered-set.c +++ b/src/core/ordered-set.c @@ -36,7 +36,7 @@ static INLINE void nothing(CR_UNUSED void *ptr, CR_UNUSED void *meta) {} static void destroy_ordered_set_node(void *ptr, void *meta) { struct criterion_ordered_set *set = *(void **) meta; struct criterion_ordered_set_node *n = ptr; - DEF(set->dtor, nothing)(n->data, NULL); + DEF(set->dtor, nothing)(n + 1, NULL); sfree(((struct criterion_ordered_set_node *) ptr)->next); } @@ -58,11 +58,11 @@ void *insert_ordered_set(struct criterion_ordered_set *l, size_t size) { int cmp; struct criterion_ordered_set_node *n, *prev = NULL; - for (n = l->first; n && (cmp = l->cmp(ptr, n->data)) > 0; n = n->next) + for (n = l->first; n && (cmp = l->cmp(ptr, n + 1)) > 0; n = n->next) prev = n; if (n && !cmp) // element already exists - return n->data; + return n + 1; struct criterion_ordered_set_node *new = smalloc( .size = sizeof(struct criterion_ordered_set_node) + size, @@ -72,7 +72,7 @@ void *insert_ordered_set(struct criterion_ordered_set *l, if (!new) return NULL; - memcpy(new->data, ptr, size); + memcpy(new + 1, ptr, size); new->next = n; if (prev) { prev->next = new; @@ -81,5 +81,5 @@ void *insert_ordered_set(struct criterion_ordered_set *l, } ++l->size; - return new->data; + return new + 1; } diff --git a/src/core/report.c b/src/core/report.c index 7112319..c91e780 100644 --- a/src/core/report.c +++ b/src/core/report.c @@ -71,17 +71,17 @@ f_report_hook CR_SECTION_END_(CR_HOOK_SECTION(POST_SUITE)); f_report_hook CR_SECTION_END_(CR_HOOK_SECTION(POST_ALL)); #endif -IMPL_CALL_REPORT_HOOKS(PRE_ALL); -IMPL_CALL_REPORT_HOOKS(PRE_SUITE); -IMPL_CALL_REPORT_HOOKS(PRE_INIT); -IMPL_CALL_REPORT_HOOKS(PRE_TEST); -IMPL_CALL_REPORT_HOOKS(ASSERT); -IMPL_CALL_REPORT_HOOKS(THEORY_FAIL); -IMPL_CALL_REPORT_HOOKS(TEST_CRASH); -IMPL_CALL_REPORT_HOOKS(POST_TEST); -IMPL_CALL_REPORT_HOOKS(POST_FINI); -IMPL_CALL_REPORT_HOOKS(POST_SUITE); -IMPL_CALL_REPORT_HOOKS(POST_ALL); +IMPL_CALL_REPORT_HOOKS(PRE_ALL) +IMPL_CALL_REPORT_HOOKS(PRE_SUITE) +IMPL_CALL_REPORT_HOOKS(PRE_INIT) +IMPL_CALL_REPORT_HOOKS(PRE_TEST) +IMPL_CALL_REPORT_HOOKS(ASSERT) +IMPL_CALL_REPORT_HOOKS(THEORY_FAIL) +IMPL_CALL_REPORT_HOOKS(TEST_CRASH) +IMPL_CALL_REPORT_HOOKS(POST_TEST) +IMPL_CALL_REPORT_HOOKS(POST_FINI) +IMPL_CALL_REPORT_HOOKS(POST_SUITE) +IMPL_CALL_REPORT_HOOKS(POST_ALL) ReportHook(PRE_ALL)(CR_UNUSED struct criterion_test_set *arg) {} ReportHook(PRE_SUITE)(CR_UNUSED struct criterion_suite_set *arg) {} diff --git a/src/core/report.h b/src/core/report.h index aa545ea..2713974 100644 --- a/src/core/report.h +++ b/src/core/report.h @@ -27,7 +27,8 @@ # include "criterion/hooks.h" # include "criterion/options.h" -# define report(Kind, Data) call_report_hooks_##Kind(Data) +# define report(Kind, Data) report_(Kind, Data) +# define report_(Kind, Data) call_report_hooks_##Kind(Data) # define DECL_CALL_REPORT_HOOKS(Kind) \ CR_DECL_SECTION_LIMITS(f_report_hook, CR_HOOK_SECTION(Kind)); \ diff --git a/src/core/runner.c b/src/core/runner.c index 22a0f91..30d990a 100644 --- a/src/core/runner.c +++ b/src/core/runner.c @@ -31,6 +31,7 @@ #include "criterion/options.h" #include "criterion/ordered-set.h" #include "criterion/logging.h" +#include "criterion/preprocess.h" #include "compat/time.h" #include "compat/posix.h" #include "compat/processor.h" @@ -84,7 +85,7 @@ CR_IMPL_SECTION_LIMITS(struct criterion_suite*, cr_sts); // This is here to make the test suite & test sections non-empty TestSuite(); -Test(,) {}; +Test(,) {} static INLINE void nothing(void) {} @@ -178,13 +179,16 @@ void run_test_child(struct criterion_test *test, g_wrappers[test->data->lang_](test, suite); } -#define push_event(Kind, ...) \ +#define push_event(...) \ do { \ stat_push_event(ctx->stats, \ ctx->suite_stats, \ ctx->test_stats, \ - &(struct event) { .kind = Kind, __VA_ARGS__ }); \ - report(Kind, ctx->test_stats); \ + &(struct event) { \ + .kind = CR_VA_HEAD(__VA_ARGS__), \ + CR_VA_TAIL(__VA_ARGS__) \ + }); \ + report(CR_VA_HEAD(__VA_ARGS__), ctx->test_stats); \ } while (0) s_pipe_handle *g_worker_pipe; diff --git a/src/core/runner_coroutine.c b/src/core/runner_coroutine.c index 31a271c..6e557a3 100644 --- a/src/core/runner_coroutine.c +++ b/src/core/runner_coroutine.c @@ -112,7 +112,7 @@ struct worker *run_next_test(struct criterion_test_set *p_set, ccrReturn(NULL); for (ctx->ns = ctx->set->suites->first; ctx->ns; ctx->ns = ctx->ns->next) { - ctx->suite_set = (void*) ctx->ns->data; + ctx->suite_set = (void*) (ctx->ns + 1); if (!ctx->suite_set->tests) continue; @@ -126,7 +126,7 @@ struct worker *run_next_test(struct criterion_test_set *p_set, stat_push_event(ctx->stats, ctx->suite_stats, NULL, &ev); for (ctx->nt = ctx->suite_set->tests->first; ctx->nt; ctx->nt = ctx->nt->next) { - ctx->test = (void*) ctx->nt->data; + ctx->test = (void*) (ctx->nt + 1); if (ctx->test->data->kind_ == CR_TEST_PARAMETERIZED && ctx->test->data->param_) { diff --git a/src/core/stats.c b/src/core/stats.c index f68e918..bb10bac 100644 --- a/src/core/stats.c +++ b/src/core/stats.c @@ -59,7 +59,7 @@ static void nothing(CR_UNUSED s_glob_stats *stats, CR_UNUSED s_suite_stats *sstats, CR_UNUSED s_test_stats *tstats, CR_UNUSED void *data) { -}; +} static void destroy_stats(void *ptr, CR_UNUSED void *meta) { s_glob_stats *stats = ptr; diff --git a/src/core/theories.c b/src/core/theories.c index 28d0d12..d1a027c 100644 --- a/src/core/theories.c +++ b/src/core/theories.c @@ -91,7 +91,7 @@ void cr_theory_reset(struct criterion_theory_context *ctx) { } void cr_theory_call(struct criterion_theory_context *ctx, void (*fnptr)(void)) { - dcCallVoid(ctx->vm, (DCpointer) fnptr); + dcCallVoid(ctx->vm, (DCpointer) (unsigned long long) fnptr); } static bool contains_word(const char *str, const char *pattern, size_t sz) { diff --git a/src/string/extmatch.c b/src/string/extmatch.c index b838ff9..3af6da9 100644 --- a/src/string/extmatch.c +++ b/src/string/extmatch.c @@ -134,16 +134,16 @@ static inline void handle_special(struct context *ctx, handler_arg strs[5]) { } # define _ active -Handler(handle_plus, [POSTSUFFIX] = {_, "+"}, [ELSESTR] = {_, "+" }); -Handler(handle_star, [POSTSUFFIX] = {_, "*"}, [ELSESTR] = {_, ".*"}); -Handler(handle_wild, [POSTSUFFIX] = {_, "?"}, [ELSESTR] = {_, "." }); +Handler(handle_plus, [POSTSUFFIX] = {_, "+"}, [ELSESTR] = {_, "+" }) +Handler(handle_star, [POSTSUFFIX] = {_, "*"}, [ELSESTR] = {_, ".*"}) +Handler(handle_wild, [POSTSUFFIX] = {_, "?"}, [ELSESTR] = {_, "." }) Handler(handle_excl, [POSTPREFIX] = {_, "?!"}, [PRESUFFIX] = {is_eos, "$" }, [POSTSUFFIX] = {_, ".*"}, [ELSESTR] = {_, "!" } - ); -Handler(handle_at, [ELSESTR] = {_, "@"}); + ) +Handler(handle_at, [ELSESTR] = {_, "@"}) # undef _ static void handle_rbra(struct context *ctx, CR_UNUSED char c) {