From 86762f8ff7295fc4a8bac1a29d74a3f1172f47bb Mon Sep 17 00:00:00 2001 From: Snaipe Date: Mon, 3 Aug 2015 15:15:48 +0200 Subject: [PATCH] Fixed windows code for section retrieving and changed section names to fit under 8 bytes. --- include/criterion/criterion.h | 4 ++-- include/criterion/hooks.h | 20 +++++++++++++++++++- src/posix-compat.c | 6 +++--- src/report.c | 16 ++++++++-------- src/report.h | 4 ++-- src/runner.c | 4 ++-- src/runner.h | 16 ++++++++-------- 7 files changed, 44 insertions(+), 26 deletions(-) diff --git a/include/criterion/criterion.h b/include/criterion/criterion.h index 48b3dcf..50c85b2 100644 --- a/include/criterion/criterion.h +++ b/include/criterion/criterion.h @@ -22,7 +22,7 @@ .line_ = __LINE__, \ __VA_ARGS__ \ }; \ - SECTION_("criterion_tests") \ + SECTION_("cr_tst") \ const struct criterion_test IDENTIFIER_(Category, Name, meta) = { \ .name = #Name, \ .category = #Category, \ @@ -38,7 +38,7 @@ .line_ = 0, \ __VA_ARGS__ \ }; \ - SECTION_("crit_suites") \ + SECTION_("cr_sts") \ const struct criterion_suite SUITE_IDENTIFIER_(Name, meta) = { \ .name = #Name, \ .data = &SUITE_IDENTIFIER_(Name, extra), \ diff --git a/include/criterion/hooks.h b/include/criterion/hooks.h index a8b7bfa..c597467 100644 --- a/include/criterion/hooks.h +++ b/include/criterion/hooks.h @@ -48,9 +48,27 @@ typedef void (*f_report_hook)(); # define HOOK_PROTOTYPE_ \ void HOOK_IDENTIFIER_(impl) +// Section abbreviations +# define HOOK_SECTION_PRE_ALL cr_pra +# define HOOK_SECTION_PRE_SUITE cr_prs +# define HOOK_SECTION_PRE_INIT cr_pri +# define HOOK_SECTION_PRE_TEST cr_prt +# define HOOK_SECTION_ASSERT cr_ast +# define HOOK_SECTION_TEST_CRASH cr_tsc +# define HOOK_SECTION_POST_TEST cr_pot +# define HOOK_SECTION_POST_FINI cr_pof +# define HOOK_SECTION_POST_SUITE cr_pos +# define HOOK_SECTION_POST_ALL cr_poa + +# define HOOK_SECTION(Kind) HOOK_SECTION_ ## Kind + +# define HOOK_SECTION_STRINGIFY__(Sec) #Sec +# define HOOK_SECTION_STRINGIFY_(Sec) HOOK_SECTION_STRINGIFY__(Sec) +# define HOOK_SECTION_STRINGIFY(Kind) HOOK_SECTION_STRINGIFY_(HOOK_SECTION(Kind)) + # define ReportHook(Kind) \ HOOK_PROTOTYPE_(); \ - SECTION_("crit_" #Kind) \ + SECTION_(HOOK_SECTION_STRINGIFY(Kind)) \ const f_report_hook HOOK_IDENTIFIER_(func) = HOOK_IDENTIFIER_(impl); \ HOOK_PROTOTYPE_ diff --git a/src/posix-compat.c b/src/posix-compat.c index 34516d6..8759d32 100644 --- a/src/posix-compat.c +++ b/src/posix-compat.c @@ -219,7 +219,7 @@ void *get_win_section_start(const char *section) { PIMAGE_SECTION_HEADER pSecHeader = IMAGE_FIRST_SECTION(ntHeader); for(int i = 0; i < ntHeader->FileHeader.NumberOfSections; i++, pSecHeader++) { - if (!strcmp(pSecHeader->Name, section)) { + if (!strncmp(pSecHeader->Name, section, 8)) { return (void*) pSecHeader->VirtualAddress; } } @@ -235,8 +235,8 @@ void *get_win_section_end(const char *section) { PIMAGE_SECTION_HEADER pSecHeader = IMAGE_FIRST_SECTION(ntHeader); for(int i = 0; i < ntHeader->FileHeader.NumberOfSections; i++, pSecHeader++) { - if (!strcmp(pSecHeader->Name, section)) { - return (char*) pSecHeader->VirtualAddress + pSecHeader->SizeOfRawData); + if (!strncmp(pSecHeader->Name, section, 8)) { + return (char*) pSecHeader->VirtualAddress + pSecHeader->SizeOfRawData; } } return NULL; diff --git a/src/report.c b/src/report.c index f57758b..a55994a 100644 --- a/src/report.c +++ b/src/report.c @@ -37,14 +37,14 @@ #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 = GET_SECTION_START(crit_ ## Kind); \ - hook < (f_report_hook*) GET_SECTION_END(crit_ ## Kind); \ - ++hook) { \ - (*hook)(data); \ - } \ +#define IMPL_CALL_REPORT_HOOKS(Kind) \ + IMPL_SECTION_LIMITS(f_report_hook, HOOK_SECTION(Kind)); \ + void call_report_hooks_##Kind(void *data) { \ + for (f_report_hook *hook = GET_SECTION_START(HOOK_SECTION(Kind)); \ + hook < (f_report_hook*) GET_SECTION_END(HOOK_SECTION(Kind)); \ + ++hook) { \ + (*hook)(data); \ + } \ } #define IMPL_REPORT_HOOK(Type) \ diff --git a/src/report.h b/src/report.h index 6a740c5..aab2a10 100644 --- a/src/report.h +++ b/src/report.h @@ -28,8 +28,8 @@ # define report(Kind, Data) call_report_hooks_##Kind(Data) -# define DECL_CALL_REPORT_HOOKS(Kind) \ - DECL_SECTION_LIMITS(f_report_hook, crit_ ## Kind); \ +# define DECL_CALL_REPORT_HOOKS(Kind) \ + DECL_SECTION_LIMITS(f_report_hook, HOOK_SECTION(Kind)); \ void call_report_hooks_##Kind(void *data) DECL_CALL_REPORT_HOOKS(PRE_ALL); diff --git a/src/runner.c b/src/runner.c index b19ea48..0136952 100644 --- a/src/runner.c +++ b/src/runner.c @@ -36,8 +36,8 @@ #include "posix-compat.h" #include "abort.h" -IMPL_SECTION_LIMITS(struct criterion_test, criterion_tests); -IMPL_SECTION_LIMITS(struct criterion_suite, crit_suites); +IMPL_SECTION_LIMITS(struct criterion_test, cr_tst); +IMPL_SECTION_LIMITS(struct criterion_suite, cr_sts); // This is here to make the test suite & test sections non-empty TestSuite(); diff --git a/src/runner.h b/src/runner.h index f021ee4..e78fd96 100644 --- a/src/runner.h +++ b/src/runner.h @@ -27,19 +27,19 @@ # include "criterion/types.h" # include "posix-compat.h" -DECL_SECTION_LIMITS(struct criterion_test, criterion_tests); -DECL_SECTION_LIMITS(struct criterion_suite, crit_suites); +DECL_SECTION_LIMITS(struct criterion_test, cr_tst); +DECL_SECTION_LIMITS(struct criterion_suite, cr_sts); struct criterion_test_set *criterion_init(void); -# define FOREACH_TEST_SEC(Test) \ - for (struct criterion_test *Test = GET_SECTION_START(criterion_tests); \ - Test < (struct criterion_test*) GET_SECTION_END(criterion_tests); \ +# define FOREACH_TEST_SEC(Test) \ + for (struct criterion_test *Test = GET_SECTION_START(cr_tst); \ + Test < (struct criterion_test*) GET_SECTION_END(cr_tst); \ ++Test) -# define FOREACH_SUITE_SEC(Suite) \ - for (struct criterion_suite *Suite = GET_SECTION_START(crit_suites); \ - Suite < (struct criterion_suite*) GET_SECTION_END(crit_suites); \ +# define FOREACH_SUITE_SEC(Suite) \ + for (struct criterion_suite *Suite = GET_SECTION_START(cr_sts); \ + Suite < (struct criterion_suite*) GET_SECTION_END(cr_sts); \ ++Suite) #endif /* !CRITERION_RUNNER_H_ */