style: apply consistent formatting and remove unnecessary blank lines
This commit is contained in:
parent
20e51fd6af
commit
121c54227a
10 changed files with 79 additions and 73 deletions
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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,7 +30,6 @@
|
|||
# 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)))
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
#include <drang/alloc.h>
|
||||
#include <mimalloc.h>
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
#pragma once
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <stdbool.h>
|
||||
#include <windows.h>
|
||||
|
||||
struct drang_mutex
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,9 +1,6 @@
|
|||
#include "internal.h"
|
||||
#include <drang/alloc.h>
|
||||
#include <drang/sync.h>
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
|
||||
|
||||
size_t drang_mutex_size(void)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#include "internal.h"
|
||||
#include <drang/alloc.h>
|
||||
#include <drang/sync.h>
|
||||
#include "internal.h"
|
||||
|
||||
size_t drang_rwlock_size(void)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue