From 121c54227a39dea4640ef758b3d0a26b724d8756 Mon Sep 17 00:00:00 2001 From: MechSlayer <0jcrespo1996@gmail.com> Date: Fri, 5 Sep 2025 16:05:19 +0200 Subject: [PATCH] style: apply consistent formatting and remove unnecessary blank lines --- Source/DrangPlatform/CMakeLists.txt | 34 +++++++++--------- Source/DrangPlatform/Include/drang/alloc.h | 33 +++++++++-------- Source/DrangPlatform/Include/drang/platform.h | 31 ++++++++-------- Source/DrangPlatform/Include/drang/sync.h | 1 - Source/DrangPlatform/Source/alloc.c | 4 +-- Source/DrangPlatform/Source/error.c | 36 ++++++++++++------- .../Source/win32/sync/cond_var.c | 4 +-- .../Source/win32/sync/internal.h | 2 +- .../DrangPlatform/Source/win32/sync/mutex.c | 5 +-- .../DrangPlatform/Source/win32/sync/rwlock.c | 2 +- 10 files changed, 79 insertions(+), 73 deletions(-) diff --git a/Source/DrangPlatform/CMakeLists.txt b/Source/DrangPlatform/CMakeLists.txt index 2820aa8..ec6f0ff 100644 --- a/Source/DrangPlatform/CMakeLists.txt +++ b/Source/DrangPlatform/CMakeLists.txt @@ -16,33 +16,33 @@ function(collect_platform_sources output_var source_dir) # Define platform directories to exclude based on current platform set(exclude_patterns) - if(WIN32) + if (WIN32) list(APPEND exclude_patterns "linux/" "macos/" "unix/") - elseif(UNIX AND NOT APPLE) + elseif (UNIX AND NOT APPLE) list(APPEND exclude_patterns "win32/" "windows/" "macos/") - elseif(APPLE) + elseif (APPLE) list(APPEND exclude_patterns "win32/" "windows/" "linux/") - endif() + endif () # Filter out sources from excluded platform directories set(filtered_sources) - foreach(source ${all_sources}) + foreach (source ${all_sources}) set(exclude_file FALSE) # Check if source is in any excluded platform directory - foreach(pattern ${exclude_patterns}) + foreach (pattern ${exclude_patterns}) string(FIND "${source}" "/${pattern}" found_pos) - if(found_pos GREATER -1) + if (found_pos GREATER -1) set(exclude_file TRUE) break() - endif() - endforeach() + endif () + endforeach () # Add to filtered list if not excluded - if(NOT exclude_file) + if (NOT exclude_file) list(APPEND filtered_sources "${source}") - endif() - endforeach() + endif () + endforeach () # Return the filtered list set(${output_var} ${filtered_sources} PARENT_SCOPE) @@ -52,17 +52,17 @@ collect_platform_sources(MODULE_PRIVATE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/Sourc collect_platform_sources(MODULE_PUBLIC_FILES "${CMAKE_CURRENT_SOURCE_DIR}/Include") set(MODULE_FILES ${MODULE_PRIVATE_FILES} ${MODULE_PUBLIC_FILES}) -if(${BUILD_SHARED_LIBS}) +if (${BUILD_SHARED_LIBS}) add_library(${MODULE_NAME} SHARED ${MODULE_FILES}) target_compile_definitions(${MODULE_NAME} PRIVATE DRANG_PLATFORM_EXPORT=1) -else() +else () add_library(${MODULE_NAME} STATIC ${MODULE_FILES}) target_compile_definitions(${MODULE_NAME} PRIVATE DRANG_PLATFORM_STATIC=1) -endif() +endif () -if(UNIX) +if (UNIX) target_compile_definitions(${MODULE_NAME} PRIVATE _GNU_SOURCE=1) -endif() +endif () set_target_properties(${MODULE_NAME} PROPERTIES LINKER_LANGUAGE C) diff --git a/Source/DrangPlatform/Include/drang/alloc.h b/Source/DrangPlatform/Include/drang/alloc.h index dffd09c..cfa4201 100644 --- a/Source/DrangPlatform/Include/drang/alloc.h +++ b/Source/DrangPlatform/Include/drang/alloc.h @@ -89,8 +89,7 @@ DRANG_API void *drang_realloc_aligned(void *ptr, size_t size, size_t alignment); * @remarks If the array grows, new elements are zero-initialized. Similar to _recalloc() on Windows. */ DRANG_ALLOC_SIZE_COUNT_ATTR(2, 3) -DRANG_API void *drang_recalloc( - void *ptr, size_t new_num, size_t size); +DRANG_API void *drang_recalloc(void *ptr, size_t new_num, size_t size); /** * @brief Reallocates aligned memory for an array and initializes new elements to zero. @@ -104,8 +103,7 @@ DRANG_API void *drang_recalloc( */ DRANG_ALLOC_SIZE_COUNT_ATTR(2, 3) DRANG_ALLOC_ALIGN_ATTR(4) -DRANG_API void *drang_recalloc_aligned( - void *ptr, size_t new_num, size_t size, size_t alignment); +DRANG_API void *drang_recalloc_aligned(void *ptr, size_t new_num, size_t size, size_t alignment); /** * @brief Frees previously allocated memory. @@ -115,9 +113,6 @@ DRANG_API void *drang_recalloc_aligned( */ DRANG_API void drang_free(void *ptr); - - - /** * @brief Internal implementation macro for allocation with error handling. * @@ -126,7 +121,12 @@ DRANG_API void drang_free(void *ptr); * @remarks This macro calls the allocation function and automatically handles NULL return * by triggering DRANG error handling with DRANG_ENOMEM. Uses GCC statement expressions. */ -#define DRANG_ALLOC_TRY_IMPL(_Func_) ({void* _tmp_ptr = (_Func_); DRANG_FAIL_IF_NULL_OOM(_tmp_ptr); _tmp_ptr; }) +#define DRANG_ALLOC_TRY_IMPL(_Func_) \ + ({ \ + void *_tmp_ptr = (_Func_); \ + DRANG_FAIL_IF_NULL_OOM(_tmp_ptr); \ + _tmp_ptr; \ + }) /** * @brief Allocates memory for a single object of the specified type with proper alignment. @@ -156,7 +156,8 @@ DRANG_API void drang_free(void *ptr); * @return Pointer to reallocated memory cast to the appropriate type. * @remarks Maintains proper alignment during reallocation. */ -#define DRANG_REALLOC_T(_Ptr_, _Type_, _Num_) ((_Type_ *) drang_realloc_aligned((_Ptr_), sizeof(_Type_) * (_Num_), alignof(_Type_))) +#define DRANG_REALLOC_T(_Ptr_, _Type_, _Num_) \ + ((_Type_ *) drang_realloc_aligned((_Ptr_), sizeof(_Type_) * (_Num_), alignof(_Type_))) /** * @brief Allocates memory with automatic error handling. @@ -196,7 +197,8 @@ DRANG_API void drang_free(void *ptr); * @return Pointer to allocated zero-initialized aligned memory. * @remarks Automatically triggers DRANG error handling if allocation fails. */ -#define DRANG_TRY_CALLOC_ALIGNED(_Num_, _Size_, _Alignment_) DRANG_ALLOC_TRY_IMPL(drang_calloc_aligned((_Num_), (_Size_), (_Alignment_))) +#define DRANG_TRY_CALLOC_ALIGNED(_Num_, _Size_, _Alignment_) \ + DRANG_ALLOC_TRY_IMPL(drang_calloc_aligned((_Num_), (_Size_), (_Alignment_))) /** * @brief Reallocates memory with automatic error handling. @@ -217,7 +219,8 @@ DRANG_API void drang_free(void *ptr); * @return Pointer to reallocated aligned memory. * @remarks Automatically triggers DRANG error handling if allocation fails. */ -#define DRANG_TRY_REALLOC_ALIGNED(_Ptr_, _Size_, _Alignment_) DRANG_ALLOC_TRY_IMPL(drang_realloc_aligned((_Ptr_), (_Size_), (_Alignment_))) +#define DRANG_TRY_REALLOC_ALIGNED(_Ptr_, _Size_, _Alignment_) \ + DRANG_ALLOC_TRY_IMPL(drang_realloc_aligned((_Ptr_), (_Size_), (_Alignment_))) /** * @brief Reallocates memory for an array with zero-initialization and automatic error handling. @@ -228,7 +231,8 @@ DRANG_API void drang_free(void *ptr); * @return Pointer to reallocated memory. * @remarks Automatically triggers DRANG error handling if allocation fails. New elements are zero-initialized. */ -#define DRANG_TRY_RECALLOC(_Ptr_, _New_Num_, _Size_) DRANG_ALLOC_TRY_IMPL(drang_recalloc((_Ptr_), (_New_Num_), (_Size_))) +#define DRANG_TRY_RECALLOC(_Ptr_, _New_Num_, _Size_) \ + DRANG_ALLOC_TRY_IMPL(drang_recalloc((_Ptr_), (_New_Num_), (_Size_))) /** * @brief Reallocates aligned memory for an array with zero-initialization and automatic error handling. @@ -240,9 +244,8 @@ DRANG_API void drang_free(void *ptr); * @return Pointer to reallocated aligned memory. * @remarks Automatically triggers DRANG error handling if allocation fails. New elements are zero-initialized. */ -#define DRANG_TRY_RECALLOC_ALIGNED(_Ptr_, _New_Num_, _Size_, _Alignment_) DRANG_ALLOC_TRY_IMPL(drang_recalloc_aligned((_Ptr_), (_New_Num_), (_Size_), (_Alignment_))) - - +#define DRANG_TRY_RECALLOC_ALIGNED(_Ptr_, _New_Num_, _Size_, _Alignment_) \ + DRANG_ALLOC_TRY_IMPL(drang_recalloc_aligned((_Ptr_), (_New_Num_), (_Size_), (_Alignment_))) /** * @brief Allocates memory for a single typed object with automatic error handling. diff --git a/Source/DrangPlatform/Include/drang/platform.h b/Source/DrangPlatform/Include/drang/platform.h index ae063e8..f0a9ecd 100644 --- a/Source/DrangPlatform/Include/drang/platform.h +++ b/Source/DrangPlatform/Include/drang/platform.h @@ -7,8 +7,7 @@ # elif defined(__linux__) # define DRANG_API __attribute__((visibility("default"))) # else -# error \ - "Unknown platform, please implement shared library export macros" +# error "Unknown platform, please implement shared library export macros" # endif # else # ifdef _WIN32 @@ -16,8 +15,7 @@ # elif defined(__linux__) # define DRANG_API __attribute__((visibility("default"))) # else -# error \ - "Unknown platform, please implement shared library import macros" +# error "Unknown platform, please implement shared library import macros" # endif # endif #else @@ -32,20 +30,19 @@ # define DRANG_END_DECLS #endif - #if defined(__GNUC__) || defined(__clang__) -#define DRANG_PRINTF_ATTR(fmt_idx, arg_idx) __attribute__((format(printf, fmt_idx, arg_idx))) -#define DRANG_VPRINTF_ATTR(fmt_idx) __attribute__((format(printf, fmt_idx, 0))) -#define DRANG_ALLOC_SIZE_COUNT_ATTR(count, idx) __attribute__((alloc_size(idx, count))) -#define DRANG_ALLOC_SIZE_ATTR(idx) __attribute__((alloc_size(idx))) -#define DRANG_ALLOC_ALIGN_ATTR(idx) __attribute__((alloc_align(idx))) -#define DRANG_MALLOC_ATTR __attribute__((malloc)) +# define DRANG_PRINTF_ATTR(fmt_idx, arg_idx) __attribute__((format(printf, fmt_idx, arg_idx))) +# define DRANG_VPRINTF_ATTR(fmt_idx) __attribute__((format(printf, fmt_idx, 0))) +# define DRANG_ALLOC_SIZE_COUNT_ATTR(count, idx) __attribute__((alloc_size(idx, count))) +# define DRANG_ALLOC_SIZE_ATTR(idx) __attribute__((alloc_size(idx))) +# define DRANG_ALLOC_ALIGN_ATTR(idx) __attribute__((alloc_align(idx))) +# define DRANG_MALLOC_ATTR __attribute__((malloc)) #else -#define DRANG_PRINTF_ATTR(fmt_idx, arg_idx) -#define DRANG_VPRINTF_ATTR(fmt_idx) -#define DRANG_ALLOC_SIZE_COUNT_ATTR(idx, count) -#define DRANG_ALLOC_SIZE_ATTR(idx) -#define DRANG_ALLOC_ALIGN_ATTR(idx) -#define DRANG_MALLOC_ATTR +# define DRANG_PRINTF_ATTR(fmt_idx, arg_idx) +# define DRANG_VPRINTF_ATTR(fmt_idx) +# define DRANG_ALLOC_SIZE_COUNT_ATTR(idx, count) +# define DRANG_ALLOC_SIZE_ATTR(idx) +# define DRANG_ALLOC_ALIGN_ATTR(idx) +# define DRANG_MALLOC_ATTR #endif diff --git a/Source/DrangPlatform/Include/drang/sync.h b/Source/DrangPlatform/Include/drang/sync.h index 3a7c95d..0e818a1 100644 --- a/Source/DrangPlatform/Include/drang/sync.h +++ b/Source/DrangPlatform/Include/drang/sync.h @@ -434,5 +434,4 @@ DRANG_API int drang_rwlock_rdunlock(struct drang_rwlock *rwlock); */ DRANG_API int drang_rwlock_wrunlock(struct drang_rwlock *rwlock); - DRANG_END_DECLS diff --git a/Source/DrangPlatform/Source/alloc.c b/Source/DrangPlatform/Source/alloc.c index 199b8f6..eaf06c0 100644 --- a/Source/DrangPlatform/Source/alloc.c +++ b/Source/DrangPlatform/Source/alloc.c @@ -1,7 +1,6 @@ #include #include - void *drang_alloc(const size_t size) { return mi_malloc(size); @@ -30,8 +29,7 @@ void *drang_recalloc(void *ptr, const size_t new_num, const size_t size) { return mi_recalloc(ptr, new_num, size); } -void *drang_recalloc_aligned( - void *ptr, const size_t new_num, const size_t size, const size_t alignment) +void *drang_recalloc_aligned(void *ptr, const size_t new_num, const size_t size, const size_t alignment) { return mi_recalloc_aligned(ptr, new_num, size, alignment); } diff --git a/Source/DrangPlatform/Source/error.c b/Source/DrangPlatform/Source/error.c index 437528c..4e3b684 100644 --- a/Source/DrangPlatform/Source/error.c +++ b/Source/DrangPlatform/Source/error.c @@ -3,17 +3,29 @@ const char *drang_error_str(const int err) { switch (err) { - case DRANG_EOK: return "No error"; - case DRANG_EINVAL: return "Invalid argument"; - case DRANG_ENOMEM: return "Out of memory"; - case DRANG_EIO: return "I/O error"; - case DRANG_NOTSUP: return "Operation not supported"; - case DRANG_EAGAIN: return "Resource temporarily unavailable"; - case DRANG_ENOENT: return "No such file or directory"; - case DRANG_EDEADLK: return "Resource deadlock would occur"; - case DRANG_EPERM: return "Operation not permitted"; - case DRANG_ETIMEDOUT: return "Connection timed out"; - case DRANG_EBUSY: return "Device or resource busy"; - default: return "Unknown error"; + case DRANG_EOK: + return "No error"; + case DRANG_EINVAL: + return "Invalid argument"; + case DRANG_ENOMEM: + return "Out of memory"; + case DRANG_EIO: + return "I/O error"; + case DRANG_NOTSUP: + return "Operation not supported"; + case DRANG_EAGAIN: + return "Resource temporarily unavailable"; + case DRANG_ENOENT: + return "No such file or directory"; + case DRANG_EDEADLK: + return "Resource deadlock would occur"; + case DRANG_EPERM: + return "Operation not permitted"; + case DRANG_ETIMEDOUT: + return "Connection timed out"; + case DRANG_EBUSY: + return "Device or resource busy"; + default: + return "Unknown error"; } } diff --git a/Source/DrangPlatform/Source/win32/sync/cond_var.c b/Source/DrangPlatform/Source/win32/sync/cond_var.c index 60d1690..59845b7 100644 --- a/Source/DrangPlatform/Source/win32/sync/cond_var.c +++ b/Source/DrangPlatform/Source/win32/sync/cond_var.c @@ -94,7 +94,7 @@ int drang_cond_wait(struct drang_cond *cond, struct drang_mutex *mutex) int drang_cond_timedwait(struct drang_cond *cond, struct drang_mutex *mutex, uint64_t timeout_ms) { - DWORD timeout = (timeout_ms == 0) ? INFINITE : (DWORD)timeout_ms; + DWORD timeout = (timeout_ms == 0) ? INFINITE : (DWORD) timeout_ms; BOOL result; DRANG_BEGIN_TRY(); @@ -113,4 +113,4 @@ int drang_cond_timedwait(struct drang_cond *cond, struct drang_mutex *mutex, uin } DRANG_END_TRY_IGNORE(); -} \ No newline at end of file +} diff --git a/Source/DrangPlatform/Source/win32/sync/internal.h b/Source/DrangPlatform/Source/win32/sync/internal.h index e1ed6b7..ac08f17 100644 --- a/Source/DrangPlatform/Source/win32/sync/internal.h +++ b/Source/DrangPlatform/Source/win32/sync/internal.h @@ -1,8 +1,8 @@ #pragma once #define WIN32_LEAN_AND_MEAN -#include #include +#include struct drang_mutex { diff --git a/Source/DrangPlatform/Source/win32/sync/mutex.c b/Source/DrangPlatform/Source/win32/sync/mutex.c index 41b98a3..b74d0be 100644 --- a/Source/DrangPlatform/Source/win32/sync/mutex.c +++ b/Source/DrangPlatform/Source/win32/sync/mutex.c @@ -1,9 +1,6 @@ +#include "internal.h" #include #include -#include "internal.h" - - - size_t drang_mutex_size(void) { diff --git a/Source/DrangPlatform/Source/win32/sync/rwlock.c b/Source/DrangPlatform/Source/win32/sync/rwlock.c index 599ca02..5e860e8 100644 --- a/Source/DrangPlatform/Source/win32/sync/rwlock.c +++ b/Source/DrangPlatform/Source/win32/sync/rwlock.c @@ -1,6 +1,6 @@ +#include "internal.h" #include #include -#include "internal.h" size_t drang_rwlock_size(void) {