From d82af845bc81c2b6722729db7ab1a21163e5ebb5 Mon Sep 17 00:00:00 2001 From: Ed_ Date: Sat, 8 Feb 2025 23:53:35 -0500 Subject: [PATCH] forgot about stb_sprintf.h... --- bin/build.ps1 | 8 ++- code/base/context_cracking.h | 12 ++++- code/base/linkage.h | 8 +-- code/base/logger.h | 2 - code/base/strings.c | 8 ++- code/base/strings.h | 1 - code/mdesk/mdesk.h | 3 ++ code/metadesk.c | 6 +++ code/metadesk.h | 3 ++ code/os/win32/os_win32.c | 8 +-- tests/c11_sanity.c | 0 tests/code_sanity.c | 5 ++ .../{cpp_build_test.cpp => cpp17_sanity.cpp} | 0 third_party/stb/stb_sprintf.h | 52 +++++++++---------- 14 files changed, 67 insertions(+), 49 deletions(-) create mode 100644 tests/c11_sanity.c rename tests/{cpp_build_test.cpp => cpp17_sanity.cpp} (100%) diff --git a/bin/build.ps1 b/bin/build.ps1 index 2420bd9..000c68f 100644 --- a/bin/build.ps1 +++ b/bin/build.ps1 @@ -134,11 +134,9 @@ if ($code_sanity) $linker_args = @() $linker_args += $flag_link_win_subsystem_console - $path_base = join-path $path_code base - - $includes = @( $path_base ) - $unit = join-path $path_code 'metadesk.c' - $executable = join-path $path_build 'metadesk.lib' + $includes = @( $path_code, $path_root ) + $unit = join-path $path_tests 'code_sanity.c' + $executable = join-path $path_build 'code_sanity.exe' $result = build-simple $path_build $includes $compiler_args $linker_args $unit $executable } diff --git a/code/base/context_cracking.h b/code/base/context_cracking.h index 0002328..494de5d 100644 --- a/code/base/context_cracking.h +++ b/code/base/context_cracking.h @@ -9,8 +9,16 @@ # define BUILD_DEBUG 1 #endif -#if ! defined(BUILD_SUPPLEMENTARY_UNIT) -# define BUILD_SUPPLEMENTARY_UNIT 0 +#if ! defined(BUILD_STATIC) +# define BUILD_STATIC 0 +#endif + +#if ! defined(BUILD_DYANMIC) +# define BUILD_DYANMIC 0 +#endif + +#if ! defined(BUILD_API_EXPORT) +# define BUILD_API_EXPORT 0 #endif #if !defined(BUILD_ENTRY_DEFINING_UNIT) diff --git a/code/base/linkage.h b/code/base/linkage.h index c313e84..4280ac5 100644 --- a/code/base/linkage.h +++ b/code/base/linkage.h @@ -5,8 +5,8 @@ #ifndef MD_API #if COMPILER_MSVC -# ifdef MD_DYN_LINK -# ifdef MD_DYN_EXPORT +# if BUILD_DYANMIC +# if BUILD_API_EXPORT # define MD_API __declspec(dllexport) # else # define MD_API __declspec(dllimport) @@ -15,7 +15,7 @@ # define MD_API // Empty for static builds # endif #else -# ifdef MD_DYN_LINK +# ifdef BUILD_DYANMIC # define MD_API __attribute__((visibility("default"))) # else # define MD_API // Empty for static builds @@ -36,7 +36,7 @@ #endif #ifndef global // Global variables -# if defined(MD_DYN_EXPORT) || defined(MD_STATIC_LINK) +# if BUILD_API_EXPORT || BUILD_STATIC # define global # else # define global static diff --git a/code/base/logger.h b/code/base/logger.h index c597742..48957ff 100644 --- a/code/base/logger.h +++ b/code/base/logger.h @@ -48,8 +48,6 @@ struct Log //////////////////////////////// //~ rjf: Log Creation/Selection - - Log* log_alloc(AllocatorInfo ainfo, U64 arena_block_size); void log_release(Log* log); MD_API void log_select (Log* log); diff --git a/code/base/strings.c b/code/base/strings.c index d59c709..6a7ffcb 100644 --- a/code/base/strings.c +++ b/code/base/strings.c @@ -6,13 +6,11 @@ # include "thread_context.h" //////////////////////////////// //~ rjf: Third Party Includes -#if !BUILD_SUPPLEMENTARY_UNIT # define STB_SPRINTF_IMPLEMENTATION -# define STB_SPRINTF_STATIC +# if BUILD_STATIC +# #define STB_SPRINTF_STATIC +# endif # include "third_party/stb/stb_sprintf.h" -// Note(Ed): We should inject when generating the library segmented or singleheader -#endif - #endif // Copyright (c) 2024 Epic Games Tools diff --git a/code/base/strings.h b/code/base/strings.h index 3f3665a..c922e88 100644 --- a/code/base/strings.h +++ b/code/base/strings.h @@ -15,7 +15,6 @@ //~ rjf: Third Party Includes # define STB_SPRINTF_DECORATE(name) md_##name # include "third_party/stb/stb_sprintf.h" -// Note(Ed): We should inject when generating the library segmented or singleheader #endif // Copyright (c) 2024 Epic Games Tools diff --git a/code/mdesk/mdesk.h b/code/mdesk/mdesk.h index ac40bbc..953fa0c 100644 --- a/code/mdesk/mdesk.h +++ b/code/mdesk/mdesk.h @@ -227,6 +227,9 @@ struct ParseResult typedef struct Context Context; struct Context { + // Currently, this is only relevant if the user is utilizing this library via bindings + // or they are not utilizing metadesk's hosted `entry_point` runtime + // Note: Only used so far as the first fallback if the user did not preset the thread_context's arenas // Otherwise it will just reserve its own Arena backed by chained virutal address space AllocatorInfo backing[2]; diff --git a/code/metadesk.c b/code/metadesk.c index 125b792..bad6ab1 100644 --- a/code/metadesk.c +++ b/code/metadesk.c @@ -5,6 +5,12 @@ #include "base/platform.c" +#define STB_SPRINTF_IMPLEMENTATION +#if BUILD_STATIC +# #define STB_SPRINTF_STATIC +#endif +#include "third_party/stb/stb_sprintf.h" + MD_NS_BEGIN #include "base/debug.c" diff --git a/code/metadesk.h b/code/metadesk.h index 7040754..8bbc112 100644 --- a/code/metadesk.h +++ b/code/metadesk.h @@ -10,6 +10,9 @@ #include "base/profiling.h" #include "base/namespace.h" +#define STB_SPRINTF_DECORATE(name) md_##name +#include "third_party/stb/stb_sprintf.h" + MD_NS_BEGIN #include "base/base_types.h" diff --git a/code/os/win32/os_win32.c b/code/os/win32/os_win32.c index 928a160..0965577 100644 --- a/code/os/win32/os_win32.c +++ b/code/os/win32/os_win32.c @@ -1267,19 +1267,19 @@ win32_exception_filter(EXCEPTION_POINTERS* exception_ptrs) const U32 max_frames = 32; if(idx == max_frames) { - buflen += wnsprintfW(buffer + buflen, ArrayCount(buffer) - buflen, L"..."); - break; + buflen += wnsprintfW(buffer + buflen, ArrayCount(buffer) - buflen, L"..."); + break; } if(!dbg_StackWalk64(image_type, process, thread, &frame, context, 0, dbg_SymFunctionTableAccess64, dbg_SymGetModuleBase64, 0)) { - break; + break; } U64 address = frame.AddrPC.Offset; if(address == 0) { - break; + break; } if(idx==0) diff --git a/tests/c11_sanity.c b/tests/c11_sanity.c new file mode 100644 index 0000000..e69de29 diff --git a/tests/code_sanity.c b/tests/code_sanity.c index 9c28426..3d3180a 100644 --- a/tests/code_sanity.c +++ b/tests/code_sanity.c @@ -4,5 +4,10 @@ int main() { + Context ctx; + init(& ctx); + + + deinit(& ctx); } diff --git a/tests/cpp_build_test.cpp b/tests/cpp17_sanity.cpp similarity index 100% rename from tests/cpp_build_test.cpp rename to tests/cpp17_sanity.cpp diff --git a/third_party/stb/stb_sprintf.h b/third_party/stb/stb_sprintf.h index 33423cf..490f8fc 100644 --- a/third_party/stb/stb_sprintf.h +++ b/third_party/stb/stb_sprintf.h @@ -151,25 +151,25 @@ PERFORMANCE vs MSVC 2008 32-/64-bit (GCC is even slower than MSVC): */ #if defined(__clang__) -# if defined(__has_feature) && defined(__has_attribute) -# if __has_feature(address_sanitizer) -# if __has_attribute(__no_sanitize__) -# define STBSP__ASAN __attribute__((__no_sanitize__("address"))) -# elif __has_attribute(__no_sanitize_address__) -# define STBSP__ASAN __attribute__((__no_sanitize_address__)) -# elif __has_attribute(__no_address_safety_analysis__) -# define STBSP__ASAN __attribute__((__no_address_safety_analysis__)) -# endif -# endif -# endif +# if defined(__has_feature) && defined(__has_attribute) +# if __has_feature(address_sanitizer) +# if __has_attribute(__no_sanitize__) +# define STBSP__ASAN __attribute__((__no_sanitize__("address"))) +# elif __has_attribute(__no_sanitize_address__) +# define STBSP__ASAN __attribute__((__no_sanitize_address__)) +# elif __has_attribute(__no_address_safety_analysis__) +# define STBSP__ASAN __attribute__((__no_address_safety_analysis__)) +# endif +# endif +# endif #elif defined(__GNUC__) && (__GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)) -# if defined(__SANITIZE_ADDRESS__) && __SANITIZE_ADDRESS__ -# define STBSP__ASAN __attribute__((__no_sanitize_address__)) -# endif +# if defined(__SANITIZE_ADDRESS__) && __SANITIZE_ADDRESS__ +# define STBSP__ASAN __attribute__((__no_sanitize_address__)) +# endif #elif defined(_MSC_VER) -# if defined(__SANITIZE_ADDRESS__) -# define STBSP__ASAN __declspec(no_sanitize_address) -# endif +# if defined(__SANITIZE_ADDRESS__) +# define STBSP__ASAN __declspec(no_sanitize_address) +# endif #endif #ifndef STBSP__ASAN @@ -177,16 +177,16 @@ PERFORMANCE vs MSVC 2008 32-/64-bit (GCC is even slower than MSVC): #endif #ifdef STB_SPRINTF_STATIC -#define STBSP__PUBLICDEC static STBSP__ASAN -#define STBSP__PUBLICDEF static STBSP__ASAN +# define STBSP__PUBLICDEC static STBSP__ASAN +# define STBSP__PUBLICDEF static STBSP__ASAN #else -#ifdef __cplusplus -#define STBSP__PUBLICDEC extern "C" STBSP__ASAN -#define STBSP__PUBLICDEF extern "C" STBSP__ASAN -#else -#define STBSP__PUBLICDEC extern STBSP__ASAN -#define STBSP__PUBLICDEF STBSP__ASAN -#endif +# ifdef __cplusplus +# define STBSP__PUBLICDEC extern "C" STBSP__ASAN +# define STBSP__PUBLICDEF extern "C" STBSP__ASAN +# else +# define STBSP__PUBLICDEC extern STBSP__ASAN +# define STBSP__PUBLICDEF STBSP__ASAN +# endif #endif #if defined(__has_attribute)