From 12f182f0cf37bcf6441f01d6fc6347464439fdf2 Mon Sep 17 00:00:00 2001 From: Abdelrahman Date: Sat, 5 Oct 2024 22:06:13 +0100 Subject: [PATCH] Define macros for C linkage --- src/common/aliases/aliases.h | 2 ++ src/common/mem_utils/mem_utils.h | 4 ++-- src/common/shell/commander/commander.c | 3 +-- src/common/shell/commander/commander.h | 9 +++------ src/common/shell/termcolour/posix/termcolour_posix.h | 4 ++-- src/common/shell/termcolour/termcolour.h | 4 ++-- src/common/shell/termcolour/terminal_colours.h | 4 ++-- src/common/shell/termcolour/win/termcolour_win.h | 4 ++-- src/core/cpath/cpath.h | 4 ++-- src/core/mem/allocator/mem_allocator.h | 4 ++-- src/core/mem/arena/mem_arena.h | 4 ++-- src/core/mem/arena/mem_arena_allocator.h | 4 ++-- src/core/mem/libc/mem_libc_allocator.h | 4 ++-- src/core/strings/basic_strings/basic_strings.h | 4 ++-- src/core/strings/dstr/dstr.h | 4 ++-- src/tester/tester.h | 4 ++-- tests/allocator/test_allocator.h | 4 ++-- tests/arena/test_arena.h | 4 ++-- tests/shell_commander/test_shell_commander.h | 4 ++-- 19 files changed, 38 insertions(+), 40 deletions(-) diff --git a/src/common/aliases/aliases.h b/src/common/aliases/aliases.h index 585cc06..798ae0c 100644 --- a/src/common/aliases/aliases.h +++ b/src/common/aliases/aliases.h @@ -25,6 +25,8 @@ #ifdef __cplusplus #define class_mem static +#define BEGIN_C_LINKAGE extern "C" { +#define END_C_LINKAGE } #endif // __cplusplus #endif // !ALIASES_H diff --git a/src/common/mem_utils/mem_utils.h b/src/common/mem_utils/mem_utils.h index a86dd00..048bb85 100644 --- a/src/common/mem_utils/mem_utils.h +++ b/src/common/mem_utils/mem_utils.h @@ -15,7 +15,7 @@ #endif #ifdef __cplusplus -extern "C" { +BEGIN_C_LINKAGE #endif // __cplusplus typedef enum mem_access { @@ -55,7 +55,7 @@ void *wapp_mem_util_alloc(void *addr, u64 size, MemAccess access, void wapp_mem_util_free(void *ptr, u64 size); #ifdef __cplusplus -} +END_C_LINKAGE #endif // __cplusplus #endif // !MEM_UTILS_H diff --git a/src/common/shell/commander/commander.c b/src/common/shell/commander/commander.c index 3351dfd..64abeb5 100644 --- a/src/common/shell/commander/commander.c +++ b/src/common/shell/commander/commander.c @@ -17,8 +17,7 @@ internal inline CMDError get_command_output(FILE *fp, CMDOutHandling out_handlin char *out_buf, u64 buf_size); internal inline CMDError get_output_status(FILE *fp, i32 *status_out); -// clang-format off -CMDResult run_command(CMDOutHandling out_handling, char *out_buf, u64 buf_size, ...) { // clang-format on +CMDResult run_command(CMDOutHandling out_handling, char *out_buf, u64 buf_size, ...) { va_list args; va_start(args, buf_size); diff --git a/src/common/shell/commander/commander.h b/src/common/shell/commander/commander.h index 2ed1c4f..8110834 100644 --- a/src/common/shell/commander/commander.h +++ b/src/common/shell/commander/commander.h @@ -7,11 +7,10 @@ #include #ifdef __cplusplus -extern "C" { +BEGIN_C_LINKAGE #endif // __cplusplus -#define CMD_NO_EXIT(ERR) \ - ((CMDResult){.exited = false, .exit_code = EXIT_FAILURE, .error = ERR}) +#define CMD_NO_EXIT(ERR) ((CMDResult){.exited = false, .exit_code = EXIT_FAILURE, .error = ERR}) #define wapp_shell_commander_execute(HANDLE_OUTPUT, OUT_BUF, BUF_SIZE, ...) \ run_command(HANDLE_OUTPUT, OUT_BUF, BUF_SIZE, __VA_ARGS__, "2>&1", NULL) @@ -41,12 +40,10 @@ struct commander_result { #endif // !WAPP_PLATFORM_WINDOWS }; -// clang-format off CMDResult run_command(CMDOutHandling out_handling, char *out_buf, u64 buf_size, ...); -// clang-format on #ifdef __cplusplus -} +END_C_LINKAGE #endif // __cplusplus #endif // !COMMANDER_H diff --git a/src/common/shell/termcolour/posix/termcolour_posix.h b/src/common/shell/termcolour/posix/termcolour_posix.h index 6866f48..d589b6a 100644 --- a/src/common/shell/termcolour/posix/termcolour_posix.h +++ b/src/common/shell/termcolour/posix/termcolour_posix.h @@ -8,13 +8,13 @@ #include "terminal_colours.h" #ifdef __cplusplus -extern "C" { +BEGIN_C_LINKAGE #endif // __cplusplus void print_coloured_text(const char *text, TerminalColour colour); #ifdef __cplusplus -} +END_C_LINKAGE #endif // __cplusplus #endif // !WAPP_PLATFORM_POSIX diff --git a/src/common/shell/termcolour/termcolour.h b/src/common/shell/termcolour/termcolour.h index 52830b4..5943883 100644 --- a/src/common/shell/termcolour/termcolour.h +++ b/src/common/shell/termcolour/termcolour.h @@ -4,14 +4,14 @@ #include "terminal_colours.h" #ifdef __cplusplus -extern "C" { +BEGIN_C_LINKAGE #endif // __cplusplus void wapp_shell_termcolour_print_text(const char *text, TerminalColour colour); void wapp_shell_termcolour_clear_colour(void); #ifdef __cplusplus -} +END_C_LINKAGE #endif // __cplusplus #endif // !TERM_COLOUR_H diff --git a/src/common/shell/termcolour/terminal_colours.h b/src/common/shell/termcolour/terminal_colours.h index 420863b..0fea8af 100644 --- a/src/common/shell/termcolour/terminal_colours.h +++ b/src/common/shell/termcolour/terminal_colours.h @@ -2,7 +2,7 @@ #define TERMINAL_COLOURS_H #ifdef __cplusplus -extern "C" { +BEGIN_C_LINKAGE #endif // __cplusplus typedef enum { @@ -28,7 +28,7 @@ typedef enum { } TerminalColour; #ifdef __cplusplus -} +END_C_LINKAGE #endif // __cplusplus #endif // !TERMINAL_COLOURS_H diff --git a/src/common/shell/termcolour/win/termcolour_win.h b/src/common/shell/termcolour/win/termcolour_win.h index 78d1e10..2dead47 100644 --- a/src/common/shell/termcolour/win/termcolour_win.h +++ b/src/common/shell/termcolour/win/termcolour_win.h @@ -12,13 +12,13 @@ #include #ifdef __cplusplus -extern "C" { +BEGIN_C_LINKAGE #endif // __cplusplus void print_coloured_text(const char *text, TerminalColour colour); #ifdef __cplusplus -} +END_C_LINKAGE #endif // __cplusplus #endif // !WAPP_PLATFORM_WINDOWS diff --git a/src/core/cpath/cpath.h b/src/core/cpath/cpath.h index 424c4be..adbff6a 100644 --- a/src/core/cpath/cpath.h +++ b/src/core/cpath/cpath.h @@ -4,7 +4,7 @@ #include "aliases.h" #ifdef __cplusplus -extern "C" { +BEGIN_C_LINKAGE #endif // __cplusplus #define NUMPARTS(...) \ @@ -19,7 +19,7 @@ void join_path(char *dst, u64 count, ...); void dirup(char *dst, u64 levels, const char *path); #ifdef __cplusplus -} +END_C_LINKAGE #endif // __cplusplus #endif // !PATH_UTILS_H diff --git a/src/core/mem/allocator/mem_allocator.h b/src/core/mem/allocator/mem_allocator.h index 3ca01b8..dc1ef36 100644 --- a/src/core/mem/allocator/mem_allocator.h +++ b/src/core/mem/allocator/mem_allocator.h @@ -4,7 +4,7 @@ #include "aliases.h" #ifdef __cplusplus -extern "C" { +BEGIN_C_LINKAGE #endif // __cplusplus /***************************************************************************/ // @@ -49,7 +49,7 @@ void *wapp_mem_allocator_realloc_aligned(const Allocator *allocator, void *ptr, void wapp_mem_allocator_free(const Allocator *allocator, void **ptr); #ifdef __cplusplus -} +END_C_LINKAGE #endif // __cplusplus #endif // !MEM_ALLOCATOR_H diff --git a/src/core/mem/arena/mem_arena.h b/src/core/mem/arena/mem_arena.h index 1eca49c..8bccabc 100644 --- a/src/core/mem/arena/mem_arena.h +++ b/src/core/mem/arena/mem_arena.h @@ -6,7 +6,7 @@ #include #ifdef __cplusplus -extern "C" { +BEGIN_C_LINKAGE #endif // __cplusplus typedef struct arena Arena; @@ -53,7 +53,7 @@ void wapp_mem_arena_clear(Arena *arena); void wapp_mem_arena_destroy(Arena **arena); #ifdef __cplusplus -} +END_C_LINKAGE #endif // __cplusplus #endif // !MEM_ARENA_H diff --git a/src/core/mem/arena/mem_arena_allocator.h b/src/core/mem/arena/mem_arena_allocator.h index bd77b6d..511f04d 100644 --- a/src/core/mem/arena/mem_arena_allocator.h +++ b/src/core/mem/arena/mem_arena_allocator.h @@ -7,7 +7,7 @@ #include #ifdef __cplusplus -extern "C" { +BEGIN_C_LINKAGE #endif // __cplusplus /***************************************************************************/ // @@ -51,7 +51,7 @@ void wapp_mem_arena_allocator_clear(Allocator *allocator); void wapp_mem_arena_allocator_destroy(Allocator *allocator); #ifdef __cplusplus -} +END_C_LINKAGE #endif // __cplusplus #endif // !MEM_ARENA_ALLOCATOR_H diff --git a/src/core/mem/libc/mem_libc_allocator.h b/src/core/mem/libc/mem_libc_allocator.h index 608821c..5b66539 100644 --- a/src/core/mem/libc/mem_libc_allocator.h +++ b/src/core/mem/libc/mem_libc_allocator.h @@ -3,13 +3,13 @@ #include "mem_allocator.h" #ifdef __cplusplus -extern "C" { +BEGIN_C_LINKAGE #endif // __cplusplus Allocator wapp_mem_libc_allocator(void); #ifdef __cplusplus -} +END_C_LINKAGE #endif // __cplusplus #endif // !MEM_LIBC_H diff --git a/src/core/strings/basic_strings/basic_strings.h b/src/core/strings/basic_strings/basic_strings.h index 151c167..1c8a25f 100644 --- a/src/core/strings/basic_strings/basic_strings.h +++ b/src/core/strings/basic_strings/basic_strings.h @@ -6,7 +6,7 @@ #include #ifdef __cplusplus -extern "C" { +BEGIN_C_LINKAGE #endif // __cplusplus typedef struct bstr BasicString; @@ -28,7 +28,7 @@ struct strvw { #define wapp_string_print(STR) (printf("%.*s\n", (i32)STR.size, STR.buf)) #ifdef __cplusplus -} +END_C_LINKAGE #endif // __cplusplus #endif // !BASIC_STRING_H diff --git a/src/core/strings/dstr/dstr.h b/src/core/strings/dstr/dstr.h index a8c9eff..a6fd83e 100644 --- a/src/core/strings/dstr/dstr.h +++ b/src/core/strings/dstr/dstr.h @@ -8,7 +8,7 @@ #include #ifdef __cplusplus -extern "C" { +BEGIN_C_LINKAGE #endif // __cplusplus typedef struct dstr String; @@ -35,7 +35,7 @@ u64 wapp_dstr_capacity(const String *str); const char *wapp_dstr_to_cstr(const String *str); #ifdef __cplusplus -} +END_C_LINKAGE #endif // __cplusplus #endif // !DSTR_H diff --git a/src/tester/tester.h b/src/tester/tester.h index d4b397e..cfbd7ed 100644 --- a/src/tester/tester.h +++ b/src/tester/tester.h @@ -6,7 +6,7 @@ #include #ifdef __cplusplus -extern "C" { +BEGIN_C_LINKAGE #endif // __cplusplus #define wapp_tester_result(PASSED) ((TestFuncResult){.name = __func__, .passed = PASSED}) @@ -27,7 +27,7 @@ typedef TestFuncResult(TestFunc)(void); void run_tests(TestFunc *func1, ...); #ifdef __cplusplus -} +END_C_LINKAGE #endif // __cplusplus #endif // !TESTER_H diff --git a/tests/allocator/test_allocator.h b/tests/allocator/test_allocator.h index 6b3e20a..7b28de2 100644 --- a/tests/allocator/test_allocator.h +++ b/tests/allocator/test_allocator.h @@ -4,14 +4,14 @@ #include "tester.h" #ifdef __cplusplus -extern "C" { +BEGIN_C_LINKAGE #endif // __cplusplus TestFuncResult test_libc_allocator(void); TestFuncResult test_arena_allocator(void); #ifdef __cplusplus -} +END_C_LINKAGE #endif // __cplusplus #endif // !TEST_ALLOCATOR_H diff --git a/tests/arena/test_arena.h b/tests/arena/test_arena.h index 4625b0f..0ebad3e 100644 --- a/tests/arena/test_arena.h +++ b/tests/arena/test_arena.h @@ -4,7 +4,7 @@ #include "tester.h" #ifdef __cplusplus -extern "C" { +BEGIN_C_LINKAGE #endif // __cplusplus TestFuncResult test_arena_init(void); @@ -17,7 +17,7 @@ TestFuncResult test_arena_clear(void); TestFuncResult test_arena_destroy(void); #ifdef __cplusplus -} +END_C_LINKAGE #endif // __cplusplus #endif // !TEST_ARENA_H diff --git a/tests/shell_commander/test_shell_commander.h b/tests/shell_commander/test_shell_commander.h index 4cd6fc4..1854237 100644 --- a/tests/shell_commander/test_shell_commander.h +++ b/tests/shell_commander/test_shell_commander.h @@ -4,7 +4,7 @@ #include "tester.h" #ifdef __cplusplus -extern "C" { +BEGIN_C_LINKAGE #endif // __cplusplus TestFuncResult test_commander_cmd_success(void); @@ -13,7 +13,7 @@ TestFuncResult test_commander_cmd_out_buf_success(void); TestFuncResult test_commander_cmd_out_buf_failure(void); #ifdef __cplusplus -} +END_C_LINKAGE #endif // __cplusplus #endif // !TEST_SHELL_COMMANDER_H