Reformat common

This commit is contained in:
2025-12-29 21:41:04 +00:00
parent 31a22b74e9
commit ed72ccc139
4 changed files with 145 additions and 145 deletions

View File

@@ -7,20 +7,20 @@
#include <stdint.h> #include <stdint.h>
#if defined(WAPP_PLATFORM_C) && WAPP_PLATFORM_C_VERSION >= WAPP_PLATFORM_C11_VERSION && !defined(WAPP_PLATFORM_APPLE) #if defined(WAPP_PLATFORM_C) && WAPP_PLATFORM_C_VERSION >= WAPP_PLATFORM_C11_VERSION && !defined(WAPP_PLATFORM_APPLE)
#include <uchar.h> #include <uchar.h>
#if WAPP_PLATFORM_C_VERSION >= WAPP_PLATFORM_C23_VERSION #if WAPP_PLATFORM_C_VERSION >= WAPP_PLATFORM_C23_VERSION
#define c8 char8_t #define c8 char8_t
#else #else
#define c8 uint8_t #define c8 uint8_t
#endif // !WAPP_PLATFORM_C23_VERSION #endif // !WAPP_PLATFORM_C23_VERSION
#define c16 char16_t #define c16 char16_t
#define c32 char32_t #define c32 char32_t
#else #else
#define c8 uint8_t #define c8 uint8_t
#define c16 uint16_t #define c16 uint16_t
#define c32 uint32_t #define c32 uint32_t
#endif // !WAPP_PLATFORM_C #endif // !WAPP_PLATFORM_C
#define u8 uint8_t #define u8 uint8_t

View File

@@ -16,42 +16,42 @@ BEGIN_C_LINKAGE
#define wapp_static_assert(EXPR, MSG) extern char ASSERTION_FAILED[EXPR ? 1 : -1] #define wapp_static_assert(EXPR, MSG) extern char ASSERTION_FAILED[EXPR ? 1 : -1]
#ifndef WAPP_NO_RUNTIME_ASSERT #ifndef WAPP_NO_RUNTIME_ASSERT
#define wapp_runtime_assert(EXPR, MSG) __wapp_runtime_assert(EXPR, MSG) #define wapp_runtime_assert(EXPR, MSG) __wapp_runtime_assert(EXPR, MSG)
#else #else
#define wapp_runtime_assert(EXPR, MSG) #define wapp_runtime_assert(EXPR, MSG)
#endif #endif
#ifdef WAPP_DEBUG_ASSERT #ifdef WAPP_DEBUG_ASSERT
#define wapp_debug_assert(EXPR, MSG) wapp_runtime_assert(EXPR, MSG) #define wapp_debug_assert(EXPR, MSG) wapp_runtime_assert(EXPR, MSG)
#else #else
#define wapp_debug_assert(EXPR, MSG) #define wapp_debug_assert(EXPR, MSG)
#endif #endif
#ifdef WAPP_PLATFORM_WINDOWS #ifdef WAPP_PLATFORM_WINDOWS
#define __wapp_runtime_assert(EXPR, MSG) do { \ #define __wapp_runtime_assert(EXPR, MSG) do { \
__pragma(warning(push)) \ __pragma(warning(push)) \
__pragma(warning(disable:4127)) \ __pragma(warning(disable:4127)) \
if (!(EXPR)) { \ if (!(EXPR)) { \
__pragma(warning(pop)) \ __pragma(warning(pop)) \
__runtime_assert_failed(EXPR, MSG); \ __runtime_assert_failed(EXPR, MSG); \
} \ } \
} while(false) } while(false)
#else #else
#define __wapp_runtime_assert(EXPR, MSG) do { \ #define __wapp_runtime_assert(EXPR, MSG) do { \
if (!(EXPR)) { \ if (!(EXPR)) { \
__runtime_assert_failed(EXPR, MSG); \ __runtime_assert_failed(EXPR, MSG); \
} \ } \
} while(false) } while(false)
#endif // !WAPP_PLATFORM_WINDOWS #endif // !WAPP_PLATFORM_WINDOWS
#define __runtime_assert_failed(EXPR, MSG) do { \ #define __runtime_assert_failed(EXPR, MSG) do { \
fprintf( \ fprintf( \
stderr, \ stderr, \
"%s:%d (In function `%s`): Assertion failed (%" PRIu32 ")\nDiagnostic: %s\n\n", \ "%s:%d (In function `%s`): Assertion failed (%" PRIu32 ")\nDiagnostic: %s\n\n", \
__FILE__, __LINE__, __func__, \ __FILE__, __LINE__, __func__, \
EXPR, MSG \ EXPR, MSG \
); \ ); \
abort(); \ abort(); \
} while(false) } while(false)
#ifdef WAPP_PLATFORM_CPP #ifdef WAPP_PLATFORM_CPP

View File

@@ -16,35 +16,35 @@ BEGIN_C_LINKAGE
#define PiB(SIZE) (((u64)SIZE) << 50) #define PiB(SIZE) (((u64)SIZE) << 50)
#define EiB(SIZE) (((u64)SIZE) << 60) #define EiB(SIZE) (((u64)SIZE) << 60)
#define KB(SIZE) (((u64)SIZE) * 1000llu) #define KB(SIZE) (((u64)SIZE) * 1000llu)
#define MB(SIZE) (KB(SIZE) * 1000llu) #define MB(SIZE) (KB(SIZE) * 1000llu)
#define GB(SIZE) (MB(SIZE) * 1000llu) #define GB(SIZE) (MB(SIZE) * 1000llu)
#define TB(SIZE) (GB(SIZE) * 1000llu) #define TB(SIZE) (GB(SIZE) * 1000llu)
#define PB(SIZE) (TB(SIZE) * 1000llu) #define PB(SIZE) (TB(SIZE) * 1000llu)
#define EB(SIZE) (PB(SIZE) * 1000llu) #define EB(SIZE) (PB(SIZE) * 1000llu)
#define wapp_misc_utils_padding_size(SIZE) u8 reserved_padding[sizeof(void *) - ((SIZE) % sizeof(void *))] #define wapp_misc_utils_padding_size(SIZE) u8 reserved_padding[sizeof(void *) - ((SIZE) % sizeof(void *))]
#define U64_RSHIFT_OR_1(X) (((u64)X) | (((u64)X) >> 1)) #define U64_RSHIFT_OR_1(X) (((u64)X) | (((u64)X) >> 1))
#define U64_RSHIFT_OR_2(X) (((u64)X) | (((u64)X) >> 2)) #define U64_RSHIFT_OR_2(X) (((u64)X) | (((u64)X) >> 2))
#define U64_RSHIFT_OR_4(X) (((u64)X) | (((u64)X) >> 4)) #define U64_RSHIFT_OR_4(X) (((u64)X) | (((u64)X) >> 4))
#define U64_RSHIFT_OR_8(X) (((u64)X) | (((u64)X) >> 8)) #define U64_RSHIFT_OR_8(X) (((u64)X) | (((u64)X) >> 8))
#define U64_RSHIFT_OR_16(X) (((u64)X) | (((u64)X) >> 16)) #define U64_RSHIFT_OR_16(X) (((u64)X) | (((u64)X) >> 16))
#define U64_RSHIFT_OR_32(X) (((u64)X) | (((u64)X) >> 32)) #define U64_RSHIFT_OR_32(X) (((u64)X) | (((u64)X) >> 32))
#define wapp_misc_utils_u64_round_up_pow2(X) ( \ #define wapp_misc_utils_u64_round_up_pow2(X) ( \
( \ ( \
U64_RSHIFT_OR_32( \ U64_RSHIFT_OR_32( \
U64_RSHIFT_OR_16( \ U64_RSHIFT_OR_16( \
U64_RSHIFT_OR_8( \ U64_RSHIFT_OR_8( \
U64_RSHIFT_OR_4( \ U64_RSHIFT_OR_4( \
U64_RSHIFT_OR_2( \ U64_RSHIFT_OR_2( \
U64_RSHIFT_OR_1(X - 1) \ U64_RSHIFT_OR_1(X - 1) \
) \ ) \
) \ ) \
) \ ) \
) \ ) \
) \ ) \
) + 1 \ ) + 1 \
) )
#ifdef WAPP_PLATFORM_CPP #ifdef WAPP_PLATFORM_CPP

View File

@@ -4,111 +4,111 @@
#define PLATFORM_H #define PLATFORM_H
#if defined(__ANDROID__) #if defined(__ANDROID__)
#define WAPP_PLATFORM_ANDROID #define WAPP_PLATFORM_ANDROID
#define WAPP_PLATFORM_POSIX #define WAPP_PLATFORM_POSIX
#elif defined(__FreeBSD__) #elif defined(__FreeBSD__)
#define WAPP_PLATFORM_FREE_BSD #define WAPP_PLATFORM_FREE_BSD
#define WAPP_PLATFORM_BSD #define WAPP_PLATFORM_BSD
#define WAPP_PLATFORM_POSIX #define WAPP_PLATFORM_POSIX
#elif defined(__NetBSD__) #elif defined(__NetBSD__)
#define WAPP_PLATFORM_NET_BSD #define WAPP_PLATFORM_NET_BSD
#define WAPP_PLATFORM_BSD #define WAPP_PLATFORM_BSD
#define WAPP_PLATFORM_POSIX #define WAPP_PLATFORM_POSIX
#elif defined(__OpenBSD__) #elif defined(__OpenBSD__)
#define WAPP_PLATFORM_OPEN_BSD #define WAPP_PLATFORM_OPEN_BSD
#define WAPP_PLATFORM_BSD #define WAPP_PLATFORM_BSD
#define WAPP_PLATFORM_POSIX #define WAPP_PLATFORM_POSIX
#elif defined(__DragonFly__) #elif defined(__DragonFly__)
#define WAPP_PLATFORM_DRAGON_FLY #define WAPP_PLATFORM_DRAGON_FLY
#define WAPP_PLATFORM_BSD #define WAPP_PLATFORM_BSD
#define WAPP_PLATFORM_POSIX #define WAPP_PLATFORM_POSIX
#elif defined(__bsdi__) #elif defined(__bsdi__)
#define WAPP_PLATFORM_BSD #define WAPP_PLATFORM_BSD
#define WAPP_PLATFORM_POSIX #define WAPP_PLATFORM_POSIX
#elif defined(__linux__) || defined(linux) || defined(__linux) || defined(__gnu_linux__) #elif defined(__linux__) || defined(linux) || defined(__linux) || defined(__gnu_linux__)
#define WAPP_PLATFORM_LINUX #define WAPP_PLATFORM_LINUX
#define WAPP_PLATFORM_POSIX #define WAPP_PLATFORM_POSIX
#elif defined(__GNU__) || defined(__gnu_hurd__) #elif defined(__GNU__) || defined(__gnu_hurd__)
#define WAPP_PLATFORM_GNU #define WAPP_PLATFORM_GNU
#define WAPP_PLATFORM_POSIX #define WAPP_PLATFORM_POSIX
#elif defined(__APPLE__) || defined(__MACH__) #elif defined(__APPLE__) || defined(__MACH__)
#include <TargetConditionals.h> #include <TargetConditionals.h>
#if TARGET_OS_IPHONE #if TARGET_OS_IPHONE
#define WAPP_PLATFORM_IOS #define WAPP_PLATFORM_IOS
#define WAPP_PLATFORM_APPLE #define WAPP_PLATFORM_APPLE
#define WAPP_PLATFORM_POSIX #define WAPP_PLATFORM_POSIX
#elif TARGET_OS_MAC #elif TARGET_OS_MAC
#define WAPP_PLATFORM_MACOS #define WAPP_PLATFORM_MACOS
#define WAPP_PLATFORM_APPLE #define WAPP_PLATFORM_APPLE
#define WAPP_PLATFORM_POSIX #define WAPP_PLATFORM_POSIX
#else #else
#error "Unrecognised Apple platform" #error "Unrecognised Apple platform"
#endif #endif
#elif defined(_WIN64) #elif defined(_WIN64)
#define WAPP_PLATFORM_WINDOWS64 #define WAPP_PLATFORM_WINDOWS64
#define WAPP_PLATFORM_WINDOWS #define WAPP_PLATFORM_WINDOWS
#elif defined(_WIN32) #elif defined(_WIN32)
#define WAPP_PLATFORM_WINDOWS32 #define WAPP_PLATFORM_WINDOWS32
#define WAPP_PLATFORM_WINDOWS #define WAPP_PLATFORM_WINDOWS
#elif defined(__CYGWIN__) #elif defined(__CYGWIN__)
#define WAPP_PLATFORM_CYGWIN #define WAPP_PLATFORM_CYGWIN
#define WAPP_PLATFORM_WINDOWS #define WAPP_PLATFORM_WINDOWS
#elif defined(__unix__) || defined(__unix) #elif defined(__unix__) || defined(__unix)
#define WAPP_PLATFORM_UNIX #define WAPP_PLATFORM_UNIX
#define WAPP_PLATFORM_POSIX #define WAPP_PLATFORM_POSIX
#else #else
#error "Unrecognised platform" #error "Unrecognised platform"
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus
#define WAPP_PLATFORM_CPP #define WAPP_PLATFORM_CPP
#define WAPP_PLATFORM_CPP_VERSION __cplusplus #define WAPP_PLATFORM_CPP_VERSION __cplusplus
#define WAPP_PLATFORM_CPP98_VERSION 199711L #define WAPP_PLATFORM_CPP98_VERSION 199711L
#define WAPP_PLATFORM_CPP11_VERSION 201103L #define WAPP_PLATFORM_CPP11_VERSION 201103L
#define WAPP_PLATFORM_CPP14_VERSION 201402L #define WAPP_PLATFORM_CPP14_VERSION 201402L
#define WAPP_PLATFORM_CPP17_VERSION 201703L #define WAPP_PLATFORM_CPP17_VERSION 201703L
#define WAPP_PLATFORM_CPP20_VERSION 202002L #define WAPP_PLATFORM_CPP20_VERSION 202002L
#define WAPP_PLATFORM_CPP23_VERSION 202302L #define WAPP_PLATFORM_CPP23_VERSION 202302L
#if WAPP_PLATFORM_CPP_VERSION == WAPP_PLATFORM_CPP98_VERSION #if WAPP_PLATFORM_CPP_VERSION == WAPP_PLATFORM_CPP98_VERSION
#define WAPP_PLATFORM_CPP98 #define WAPP_PLATFORM_CPP98
#elif WAPP_PLATFORM_CPP_VERSION == WAPP_PLATFORM_CPP11_VERSION #elif WAPP_PLATFORM_CPP_VERSION == WAPP_PLATFORM_CPP11_VERSION
#define WAPP_PLATFORM_CPP11 #define WAPP_PLATFORM_CPP11
#elif WAPP_PLATFORM_CPP_VERSION == WAPP_PLATFORM_CPP14_VERSION #elif WAPP_PLATFORM_CPP_VERSION == WAPP_PLATFORM_CPP14_VERSION
#define WAPP_PLATFORM_CPP14 #define WAPP_PLATFORM_CPP14
#elif WAPP_PLATFORM_CPP_VERSION == WAPP_PLATFORM_CPP17_VERSION #elif WAPP_PLATFORM_CPP_VERSION == WAPP_PLATFORM_CPP17_VERSION
#define WAPP_PLATFORM_CPP17 #define WAPP_PLATFORM_CPP17
#elif WAPP_PLATFORM_CPP_VERSION == WAPP_PLATFORM_CPP20_VERSION #elif WAPP_PLATFORM_CPP_VERSION == WAPP_PLATFORM_CPP20_VERSION
#define WAPP_PLATFORM_CPP20 #define WAPP_PLATFORM_CPP20
#elif WAPP_PLATFORM_CPP_VERSION == WAPP_PLATFORM_CPP23_VERSION #elif WAPP_PLATFORM_CPP_VERSION == WAPP_PLATFORM_CPP23_VERSION
#define WAPP_PLATFORM_CPP23 #define WAPP_PLATFORM_CPP23
#else #else
#error "Unrecognised C++ version" #error "Unrecognised C++ version"
#endif #endif
#else #else
#define WAPP_PLATFORM_C #define WAPP_PLATFORM_C
#if defined(__STDC_VERSION__) #if defined(__STDC_VERSION__)
#define WAPP_PLATFORM_C_VERSION __STDC_VERSION__ #define WAPP_PLATFORM_C_VERSION __STDC_VERSION__
#define WAPP_PLATFORM_C99_VERSION 199901L #define WAPP_PLATFORM_C99_VERSION 199901L
#define WAPP_PLATFORM_C11_VERSION 201112L #define WAPP_PLATFORM_C11_VERSION 201112L
#define WAPP_PLATFORM_C17_VERSION 201710L #define WAPP_PLATFORM_C17_VERSION 201710L
#define WAPP_PLATFORM_C23_VERSION 202311L #define WAPP_PLATFORM_C23_VERSION 202311L
#if WAPP_PLATFORM_C_VERSION == WAPP_PLATFORM_C99_VERSION #if WAPP_PLATFORM_C_VERSION == WAPP_PLATFORM_C99_VERSION
#define WAPP_PLATFORM_C99 #define WAPP_PLATFORM_C99
#elif WAPP_PLATFORM_C_VERSION == WAPP_PLATFORM_C11_VERSION #elif WAPP_PLATFORM_C_VERSION == WAPP_PLATFORM_C11_VERSION
#define WAPP_PLATFORM_C11 #define WAPP_PLATFORM_C11
#elif WAPP_PLATFORM_C_VERSION == WAPP_PLATFORM_C17_VERSION #elif WAPP_PLATFORM_C_VERSION == WAPP_PLATFORM_C17_VERSION
#define WAPP_PLATFORM_C17 #define WAPP_PLATFORM_C17
#elif WAPP_PLATFORM_C_VERSION == WAPP_PLATFORM_C23_VERSION #elif WAPP_PLATFORM_C_VERSION == WAPP_PLATFORM_C23_VERSION
#define WAPP_PLATFORM_C23 #define WAPP_PLATFORM_C23
#else #else
#error "Unrecognised C version" #error "Unrecognised C version"
#endif #endif
#else #else
#define WAPP_PLATFORM_C89 #define WAPP_PLATFORM_C89
#endif #endif
#endif // !__cplusplus #endif // !__cplusplus
#endif // !PLATFORM_H #endif // !PLATFORM_H