From a6929666401953a5b3a93dfe83c9398e012beefc Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sat, 21 Sep 2024 12:52:06 +1000 Subject: [PATCH] Investigating bitness issue on windows --- source/toy_common.h | 4 ++-- tests/cases/test_ast.c | 37 ++++++++++++++++++++----------------- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/source/toy_common.h b/source/toy_common.h index b87d9ca..231c7a3 100644 --- a/source/toy_common.h +++ b/source/toy_common.h @@ -8,7 +8,7 @@ //TOY_API is platform-dependant, and marks publicly usable API functions #if defined(__linux__) #define TOY_API extern -#elif defined(_MSC_VER) +#elif defined(_WIN32) || defined(_WIN64) #ifndef TOY_EXPORT #define TOY_API __declspec(dllimport) #else @@ -28,7 +28,7 @@ #else #define TOY_BITNESS 32 #endif -#elif defined(_MSC_VER) +#elif defined(_WIN32) || defined(_WIN64) #if defined(_WIN64) #define TOY_BITNESS 64 #else diff --git a/tests/cases/test_ast.c b/tests/cases/test_ast.c index bbe4e43..9e15393 100644 --- a/tests/cases/test_ast.c +++ b/tests/cases/test_ast.c @@ -3,7 +3,7 @@ #include -int test_sizeof_ast_32bit() { +int test_sizeof_ast_64bit() { #define TEST_SIZEOF(type, size) \ if (sizeof(type) != size) { \ fprintf(stderr, TOY_CC_ERROR "ERROR: sizeof(" #type ") is %d, expected %d\n" TOY_CC_RESET, (int)sizeof(type), size); \ @@ -15,21 +15,22 @@ int test_sizeof_ast_32bit() { //run for each type TEST_SIZEOF(Toy_AstType, 4); - TEST_SIZEOF(Toy_AstBlock, 16); + TEST_SIZEOF(Toy_AstBlock, 32); TEST_SIZEOF(Toy_AstValue, 12); - TEST_SIZEOF(Toy_AstUnary, 12); - TEST_SIZEOF(Toy_AstBinary, 16); - TEST_SIZEOF(Toy_AstGroup, 8); + TEST_SIZEOF(Toy_AstUnary, 16); + TEST_SIZEOF(Toy_AstBinary, 24); + TEST_SIZEOF(Toy_AstGroup, 16); TEST_SIZEOF(Toy_AstPass, 4); TEST_SIZEOF(Toy_AstError, 4); - TEST_SIZEOF(Toy_Ast, 16); + TEST_SIZEOF(Toy_AstEnd, 4); + TEST_SIZEOF(Toy_Ast, 32); #undef TEST_SIZEOF return -err; } -int test_sizeof_ast_64bit() { +int test_sizeof_ast_32bit() { #define TEST_SIZEOF(type, size) \ if (sizeof(type) != size) { \ fprintf(stderr, TOY_CC_ERROR "ERROR: sizeof(" #type ") is %d, expected %d\n" TOY_CC_RESET, (int)sizeof(type), size); \ @@ -41,14 +42,15 @@ int test_sizeof_ast_64bit() { //run for each type TEST_SIZEOF(Toy_AstType, 4); - TEST_SIZEOF(Toy_AstBlock, 32); + TEST_SIZEOF(Toy_AstBlock, 16); TEST_SIZEOF(Toy_AstValue, 12); - TEST_SIZEOF(Toy_AstUnary, 16); - TEST_SIZEOF(Toy_AstBinary, 24); - TEST_SIZEOF(Toy_AstGroup, 16); + TEST_SIZEOF(Toy_AstUnary, 12); + TEST_SIZEOF(Toy_AstBinary, 16); + TEST_SIZEOF(Toy_AstGroup, 8); TEST_SIZEOF(Toy_AstPass, 4); TEST_SIZEOF(Toy_AstError, 4); - TEST_SIZEOF(Toy_Ast, 32); + TEST_SIZEOF(Toy_AstEnd, 4); + TEST_SIZEOF(Toy_Ast, 16); #undef TEST_SIZEOF @@ -194,22 +196,23 @@ int main() { //run each test set, returning the total errors given int total = 0, res = 0; -#if TOY_BITNESS == 32 - res = test_sizeof_ast_32bit(); + +#if TOY_BITNESS == 64 + res = test_sizeof_ast_64bit(); total += res; if (res == 0) { printf(TOY_CC_NOTICE "All good\n" TOY_CC_RESET); } -#elif TOY_BITNESS == 64 - res = test_sizeof_ast_64bit(); +#elif TOY_BITNESS == 32 + res = test_sizeof_ast_32bit(); total += res; if (res == 0) { printf(TOY_CC_NOTICE "All good\n" TOY_CC_RESET); } #else - fprintf(stderr, TOY_CC_WARN "WARNING: Skipping test_sizeof_ast_*bit(); Can't determine the 'bitness' of this platform\n" TOY_CC_RESET); + fprintf(stderr, TOY_CC_WARN "WARNING: Skipping test_sizeof_ast_*bit(); Can't determine the 'bitness' of this platform (seems to be %d)\n" TOY_CC_RESET, TOY_BITNESS); #endif {