Compare commits

...
2 Commits
Author SHA1 Message Date
abdelrahman fc4f3f49d2 Updated WpUuid API
Release / release (push) Successful in 12s
2026-11-16 21:32:20 +00:00
abdelrahman 45e58a23f6 Rename debug macro
Release / release (push) Successful in 12s
2026-11-11 01:48:12 +00:00
7 changed files with 50 additions and 63 deletions

No files matched your search

+12
View File
@@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
## [3.5.0] - 2026-11-16
### Changed
- `WpUuid` API
## [3.4.0] - 2026-11-11
### Changed
- `WP_DEBUG_ASSERT` macro to `WP_DEBUG_BUILD`
## [3.3.1] - 2026-10-29
### Fixed
+2 -2
View File
@@ -34,9 +34,9 @@ override HEADER_INSTALL_CMD := scripts/header_install.sh
ifeq ($(origin BUILD_FLAGS), undefined)
ifeq ($(BUILD_TYPE),Debug)
BUILD_FLAGS += -g -fsanitize=address,undefined -DWP_DEBUG_ASSERT
BUILD_FLAGS += -g -fsanitize=address,undefined -DWP_DEBUG_BUILD
else ifeq ($(BUILD_TYPE),RelWithDebInfo)
BUILD_FLAGS += -g -O2 -fsanitize=address,undefined -DWP_DEBUG_ASSERT
BUILD_FLAGS += -g -O2 -fsanitize=address,undefined -DWP_DEBUG_BUILD
else ifeq ($(BUILD_TYPE),Release)
BUILD_FLAGS += -O3
else
+1 -1
View File
@@ -1 +1 @@
3.3.1
3.5.0
+1 -1
View File
@@ -21,7 +21,7 @@ BEGIN_C_LINKAGE
#define wpRuntimeAssert(EXPR, MSG)
#endif
#ifdef WP_DEBUG_ASSERT
#ifdef WP_DEBUG_BUILD
#define wpDebugAssert(EXPR, MSG) wpRuntimeAssert(EXPR, MSG)
#else
#define wpDebugAssert(EXPR, MSG)
+1 -1
View File
@@ -41,7 +41,7 @@
// --- Assert ---
#define WAPP_NO_RUNTIME_ASSERT WP_NO_RUNTIME_ASSERT
#define WAPP_DEBUG_ASSERT WP_DEBUG_ASSERT
#define WAPP_DEBUG_ASSERT WP_DEBUG_BUILD
// --- CPath ---
+24 -29
View File
@@ -8,36 +8,19 @@
#include <inttypes.h>
#define UUID_STR_FORMAT ("%.8" PRIx64 "-%.4" PRIx64 "-%.4" PRIx64 "-%.4" PRIx64 "-%.12" PRIx64)
#define UUID_HEX_FORMAT ("%.16" PRIx64 "%.16" PRIx64)
typedef struct UUID4 UUID4;
struct UUID4 {
u64 high;
u64 low;
};
wp_intern UUID4 genUuid4(void);
wp_intern void uuid4ToUuid(const UUID4* uuid4, WpUuid *uuid);
WpUuid *wpUuidInitUuid4(WpUuid *uuid) {
wpDebugAssert(uuid != NULL, "`uuid` should not be NULL");
UUID4 uuid4 = genUuid4();
uuid4ToUuid(&uuid4, uuid);
return uuid;
}
wp_intern UUID4 genUuid4(void) {
WpUuid wpUuidGenUuid4(void) {
wp_persist WpXor256State state = {0};
wp_persist b8 initialised = false;
wp_persist b8 initialised = false;
if (!initialised) {
initialised = true;
state = wpPrngXorshiftInit();
}
UUID4 uuid = (UUID4){
.high = wpPrngXorshift256(&state),
WpUuid uuid = {
.high = wpPrngXorshift256(&state),
.low = wpPrngXorshift256(&state),
};
@@ -47,12 +30,24 @@ wp_intern UUID4 genUuid4(void) {
return uuid;
}
wp_intern void uuid4ToUuid(const UUID4* uuid4, WpUuid *uuid) {
u64 group1 = uuid4->high >> 32;
u64 group2 = (uuid4->high << 32) >> 48;
u64 group3 = (uuid4->high << 48) >> 48;
u64 group4 = uuid4->low >> 48;
u64 group5 = (uuid4->low << 16) >> 16;
void wpUuidToStr8(const WpUuid *uuid, WpStr8 *buf) {
wpDebugAssert(uuid != NULL, "`uuid` should not be NULL");
wpRuntimeAssert(buf != NULL && buf->capacity >= WP_UUID_STR_BUF_LENGTH,
"String buffer is NULL or doesn't have sufficient capacity");
wpStr8Format(&(uuid->uuid), UUID_STR_FORMAT, group1, group2, group3, group4, group5);
u64 group1 = uuid->high >> 32;
u64 group2 = (uuid->high << 32) >> 48;
u64 group3 = (uuid->high << 48) >> 48;
u64 group4 = uuid->low >> 48;
u64 group5 = (uuid->low << 16) >> 16;
wpStr8Format(buf, UUID_STR_FORMAT, group1, group2, group3, group4, group5);
}
void wpUuidToHex(const WpUuid *uuid, WpStr8 *buf) {
wpDebugAssert(uuid != NULL, "`uuid` should not be NULL");
wpRuntimeAssert(buf != NULL && buf->capacity >= WP_UUID_HEX_BUF_LENGTH,
"String buffer is NULL or doesn't have sufficient capacity");
wpStr8Format(buf, UUID_HEX_FORMAT, uuid->high, uuid->low);
}
+9 -29
View File
@@ -11,37 +11,17 @@
BEGIN_C_LINKAGE
#endif // !WP_PLATFORM_CPP
#define WP_UUID_BUF_LENGTH 48
#define WP_UUID_SPEC WP_STR8_SPEC
#define wpUuidVarg(WpUuid) wpStr8Varg((WpUuid).uuid)
#define WP_UUID_STR_BUF_LENGTH 36
#define WP_UUID_HEX_BUF_LENGTH 32
typedef struct WpUuid WpUuid;
struct WpUuid {
WpStr8 uuid;
};
typedef struct WpUuid {
u64 high;
u64 low;
} WpUuid;
// TODO (Abdelrahman): Update UUID implementation to work properly with C++ and tests for validation
#ifdef WP_PLATFORM_CPP
#define wpUuidGenUuid4() ([&](){ \
wp_persist WpUuid uuid = wpUuidCreate(); \
return *(wpUuidInitUuid4(&uuid)); \
}())
#else
#define wpUuidGenUuid4() *(wpUuidInitUuid4(&wpUuidCreate()))
#endif
/* Low level UUID API */
#ifdef WP_PLATFORM_CPP
#define wpUuidCreate() ([&](){ return WpUuid{wpStr8Buf(WP_UUID_BUF_LENGTH)}; }())
#else
#define wpUuidCreate() ((WpUuid){.uuid = wpStr8Buf(WP_UUID_BUF_LENGTH)})
#endif
// Just returns the same pointer that was passed in with the UUID initialised.
// Fails when passed a NULL pointer.
WpUuid *wpUuidInitUuid4(WpUuid *uuid);
WpUuid wpUuidGenUuid4(void);
void wpUuidToStr8(const WpUuid *uuid, WpStr8 *buf);
void wpUuidToHex(const WpUuid *uuid, WpStr8 *buf);
#ifdef WP_PLATFORM_CPP
END_C_LINKAGE