diff --git a/include/criterion/types.h b/include/criterion/types.h index 6e7dae2..f508174 100644 --- a/include/criterion/types.h +++ b/include/criterion/types.h @@ -26,6 +26,7 @@ # include # include +# include "common.h" struct criterion_test_extra_data { int sentinel_; diff --git a/src/posix-compat.c b/src/posix-compat.c index 020d61f..21378aa 100644 --- a/src/posix-compat.c +++ b/src/posix-compat.c @@ -208,3 +208,17 @@ bool is_current_process(s_proc_handle *proc) { return proc->pid == getpid(); #endif } + +#ifdef VANILLA_WIN32 +void *get_win_section_start(const char *section) { + char symbol[64]; + sprintf(symbol, "g_%s_section_start", section); + return (void*) GetProcAddress(GetModuleHandle(NULL), symbol); +} + +void *get_win_section_end(const char *section) { + char symbol[64]; + sprintf(symbol, "g_%s_section_end", section); + return (void*) GetProcAddress(GetModuleHandle(NULL), symbol); +} +#endif diff --git a/src/posix-compat.h b/src/posix-compat.h index 477361e..3ad0525 100644 --- a/src/posix-compat.h +++ b/src/posix-compat.h @@ -53,4 +53,14 @@ void wait_process(s_proc_handle *handle, int *status); s_proc_handle *get_current_process(); bool is_current_process(s_proc_handle *proc); +# ifdef VANILLA_WIN32 +void *get_win_section_start(const char *section); +void *get_win_section_end(const char *section); +# define GET_SECTION_START(Name) get_win_section_start(Name) +# define GET_SECTION_END(Name) get_win_section_end(Name) +# else +# define GET_SECTION_START(Name) SECTION_START(Name) +# define GET_SECTION_END(Name) SECTION_END(Name) +# endif + #endif /* !POSIX_COMPAT_H_ */ diff --git a/src/report.c b/src/report.c index 59e3738..8bdab4d 100644 --- a/src/report.c +++ b/src/report.c @@ -31,19 +31,20 @@ #include "criterion/ordered-set.h" #include "report.h" #include "config.h" +#include "posix-compat.h" #ifdef HAVE_PCRE #include "extmatch.h" #endif -#define IMPL_CALL_REPORT_HOOKS(Kind) \ - IMPL_SECTION_LIMITS(f_report_hook, crit_ ## Kind); \ - void call_report_hooks_##Kind(void *data) { \ - for (f_report_hook *hook = SECTION_START(crit_ ## Kind); \ - hook < SECTION_END(crit_ ## Kind); \ - ++hook) { \ - (*hook)(data); \ - } \ +#define IMPL_CALL_REPORT_HOOKS(Kind) \ + IMPL_SECTION_LIMITS(f_report_hook, crit_ ## Kind); \ + void call_report_hooks_##Kind(void *data) { \ + for (f_report_hook *hook = GET_SECTION_START(crit_ ## Kind); \ + hook < GET_SECTION_END(crit_ ## Kind); \ + ++hook) { \ + (*hook)(data); \ + } \ } #define IMPL_REPORT_HOOK(Type) \ diff --git a/src/runner.h b/src/runner.h index 9cb4156..0d47b89 100644 --- a/src/runner.h +++ b/src/runner.h @@ -25,20 +25,21 @@ # define CRITERION_RUNNER_H_ # include "criterion/types.h" +# include "posix-compat.h" DECL_SECTION_LIMITS(struct criterion_test, criterion_tests); DECL_SECTION_LIMITS(struct criterion_suite, crit_suites); struct criterion_test_set *criterion_init(void); -# define FOREACH_TEST_SEC(Test) \ - for (struct criterion_test *Test = SECTION_START(criterion_tests); \ - Test < SECTION_END(criterion_tests); \ +# define FOREACH_TEST_SEC(Test) \ + for (struct criterion_test *Test = GET_SECTION_START(criterion_tests); \ + Test < GET_SECTION_END(criterion_tests); \ ++Test) -# define FOREACH_SUITE_SEC(Suite) \ - for (struct criterion_suite *Suite = SECTION_START(crit_suites); \ - Suite < SECTION_END(crit_suites); \ +# define FOREACH_SUITE_SEC(Suite) \ + for (struct criterion_suite *Suite = GET_SECTION_START(crit_suites); \ + Suite < GET_SECTION_END(crit_suites); \ ++Suite) #endif /* !CRITERION_RUNNER_H_ */