style: apply consistent formatting and remove unnecessary blank lines

This commit is contained in:
MechSlayer 2025-09-05 16:05:19 +02:00
parent 20e51fd6af
commit 121c54227a
10 changed files with 79 additions and 73 deletions

View file

@ -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. * @remarks If the array grows, new elements are zero-initialized. Similar to _recalloc() on Windows.
*/ */
DRANG_ALLOC_SIZE_COUNT_ATTR(2, 3) DRANG_ALLOC_SIZE_COUNT_ATTR(2, 3)
DRANG_API void *drang_recalloc( DRANG_API void *drang_recalloc(void *ptr, size_t new_num, size_t size);
void *ptr, size_t new_num, size_t size);
/** /**
* @brief Reallocates aligned memory for an array and initializes new elements to zero. * @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_SIZE_COUNT_ATTR(2, 3)
DRANG_ALLOC_ALIGN_ATTR(4) DRANG_ALLOC_ALIGN_ATTR(4)
DRANG_API void *drang_recalloc_aligned( DRANG_API void *drang_recalloc_aligned(void *ptr, size_t new_num, size_t size, size_t alignment);
void *ptr, size_t new_num, size_t size, size_t alignment);
/** /**
* @brief Frees previously allocated memory. * @brief Frees previously allocated memory.
@ -115,9 +113,6 @@ DRANG_API void *drang_recalloc_aligned(
*/ */
DRANG_API void drang_free(void *ptr); DRANG_API void drang_free(void *ptr);
/** /**
* @brief Internal implementation macro for allocation with error handling. * @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 * @remarks This macro calls the allocation function and automatically handles NULL return
* by triggering DRANG error handling with DRANG_ENOMEM. Uses GCC statement expressions. * 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. * @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. * @return Pointer to reallocated memory cast to the appropriate type.
* @remarks Maintains proper alignment during reallocation. * @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. * @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. * @return Pointer to allocated zero-initialized aligned memory.
* @remarks Automatically triggers DRANG error handling if allocation fails. * @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. * @brief Reallocates memory with automatic error handling.
@ -217,7 +219,8 @@ DRANG_API void drang_free(void *ptr);
* @return Pointer to reallocated aligned memory. * @return Pointer to reallocated aligned memory.
* @remarks Automatically triggers DRANG error handling if allocation fails. * @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. * @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. * @return Pointer to reallocated memory.
* @remarks Automatically triggers DRANG error handling if allocation fails. New elements are zero-initialized. * @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. * @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. * @return Pointer to reallocated aligned memory.
* @remarks Automatically triggers DRANG error handling if allocation fails. New elements are zero-initialized. * @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. * @brief Allocates memory for a single typed object with automatic error handling.

View file

@ -7,8 +7,7 @@
# elif defined(__linux__) # elif defined(__linux__)
# define DRANG_API __attribute__((visibility("default"))) # define DRANG_API __attribute__((visibility("default")))
# else # else
# error \ # error "Unknown platform, please implement shared library export macros"
"Unknown platform, please implement shared library export macros"
# endif # endif
# else # else
# ifdef _WIN32 # ifdef _WIN32
@ -16,8 +15,7 @@
# elif defined(__linux__) # elif defined(__linux__)
# define DRANG_API __attribute__((visibility("default"))) # define DRANG_API __attribute__((visibility("default")))
# else # else
# error \ # error "Unknown platform, please implement shared library import macros"
"Unknown platform, please implement shared library import macros"
# endif # endif
# endif # endif
#else #else
@ -32,7 +30,6 @@
# define DRANG_END_DECLS # define DRANG_END_DECLS
#endif #endif
#if defined(__GNUC__) || defined(__clang__) #if defined(__GNUC__) || defined(__clang__)
# define DRANG_PRINTF_ATTR(fmt_idx, arg_idx) __attribute__((format(printf, fmt_idx, arg_idx))) # 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_VPRINTF_ATTR(fmt_idx) __attribute__((format(printf, fmt_idx, 0)))

View file

@ -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_API int drang_rwlock_wrunlock(struct drang_rwlock *rwlock);
DRANG_END_DECLS DRANG_END_DECLS

View file

@ -1,7 +1,6 @@
#include <drang/alloc.h> #include <drang/alloc.h>
#include <mimalloc.h> #include <mimalloc.h>
void *drang_alloc(const size_t size) void *drang_alloc(const size_t size)
{ {
return mi_malloc(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); return mi_recalloc(ptr, new_num, size);
} }
void *drang_recalloc_aligned( void *drang_recalloc_aligned(void *ptr, const size_t new_num, const size_t size, const size_t alignment)
void *ptr, const size_t new_num, const size_t size, const size_t alignment)
{ {
return mi_recalloc_aligned(ptr, new_num, size, alignment); return mi_recalloc_aligned(ptr, new_num, size, alignment);
} }

View file

@ -3,17 +3,29 @@
const char *drang_error_str(const int err) const char *drang_error_str(const int err)
{ {
switch (err) { switch (err) {
case DRANG_EOK: return "No error"; case DRANG_EOK:
case DRANG_EINVAL: return "Invalid argument"; return "No error";
case DRANG_ENOMEM: return "Out of memory"; case DRANG_EINVAL:
case DRANG_EIO: return "I/O error"; return "Invalid argument";
case DRANG_NOTSUP: return "Operation not supported"; case DRANG_ENOMEM:
case DRANG_EAGAIN: return "Resource temporarily unavailable"; return "Out of memory";
case DRANG_ENOENT: return "No such file or directory"; case DRANG_EIO:
case DRANG_EDEADLK: return "Resource deadlock would occur"; return "I/O error";
case DRANG_EPERM: return "Operation not permitted"; case DRANG_NOTSUP:
case DRANG_ETIMEDOUT: return "Connection timed out"; return "Operation not supported";
case DRANG_EBUSY: return "Device or resource busy"; case DRANG_EAGAIN:
default: return "Unknown error"; 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";
} }
} }

View file

@ -1,8 +1,8 @@
#pragma once #pragma once
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdbool.h> #include <stdbool.h>
#include <windows.h>
struct drang_mutex struct drang_mutex
{ {

View file

@ -1,9 +1,6 @@
#include "internal.h"
#include <drang/alloc.h> #include <drang/alloc.h>
#include <drang/sync.h> #include <drang/sync.h>
#include "internal.h"
size_t drang_mutex_size(void) size_t drang_mutex_size(void)
{ {

View file

@ -1,6 +1,6 @@
#include "internal.h"
#include <drang/alloc.h> #include <drang/alloc.h>
#include <drang/sync.h> #include <drang/sync.h>
#include "internal.h"
size_t drang_rwlock_size(void) size_t drang_rwlock_size(void)
{ {