externals: Update zycore to 1.4.1

Merge commit 'cd2ede593acee9c4956c79da4377ce890ac3a9c0'
This commit is contained in:
Alexandre Bouvier
2022-11-20 21:49:18 +01:00
35 changed files with 1120 additions and 228 deletions

View File

@@ -26,6 +26,8 @@
#include <Zycore/API/Memory.h>
#ifndef ZYAN_NO_LIBC
#if defined(ZYAN_WINDOWS)
#elif defined(ZYAN_POSIX)
@@ -126,3 +128,5 @@ ZyanStatus ZyanMemoryVirtualFree(void* address, ZyanUSize size)
/* ---------------------------------------------------------------------------------------------- */
/* ============================================================================================== */
#endif /* ZYAN_NO_LIBC */

View File

@@ -25,14 +25,21 @@
***************************************************************************************************/
#include <Zycore/Defines.h>
#if defined(ZYAN_WINDOWS)
# include <windows.h>
#include <Zycore/API/Process.h>
#ifndef ZYAN_NO_LIBC
#if defined(ZYAN_WINDOWS)
#if defined(ZYAN_KERNEL)
# include <wdm.h>
#else
# include <windows.h>
#endif
#elif defined(ZYAN_POSIX)
# include <sys/mman.h>
#else
# error "Unsupported platform detected"
#endif
#include <Zycore/API/Process.h>
/* ============================================================================================== */
/* Exported functions */
@@ -66,3 +73,5 @@ ZyanStatus ZyanProcessFlushInstructionCache(void* address, ZyanUSize size)
/* ---------------------------------------------------------------------------------------------- */
/* ============================================================================================== */
#endif /* ZYAN_NO_LIBC */

View File

@@ -26,6 +26,8 @@
#include <Zycore/API/Synchronization.h>
#ifndef ZYAN_NO_LIBC
/* ============================================================================================== */
/* Internal functions */
/* ============================================================================================== */
@@ -198,3 +200,5 @@ ZyanStatus ZyanCriticalSectionDelete(ZyanCriticalSection* critical_section)
#endif
/* ============================================================================================== */
#endif /* ZYAN_NO_LIBC */

View File

@@ -26,6 +26,8 @@
#include <Zycore/API/Terminal.h>
#ifndef ZYAN_NO_LIBC
#if defined(ZYAN_POSIX)
# include <unistd.h>
#elif defined(ZYAN_WINDOWS)
@@ -154,3 +156,5 @@ ZyanStatus ZyanTerminalIsTTY(ZyanStandardStream stream)
}
/* ============================================================================================== */
#endif /* ZYAN_NO_LIBC */

View File

@@ -26,14 +26,62 @@
#include <Zycore/API/Thread.h>
#ifndef ZYAN_NO_LIBC
/* ============================================================================================== */
/* Internal functions */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* */
/* Legacy Windows import declarations */
/* ---------------------------------------------------------------------------------------------- */
#if defined(ZYAN_WINDOWS) && defined(_WIN32_WINNT) && \
(_WIN32_WINNT >= 0x0501) && (_WIN32_WINNT < 0x0600)
/**
* The Windows SDK conditionally declares the following prototypes: the target OS must be Vista
* (0x0600) or above. MSDN states the same incorrect minimum requirement for the Fls* functions.
*
* However, these functions exist and work perfectly fine on XP (SP3) and Server 2003.
* Preserve backward compatibility with these OSes by declaring the prototypes here if needed.
*/
#ifndef FLS_OUT_OF_INDEXES
#define FLS_OUT_OF_INDEXES ((DWORD)0xFFFFFFFF)
#endif
WINBASEAPI
DWORD
WINAPI
FlsAlloc(
_In_opt_ PFLS_CALLBACK_FUNCTION lpCallback
);
WINBASEAPI
PVOID
WINAPI
FlsGetValue(
_In_ DWORD dwFlsIndex
);
WINBASEAPI
BOOL
WINAPI
FlsSetValue(
_In_ DWORD dwFlsIndex,
_In_opt_ PVOID lpFlsData
);
WINBASEAPI
BOOL
WINAPI
FlsFree(
_In_ DWORD dwFlsIndex
);
#endif /* (_WIN32_WINNT >= 0x0501) && (_WIN32_WINNT < 0x0600)*/
/* ---------------------------------------------------------------------------------------------- */
@@ -192,3 +240,5 @@ ZyanStatus ZyanThreadTlsSetValue(ZyanThreadTlsIndex index, void* data)
#endif
/* ============================================================================================== */
#endif /* ZYAN_NO_LIBC */

View File

@@ -31,8 +31,8 @@
/* Internal constants */
/* ============================================================================================== */
#define ZYAN_BITSET_GROWTH_FACTOR 2.00f
#define ZYAN_BITSET_SHRINK_THRESHOLD 0.50f
#define ZYAN_BITSET_GROWTH_FACTOR 2
#define ZYAN_BITSET_SHRINK_THRESHOLD 2
/* ============================================================================================== */
/* Internal macros */
@@ -56,7 +56,7 @@
* @return The amount of bytes needed to fit `x` bits.
*/
#define ZYAN_BITSET_BITS_TO_BYTES(x) \
ZYAN_BITSET_CEIL((x) / 8.0f)
ZYAN_BITSET_CEIL((x) / 8)
/**
* Returns the offset of the given bit.
@@ -140,7 +140,7 @@ ZyanStatus ZyanBitsetInit(ZyanBitset* bitset, ZyanUSize count)
#endif // ZYAN_NO_LIBC
ZyanStatus ZyanBitsetInitEx(ZyanBitset* bitset, ZyanUSize count, ZyanAllocator* allocator,
float growth_factor, float shrink_threshold)
ZyanU8 growth_factor, ZyanU8 shrink_threshold)
{
if (!bitset)
{

View File

@@ -83,7 +83,7 @@ static const ZyanStringView STR_SUB = ZYAN_DEFINE_STRING_VIEW("-");
/* Decimal */
/* ---------------------------------------------------------------------------------------------- */
#if defined(ZYAN_X86) || defined(ZYAN_ARM) || defined(ZYAN_EMSCRIPTEN)
#if defined(ZYAN_X86) || defined(ZYAN_ARM) || defined(ZYAN_EMSCRIPTEN) || defined(ZYAN_WASM) || defined(ZYAN_PPC)
ZyanStatus ZyanStringAppendDecU32(ZyanString* string, ZyanU32 value, ZyanU8 padding_length)
{
if (!string)
@@ -179,7 +179,7 @@ ZyanStatus ZyanStringAppendDecU64(ZyanString* string, ZyanU64 value, ZyanU8 padd
/* Hexadecimal */
/* ---------------------------------------------------------------------------------------------- */
#if defined(ZYAN_X86) || defined(ZYAN_ARM) || defined(ZYAN_EMSCRIPTEN)
#if defined(ZYAN_X86) || defined(ZYAN_ARM) || defined(ZYAN_EMSCRIPTEN) || defined(ZYAN_WASM) || defined(ZYAN_PPC)
ZyanStatus ZyanStringAppendHexU32(ZyanString* string, ZyanU32 value, ZyanU8 padding_length,
ZyanBool uppercase)
{
@@ -423,7 +423,7 @@ ZyanStatus ZyanStringAppendFormat(ZyanString* string, const char* format, ...)
ZyanStatus ZyanStringAppendDecU(ZyanString* string, ZyanU64 value, ZyanU8 padding_length)
{
#if defined(ZYAN_X64) || defined(ZYAN_AARCH64)
#if defined(ZYAN_X64) || defined(ZYAN_AARCH64) || defined(ZYAN_PPC64) || defined(ZYAN_RISCV64)
return ZyanStringAppendDecU64(string, value, padding_length);
#else
// Working with 64-bit values is slow on non 64-bit systems
@@ -464,7 +464,7 @@ ZyanStatus ZyanStringAppendDecS(ZyanString* string, ZyanI64 value, ZyanU8 paddin
ZyanStatus ZyanStringAppendHexU(ZyanString* string, ZyanU64 value, ZyanU8 padding_length,
ZyanBool uppercase)
{
#if defined(ZYAN_X64) || defined(ZYAN_AARCH64)
#if defined(ZYAN_X64) || defined(ZYAN_AARCH64) || defined(ZYAN_PPC64) || defined(ZYAN_RISCV64)
return ZyanStringAppendHexU64(string, value, padding_length, uppercase);
#else
// Working with 64-bit values is slow on non 64-bit systems

View File

@@ -62,7 +62,7 @@ ZyanStatus ZyanStringInit(ZyanString* string, ZyanUSize capacity)
#endif // ZYAN_NO_LIBC
ZyanStatus ZyanStringInitEx(ZyanString* string, ZyanUSize capacity, ZyanAllocator* allocator,
float growth_factor, float shrink_threshold)
ZyanU8 growth_factor, ZyanU8 shrink_threshold)
{
if (!string)
{
@@ -133,7 +133,7 @@ ZyanStatus ZyanStringDuplicate(ZyanString* destination, const ZyanStringView* so
#endif // ZYAN_NO_LIBC
ZyanStatus ZyanStringDuplicateEx(ZyanString* destination, const ZyanStringView* source,
ZyanUSize capacity, ZyanAllocator* allocator, float growth_factor, float shrink_threshold)
ZyanUSize capacity, ZyanAllocator* allocator, ZyanU8 growth_factor, ZyanU8 shrink_threshold)
{
if (!source || !source->string.vector.size)
{
@@ -194,8 +194,8 @@ ZyanStatus ZyanStringConcat(ZyanString* destination, const ZyanStringView* s1,
#endif // ZYAN_NO_LIBC
ZyanStatus ZyanStringConcatEx(ZyanString* destination, const ZyanStringView* s1,
const ZyanStringView* s2, ZyanUSize capacity, ZyanAllocator* allocator, float growth_factor,
float shrink_threshold)
const ZyanStringView* s2, ZyanUSize capacity, ZyanAllocator* allocator, ZyanU8 growth_factor,
ZyanU8 shrink_threshold)
{
if (!s1 || !s2 || !s1->string.vector.size || !s2->string.vector.size)
{

View File

@@ -52,7 +52,7 @@
* @return `ZYAN_TRUE`, if the vector should shrink or `ZYAN_FALSE`, if not.
*/
#define ZYCORE_VECTOR_SHOULD_SHRINK(size, capacity, threshold) \
((size) < (capacity) * (threshold))
(((threshold) != 0) && ((size) * (threshold) < (capacity)))
/**
* Returns the offset of the element at the given `index`.
@@ -119,8 +119,7 @@ static ZyanStatus ZyanVectorReallocate(ZyanVector* vector, ZyanUSize capacity)
}
/**
* Shifts all elements starting at the specified `index` by the amount of
* `count` to the left.
* Shifts all elements starting at the specified `index` by the amount of `count` to the left.
*
* @param vector A pointer to the `ZyanVector` instance.
* @param index The start index.
@@ -136,17 +135,16 @@ static ZyanStatus ZyanVectorShiftLeft(ZyanVector* vector, ZyanUSize index, ZyanU
ZYAN_ASSERT(count > 0);
//ZYAN_ASSERT((ZyanISize)count - (ZyanISize)index + 1 >= 0);
void* const source = ZYCORE_VECTOR_OFFSET(vector, index + count);
void* const dest = ZYCORE_VECTOR_OFFSET(vector, index);
const ZyanUSize size = (vector->size - index - count) * vector->element_size;
const void* const source = ZYCORE_VECTOR_OFFSET(vector, index + count);
void* const dest = ZYCORE_VECTOR_OFFSET(vector, index);
const ZyanUSize size = (vector->size - index - count) * vector->element_size;
ZYAN_MEMMOVE(dest, source, size);
return ZYAN_STATUS_SUCCESS;
}
/**
* Shifts all elements starting at the specified `index` by the amount of
* `count` to the right.
* Shifts all elements starting at the specified `index` by the amount of `count` to the right.
*
* @param vector A pointer to the `ZyanVector` instance.
* @param index The start index.
@@ -162,9 +160,9 @@ static ZyanStatus ZyanVectorShiftRight(ZyanVector* vector, ZyanUSize index, Zyan
ZYAN_ASSERT(count > 0);
ZYAN_ASSERT(vector->size + count <= vector->capacity);
void* const source = ZYCORE_VECTOR_OFFSET(vector, index);
void* const dest = ZYCORE_VECTOR_OFFSET(vector, index + count);
const ZyanUSize size = (vector->size - index) * vector->element_size;
const void* const source = ZYCORE_VECTOR_OFFSET(vector, index);
void* const dest = ZYCORE_VECTOR_OFFSET(vector, index + count);
const ZyanUSize size = (vector->size - index) * vector->element_size;
ZYAN_MEMMOVE(dest, source, size);
return ZYAN_STATUS_SUCCESS;
@@ -192,11 +190,10 @@ ZyanStatus ZyanVectorInit(ZyanVector* vector, ZyanUSize element_size, ZyanUSize
#endif // ZYAN_NO_LIBC
ZyanStatus ZyanVectorInitEx(ZyanVector* vector, ZyanUSize element_size, ZyanUSize capacity,
ZyanMemberProcedure destructor, ZyanAllocator* allocator, float growth_factor,
float shrink_threshold)
ZyanMemberProcedure destructor, ZyanAllocator* allocator, ZyanU8 growth_factor,
ZyanU8 shrink_threshold)
{
if (!vector || !element_size || !allocator || (growth_factor < 1.0f) ||
(shrink_threshold < 0.0f) || (shrink_threshold > 1.0f))
if (!vector || !element_size || !allocator || (growth_factor < 1))
{
return ZYAN_STATUS_INVALID_ARGUMENT;
}
@@ -225,8 +222,8 @@ ZyanStatus ZyanVectorInitCustomBuffer(ZyanVector* vector, ZyanUSize element_size
}
vector->allocator = ZYAN_NULL;
vector->growth_factor = 1.0f;
vector->shrink_threshold = 0.0f;
vector->growth_factor = 1;
vector->shrink_threshold = 0;
vector->size = 0;
vector->capacity = capacity;
vector->element_size = element_size;
@@ -281,7 +278,7 @@ ZyanStatus ZyanVectorDuplicate(ZyanVector* destination, const ZyanVector* source
#endif // ZYAN_NO_LIBC
ZyanStatus ZyanVectorDuplicateEx(ZyanVector* destination, const ZyanVector* source,
ZyanUSize capacity, ZyanAllocator* allocator, float growth_factor, float shrink_threshold)
ZyanUSize capacity, ZyanAllocator* allocator, ZyanU8 growth_factor, ZyanU8 shrink_threshold)
{
if (!source)
{
@@ -774,8 +771,9 @@ ZyanStatus ZyanVectorResizeEx(ZyanVector* vector, ZyanUSize size, const void* in
if (ZYCORE_VECTOR_SHOULD_GROW(size, vector->capacity) ||
ZYCORE_VECTOR_SHOULD_SHRINK(size, vector->capacity, vector->shrink_threshold))
{
ZYAN_ASSERT(vector->growth_factor >= 1);
ZYAN_CHECK(ZyanVectorReallocate(vector, (ZyanUSize)(size * vector->growth_factor)));
};
}
if (initializer && (size > vector->size))
{