Switch to using WAPP_PLATFORM_CPP instead of __cplusplus

This commit is contained in:
Abdelrahman Said 2025-04-20 19:52:33 +01:00
parent 494bbeb398
commit b884d0e6a6
26 changed files with 114 additions and 98 deletions

View File

@ -1,6 +1,7 @@
#ifndef ALIASES_H
#define ALIASES_H
#include "../platform/platform.h"
#include <stdint.h>
#define c8 uint8_t
@ -28,10 +29,10 @@
#define internal static
#define persistent static
#ifdef __cplusplus
#ifdef WAPP_PLATFORM_CPP
#define class_mem static
#define BEGIN_C_LINKAGE extern "C" {
#define END_C_LINKAGE }
#endif // __cplusplus
#endif // WAPP_PLATFORM_CPP
#endif // !ALIASES_H

View File

@ -2,10 +2,11 @@
#define ARRAY_H
#include "../../common/aliases/aliases.h"
#include "../../common/platform/platform.h"
#ifdef __cplusplus
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // !__cplusplus
#endif // !WAPP_PLATFORM_CPP
typedef struct int_array IntArray;
struct int_array {
@ -45,8 +46,8 @@ struct int_array {
})
#define wapp_int_array_with_capacity(CAPACITY) ((IntArray){.items = (int[CAPACITY]){0}, .count = 0, .capacity = CAPACITY})
#ifdef __cplusplus
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // !__cplusplus
#endif // !WAPP_PLATFORM_CPP
#endif // !ARRAY_H

View File

@ -2,11 +2,12 @@
#define MEM_ALLOCATOR_H
#include "../../../common/aliases/aliases.h"
#include "../../../common/platform/platform.h"
#include <string.h>
#ifdef __cplusplus
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // __cplusplus
#endif // WAPP_PLATFORM_CPP
typedef void *(MemAllocFunc)(u64 size, void *alloc_obj);
typedef void *(MemAllocAlignedFunc)(u64 size, u64 alignment, void *alloc_obj);
@ -35,8 +36,8 @@ void *wapp_mem_allocator_realloc_aligned(const Allocator *allocator, void *ptr,
u64 new_size, u64 alignment);
void wapp_mem_allocator_free(const Allocator *allocator, void **ptr, u64 size);
#ifdef __cplusplus
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // __cplusplus
#endif // WAPP_PLATFORM_CPP
#endif // !MEM_ALLOCATOR_H

View File

@ -2,12 +2,13 @@
#define MEM_ARENA_H
#include "../../../common/aliases/aliases.h"
#include "../../../common/platform/platform.h"
#include "../../os/mem/mem_os.h"
#include <stdbool.h>
#ifdef __cplusplus
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // __cplusplus
#endif // WAPP_PLATFORM_CPP
typedef struct arena Arena;
@ -33,8 +34,8 @@ void *wapp_mem_arena_realloc_aligned(Arena *arena, void *ptr, u64 old_size, u64
void wapp_mem_arena_clear(Arena *arena);
void wapp_mem_arena_destroy(Arena **arena);
#ifdef __cplusplus
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // __cplusplus
#endif // WAPP_PLATFORM_CPP
#endif // !MEM_ARENA_H

View File

@ -2,13 +2,14 @@
#define MEM_ARENA_ALLOCATOR_H
#include "../../../common/aliases/aliases.h"
#include "../../../common/platform/platform.h"
#include "../allocator/mem_allocator.h"
#include "../../os/mem/mem_os.h"
#include <stdbool.h>
#ifdef __cplusplus
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // __cplusplus
#endif // WAPP_PLATFORM_CPP
#define wapp_mem_arena_allocator_init(base_capacity) \
(wapp_mem_arena_allocator_init_custom(base_capacity, WAPP_MEM_ALLOC_RESERVE, false))
@ -34,8 +35,8 @@ Allocator wapp_mem_arena_allocator_init_custom(u64 base_capacity, MemAllocFlags
void wapp_mem_arena_allocator_clear(Allocator *allocator);
void wapp_mem_arena_allocator_destroy(Allocator *allocator);
#ifdef __cplusplus
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // __cplusplus
#endif // WAPP_PLATFORM_CPP
#endif // !MEM_ARENA_ALLOCATOR_H

View File

@ -2,15 +2,16 @@
#define MEM_UTILS_H
#include "../../../common/aliases/aliases.h"
#include "../../../common/platform/platform.h"
#ifdef __cplusplus
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // __cplusplus
#endif // WAPP_PLATFORM_CPP
void *wapp_mem_util_align_forward(void *ptr, u64 alignment);
#ifdef __cplusplus
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // __cplusplus
#endif // WAPP_PLATFORM_CPP
#endif // !MEM_UTILS_H

View File

@ -6,9 +6,9 @@
#include "../../mem/allocator/mem_allocator.h"
#include "../../strings/str8/str8.h"
#ifdef __cplusplus
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // __cplusplus
#endif // WAPP_PLATFORM_CPP
#ifdef WAPP_PLATFORM_POSIX
#define PATH_SEP '/'
@ -31,8 +31,8 @@ enum {
u32 wapp_cpath_join_path(Str8 *dst, const Str8List *parts);
Str8 *dirup(const Allocator *allocator, Str8RO *path, u64 levels);
#ifdef __cplusplus
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // __cplusplus
#endif // WAPP_PLATFORM_CPP
#endif // !CPATH_H

View File

@ -4,9 +4,9 @@
#include "../../../common/aliases/aliases.h"
#include "../../../common/platform/platform.h"
#ifdef __cplusplus
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // __cplusplus
#endif // WAPP_PLATFORM_CPP
#include "mem_os_ops.h"
@ -25,8 +25,8 @@ void wapp_mem_util_free(void *ptr, u64 size);
external void *mem_util_allocate(void *addr, u64 size, MemAccess access, MemAllocFlags flags, MemInitType type);
external void mem_util_free(void *ptr, u64 size);
#ifdef __cplusplus
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // __cplusplus
#endif // WAPP_PLATFORM_CPP
#endif // !MEM_OS_H

View File

@ -1,9 +1,11 @@
#ifndef MEM_OS_OPS_H
#define MEM_OS_OPS_H
#ifdef __cplusplus
#include "../../../common/platform/platform.h"
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // __cplusplus
#endif // WAPP_PLATFORM_CPP
typedef enum mem_access {
WAPP_MEM_ACCESS_NONE,
@ -19,8 +21,8 @@ typedef enum mem_init_type {
WAPP_MEM_INIT_INITIALISED,
} MemInitType;
#ifdef __cplusplus
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // __cplusplus
#endif // WAPP_PLATFORM_CPP
#endif // !MEM_OS_OPS_H

View File

@ -3,9 +3,9 @@
#include "../../../../common/platform/platform.h"
#ifdef __cplusplus
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // !__cplusplus
#endif // !WAPP_PLATFORM_CPP
#ifdef WAPP_PLATFORM_POSIX
@ -26,8 +26,8 @@ typedef enum mem_alloc_flags {
#endif // !WAPP_PLATFORM_POSIX
#ifdef __cplusplus
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // !__cplusplus
#endif // !WAPP_PLATFORM_CPP
#endif // !MEM_OS_POSIX_H

View File

@ -3,9 +3,9 @@
#include "../../../../common/platform/platform.h"
#ifdef __cplusplus
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // !__cplusplus
#endif // !WAPP_PLATFORM_CPP
#ifdef WAPP_PLATFORM_WINDOWS
@ -20,8 +20,8 @@ typedef enum mem_alloc_flags {
#endif // !WAPP_PLATFORM_WINDOWS
#ifdef __cplusplus
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // !__cplusplus
#endif // !WAPP_PLATFORM_CPP
#endif // !MEM_OS_WIN_H

View File

@ -3,14 +3,15 @@
#include "commander_output.h"
#include "../../../../common/aliases/aliases.h"
#include "../../../../common/platform/platform.h"
#include "../../../strings/str8/str8.h"
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#ifdef __cplusplus
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // __cplusplus
#endif // WAPP_PLATFORM_CPP
#define CMD_NO_EXIT(ERR) ((CMDResult){.exited = false, .exit_code = EXIT_FAILURE, .error = ERR})
@ -18,8 +19,8 @@ CMDResult wapp_shell_commander_execute(CMDOutHandling out_handling, Str8 *out_bu
external CMDError get_output_status(FILE *fp, i32 *status_out);
#ifdef __cplusplus
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // __cplusplus
#endif // WAPP_PLATFORM_CPP
#endif // !COMMANDER_H

View File

@ -5,9 +5,9 @@
#include "../../../../common/platform/platform.h"
#include <stdbool.h>
#ifdef __cplusplus
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // __cplusplus
#endif // WAPP_PLATFORM_CPP
typedef enum {
SHELL_OUTPUT_DISCARD,
@ -36,8 +36,8 @@ struct commander_result {
#endif // !WAPP_PLATFORM_WINDOWS
};
#ifdef __cplusplus
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // __cplusplus
#endif // WAPP_PLATFORM_CPP
#endif // !COMMANDER_OUTPUT_H

View File

@ -3,19 +3,20 @@
#include "terminal_colours.h"
#include "../../../../common/aliases/aliases.h"
#include "../../../../common/platform/platform.h"
#include "../../../strings/str8/str8.h"
#ifdef __cplusplus
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // __cplusplus
#endif // WAPP_PLATFORM_CPP
void wapp_shell_termcolour_print_text(Str8RO *text, TerminalColour colour);
void wapp_shell_termcolour_clear_colour(void);
external void print_coloured_text(Str8RO *text, TerminalColour colour);
#ifdef __cplusplus
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // __cplusplus
#endif // WAPP_PLATFORM_CPP
#endif // !TERM_COLOUR_H

View File

@ -1,9 +1,11 @@
#ifndef TERMINAL_COLOURS_H
#define TERMINAL_COLOURS_H
#ifdef __cplusplus
#include "../../../../common/platform/platform.h"
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // __cplusplus
#endif // WAPP_PLATFORM_CPP
typedef enum {
WAPP_TERM_COLOUR_FG_BLACK,
@ -27,8 +29,8 @@ typedef enum {
COUNT_TERM_COLOUR,
} TerminalColour;
#ifdef __cplusplus
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // __cplusplus
#endif // WAPP_PLATFORM_CPP
#endif // !TERMINAL_COLOURS_H

View File

@ -2,14 +2,15 @@
#define STR8_H
#include "../../../common/aliases/aliases.h"
#include "../../../common/platform/platform.h"
#include "../../../containers/dbl_list/dbl_list.h"
#include "../../mem/allocator/mem_allocator.h"
#include <string.h>
#include <stdbool.h>
#ifdef __cplusplus
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // !__cplusplus
#endif // !WAPP_PLATFORM_CPP
typedef struct str8 Str8;
struct str8 {
@ -95,8 +96,8 @@ Str8 *wapp_str8_join(const Allocator *allocator, const Str8List *list, Str8R
#define wapp_str8_node_from_str8(STRING) wapp_str8_list_node(&(STRING))
u64 wapp_str8_list_total_size(const Str8List *list);
#ifdef __cplusplus
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // !__cplusplus
#endif // !WAPP_PLATFORM_CPP
#endif // !STR8_H

View File

@ -1,5 +1,6 @@
#include "xorshift.h"
#include "../../common/aliases/aliases.h"
#include <assert.h>
#include <stdbool.h>
#include <stdlib.h>
#include <time.h>

View File

@ -2,10 +2,11 @@
#define XORSHIFT_H
#include "../../common/aliases/aliases.h"
#include "../../common/platform/platform.h"
#ifdef __cplusplus
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // __cplusplus
#endif // WAPP_PLATFORM_CPP
typedef struct xor_256_state XOR256State;
struct xor_256_state {
@ -20,8 +21,8 @@ u64 wapp_prng_xorshift_256(XOR256State *state);
u64 wapp_prng_xorshift_256ss(XOR256State *state);
u64 wapp_prng_xorshift_256p(XOR256State *state);
#ifdef __cplusplus
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // __cplusplus
#endif // WAPP_PLATFORM_CPP
#endif // !XORSHIFT_H

View File

@ -6,9 +6,9 @@
#include "../../core/strings/str8/str8.h"
#include <stdbool.h>
#ifdef __cplusplus
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // __cplusplus
#endif // WAPP_PLATFORM_CPP
#define wapp_tester_result(PASSED) ((TestFuncResult){.name = wapp_str8_lit_ro(__func__), .passed = PASSED})
#define wapp_tester_run_tests(...) run_tests(__VA_ARGS__, NULL)
@ -27,8 +27,8 @@ typedef TestFuncResult(TestFunc)(void);
void run_tests(TestFunc *func1, ...);
#ifdef __cplusplus
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // __cplusplus
#endif // WAPP_PLATFORM_CPP
#endif // !TESTER_H

View File

@ -2,11 +2,12 @@
#define UUID_H
#include "../common/aliases/aliases.h"
#include "../common/platform/platform.h"
#include "../core/strings/str8/str8.h"
#ifdef __cplusplus
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // __cplusplus
#endif // WAPP_PLATFORM_CPP
#define UUID_BUF_LENGTH 48
#define WAPP_UUID_SPEC WAPP_STR8_SPEC
@ -27,8 +28,8 @@ struct uuid {
// If the pointer is NULL, it skips initialisation.
UUID *wapp_uuid_init_uuid4(UUID *uuid);
#ifdef __cplusplus
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // __cplusplus
#endif // WAPP_PLATFORM_CPP
#endif // !UUID_H

View File

@ -3,14 +3,14 @@
#include "wapp.h"
#ifdef __cplusplus
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // __cplusplus
#endif // WAPP_PLATFORM_CPP
TestFuncResult test_arena_allocator(void);
#ifdef __cplusplus
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // __cplusplus
#endif // WAPP_PLATFORM_CPP
#endif // !TEST_ALLOCATOR_H

View File

@ -3,9 +3,9 @@
#include "wapp.h"
#ifdef __cplusplus
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // __cplusplus
#endif // WAPP_PLATFORM_CPP
TestFuncResult test_arena_init(void);
TestFuncResult test_arena_init_succeeds_when_reserving_very_large_size(void);
@ -16,8 +16,8 @@ TestFuncResult test_arena_realloc_smaller_size(void);
TestFuncResult test_arena_clear(void);
TestFuncResult test_arena_destroy(void);
#ifdef __cplusplus
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // __cplusplus
#endif // WAPP_PLATFORM_CPP
#endif // !TEST_ARENA_H

View File

@ -3,16 +3,16 @@
#include "wapp.h"
#ifdef __cplusplus
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // __cplusplus
#endif // WAPP_PLATFORM_CPP
TestFuncResult test_cpath_join_path(void);
TestFuncResult test_cpath_dirname(void);
TestFuncResult test_cpath_dirup(void);
#ifdef __cplusplus
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // __cplusplus
#endif // WAPP_PLATFORM_CPP
#endif // !TEST_CPATH_H

View File

@ -3,17 +3,17 @@
#include "wapp.h"
#ifdef __cplusplus
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // __cplusplus
#endif // WAPP_PLATFORM_CPP
TestFuncResult test_commander_cmd_success(void);
TestFuncResult test_commander_cmd_failure(void);
TestFuncResult test_commander_cmd_out_buf_success(void);
TestFuncResult test_commander_cmd_out_buf_failure(void);
#ifdef __cplusplus
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // __cplusplus
#endif // WAPP_PLATFORM_CPP
#endif // !TEST_SHELL_COMMANDER_H

View File

@ -3,9 +3,9 @@
#include "wapp.h"
#ifdef __cplusplus
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // __cplusplus
#endif // WAPP_PLATFORM_CPP
TestFuncResult test_str8_lit(void);
TestFuncResult test_str8_lit_ro(void);
@ -33,8 +33,8 @@ TestFuncResult test_str8_rsplit(void);
TestFuncResult test_str8_rsplit_with_max(void);
TestFuncResult test_str8_join(void);
#ifdef __cplusplus
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // __cplusplus
#endif // WAPP_PLATFORM_CPP
#endif // !TEST_STR8_H

View File

@ -3,9 +3,9 @@
#include "wapp.h"
#ifdef __cplusplus
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // __cplusplus
#endif // WAPP_PLATFORM_CPP
TestFuncResult test_str8_list_get(void);
TestFuncResult test_str8_list_push_front(void);
@ -16,8 +16,8 @@ TestFuncResult test_str8_list_pop_back(void);
TestFuncResult test_str8_list_remove(void);
TestFuncResult test_str8_list_empty(void);
#ifdef __cplusplus
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // __cplusplus
#endif // WAPP_PLATFORM_CPP
#endif // !TEST_STR8_LIST_H