diff options
| author | Stefan Boberg <[email protected]> | 2025-11-07 14:49:13 +0100 |
|---|---|---|
| committer | GitHub Enterprise <[email protected]> | 2025-11-07 14:49:13 +0100 |
| commit | 24e43a913f29ac3b314354e8ce5175f135bcc64f (patch) | |
| tree | ca442937ceeb63461012b33a4576e9835099f106 /src/zencore/include | |
| parent | get oplog attachments (#622) (diff) | |
| download | zen-24e43a913f29ac3b314354e8ce5175f135bcc64f.tar.xz zen-24e43a913f29ac3b314354e8ce5175f135bcc64f.zip | |
switch to xmake for package management (#611)
This change removes our dependency on vcpkg for package management, in favour of bringing some code in-tree in the `thirdparty` folder as well as using the xmake build-in package management feature. For the latter, all the package definitions are maintained in the zen repo itself, in the `repo` folder.
It should now also be easier to build the project as it will no longer depend on having the right version of vcpkg installed, which has been a common problem for new people coming in to the codebase. Now you should only need xmake to build.
* Bumps xmake requirement on github runners to 2.9.9 to resolve an issue where xmake on Windows invokes cmake with `v144` toolchain which does not exist
* BLAKE3 is now in-tree at `thirdparty/blake3`
* cpr is now in-tree at `thirdparty/cpr`
* cxxopts is now in-tree at `thirdparty/cxxopts`
* fmt is now in-tree at `thirdparty/fmt`
* robin-map is now in-tree at `thirdparty/robin-map`
* ryml is now in-tree at `thirdparty/ryml`
* sol2 is now in-tree at `thirdparty/sol2`
* spdlog is now in-tree at `thirdparty/spdlog`
* utfcpp is now in-tree at `thirdparty/utfcpp`
* xmake package repo definitions is in `repo`
* implemented support for sanitizers. ASAN is supported on windows, TSAN, UBSAN, MSAN etc are supported on Linux/MacOS though I have not yet tested it extensively on MacOS
* the zencore encryption implementation also now supports using mbedTLS which is used on MacOS, though for now we still use openssl on Linux
* crashpad
* bumps libcurl to 8.11.0 (from 8.8.0) which should address a rare build upload bug
Diffstat (limited to 'src/zencore/include')
| -rw-r--r-- | src/zencore/include/zencore/memory/fmalloc.h | 47 | ||||
| -rw-r--r-- | src/zencore/include/zencore/memory/newdelete.h | 45 | ||||
| -rw-r--r-- | src/zencore/include/zencore/xxhash.h | 2 |
3 files changed, 76 insertions, 18 deletions
diff --git a/src/zencore/include/zencore/memory/fmalloc.h b/src/zencore/include/zencore/memory/fmalloc.h index 5b476429e..0c183cfd0 100644 --- a/src/zencore/include/zencore/memory/fmalloc.h +++ b/src/zencore/include/zencore/memory/fmalloc.h @@ -6,6 +6,53 @@ #include <zenbase/zenbase.h> +// Detect if any sanitizers are enabled. + +#if defined(__has_feature) +# if __has_feature(address_sanitizer) +# define ZEN_ADDRESS_SANITIZER 1 +# endif +# if __has_feature(thread_sanitizer) +# define ZEN_THREAD_SANITIZER 1 +# endif +# if __has_feature(memory_sanitizer) +# define ZEN_MEMORY_SANITIZER 1 +# endif +# if __has_feature(leak_sanitizer) +# define ZEN_LEAK_SANITIZER 1 +# endif +#elif defined(__SANITIZE_ADDRESS__) // For Windows +# define ZEN_ADDRESS_SANITIZER 1 +#endif + +#if !defined(ZEN_ADDRESS_SANITIZER) +# define ZEN_ADDRESS_SANITIZER 0 +#endif + +#if !defined(ZEN_THREAD_SANITIZER) +# define ZEN_THREAD_SANITIZER 0 +#endif + +#if !defined(ZEN_MEMORY_SANITIZER) +# define ZEN_MEMORY_SANITIZER 0 +#endif + +#if !defined(ZEN_LEAK_SANITIZER) +# define ZEN_LEAK_SANITIZER 0 +#endif + +// If sanitizers are enabled, we cannot override new/delete ourselves + +#if !defined(ZEN_OVERRIDE_NEW_DELETE) +# if ZEN_ADDRESS_SANITIZER || ZEN_THREAD_SANITIZER || ZEN_MEMORY_SANITIZER || ZEN_LEAK_SANITIZER +# define ZEN_OVERRIDE_NEW_DELETE 0 +# endif +#endif + +#if !defined(ZEN_OVERRIDE_NEW_DELETE) +# define ZEN_OVERRIDE_NEW_DELETE 1 +#endif + namespace zen { enum diff --git a/src/zencore/include/zencore/memory/newdelete.h b/src/zencore/include/zencore/memory/newdelete.h index 2ec92b91b..a5b65ccbb 100644 --- a/src/zencore/include/zencore/memory/newdelete.h +++ b/src/zencore/include/zencore/memory/newdelete.h @@ -2,18 +2,25 @@ #pragma once +// This header overrides global new/delete operators to route them through Zen's memory +// allocation system. This header should only be included once, from the program's main +// compilation unit + #include <zenbase/zenbase.h> +#include <zencore/memory/fmalloc.h> #include <new> -#if defined(_MSC_VER) -# if (_MSC_VER >= 1900) && !defined(__EDG__) -# define ZEN_RESTRICT __declspec(allocator) __declspec(restrict) +#if ZEN_OVERRIDE_NEW_DELETE + +# if defined(_MSC_VER) +# if (_MSC_VER >= 1900) && !defined(__EDG__) +# define ZEN_RESTRICT __declspec(allocator) __declspec(restrict) +# else +# define ZEN_RESTRICT __declspec(restrict) +# endif # else -# define ZEN_RESTRICT __declspec(restrict) +# define ZEN_RESTRICT # endif -#else -# define ZEN_RESTRICT -#endif ////////////////////////////////////////////////////////////////////////// @@ -29,13 +36,13 @@ void zen_free_aligned(void* p, size_t alignment) noexcept; ////////////////////////////////////////////////////////////////////////// -#if defined(_MSC_VER) && defined(_Ret_notnull_) && defined(_Post_writable_byte_size_) -# define zen_decl_new(n) [[nodiscard]] _VCRT_ALLOCATOR _Ret_notnull_ _Post_writable_byte_size_(n) -# define zen_decl_new_nothrow(n) [[nodiscard]] _VCRT_ALLOCATOR _Ret_maybenull_ _Success_(return != NULL) _Post_writable_byte_size_(n) -#else -# define zen_decl_new(n) [[nodiscard]] -# define zen_decl_new_nothrow(n) [[nodiscard]] -#endif +# if defined(_MSC_VER) && defined(_Ret_notnull_) && defined(_Post_writable_byte_size_) +# define zen_decl_new(n) [[nodiscard]] _VCRT_ALLOCATOR _Ret_notnull_ _Post_writable_byte_size_(n) +# define zen_decl_new_nothrow(n) [[nodiscard]] _VCRT_ALLOCATOR _Ret_maybenull_ _Success_(return != NULL) _Post_writable_byte_size_(n) +# else +# define zen_decl_new(n) [[nodiscard]] +# define zen_decl_new_nothrow(n) [[nodiscard]] +# endif void operator delete(void* p) noexcept @@ -87,7 +94,7 @@ operator new[](std::size_t n, const std::nothrow_t& tag) noexcept return zen_new_nothrow(n); } -#if (__cplusplus >= 201402L || _MSC_VER >= 1916) +# if (__cplusplus >= 201402L || _MSC_VER >= 1916) void operator delete(void* p, std::size_t n) noexcept { @@ -98,9 +105,9 @@ operator delete[](void* p, std::size_t n) noexcept { zen_free_size(p, n); }; -#endif +# endif -#if (__cplusplus > 201402L || defined(__cpp_aligned_new)) +# if (__cplusplus > 201402L || defined(__cpp_aligned_new)) void operator delete(void* p, std::align_val_t al) noexcept { @@ -152,7 +159,9 @@ operator new[](std::size_t n, std::align_val_t al, const std::nothrow_t&) noexce { return zen_new_aligned_nothrow(n, static_cast<size_t>(al)); } -#endif +# endif + +#endif // ZEN_OVERRIDE_NEW_DELETE // EASTL operator new diff --git a/src/zencore/include/zencore/xxhash.h b/src/zencore/include/zencore/xxhash.h index 1616e5f93..fc55b513b 100644 --- a/src/zencore/include/zencore/xxhash.h +++ b/src/zencore/include/zencore/xxhash.h @@ -6,7 +6,9 @@ #include <zencore/memoryview.h> +ZEN_THIRD_PARTY_INCLUDES_START #include <xxh3.h> +ZEN_THIRD_PARTY_INCLUDES_END #include <compare> #include <string_view> |