Add Xaligned_calloc()

git-svn-id: https://svn.eduke32.com/eduke32@8371 1a8010ca-5511-0410-912e-c29ae57300e0

# Conflicts:
#	source/build/include/compat.h
This commit is contained in:
terminx 2019-12-07 23:50:16 +00:00 committed by Christoph Oelckers
parent c851da92a6
commit 15b76f2041

View file

@ -1243,8 +1243,21 @@ static FORCE_INLINE void *xaligned_alloc(const bsize_t alignment, const bsize_t
void *ptr = Baligned_alloc(alignment, size); void *ptr = Baligned_alloc(alignment, size);
return (EDUKE32_PREDICT_TRUE(ptr != NULL)) ? ptr : handle_memerr(ptr); return (EDUKE32_PREDICT_TRUE(ptr != NULL)) ? ptr : handle_memerr(ptr);
} }
static FORCE_INLINE void *xaligned_calloc(const bsize_t alignment, const bsize_t count, const bsize_t size)
{
bsize_t const blocksize = count * size;
void *ptr = Baligned_alloc(alignment, blocksize);
if (EDUKE32_PREDICT_TRUE(ptr != NULL))
{
Bmemset(ptr, 0, blocksize);
return ptr;
}
return handle_memerr(ptr);
}
#else #else
# define xaligned_alloc(alignment, size) xmalloc(size) # define xaligned_alloc(alignment, size) xmalloc(size)
# define xaligned_calloc(alignment, count, size) xcalloc(count, size)
#endif #endif
#ifdef DEBUGGINGAIDS #ifdef DEBUGGINGAIDS
@ -1258,6 +1271,7 @@ static FORCE_INLINE void *xaligned_alloc(const bsize_t alignment, const bsize_t
#define Xcalloc(nmemb, size) (EDUKE32_PRE_XALLOC xcalloc(nmemb, size)) #define Xcalloc(nmemb, size) (EDUKE32_PRE_XALLOC xcalloc(nmemb, size))
#define Xrealloc(ptr, size) (EDUKE32_PRE_XALLOC xrealloc(ptr, size)) #define Xrealloc(ptr, size) (EDUKE32_PRE_XALLOC xrealloc(ptr, size))
#define Xaligned_alloc(alignment, size) (EDUKE32_PRE_XALLOC xaligned_alloc(alignment, size)) #define Xaligned_alloc(alignment, size) (EDUKE32_PRE_XALLOC xaligned_alloc(alignment, size))
#define Xaligned_calloc(alignment, count, size) (EDUKE32_PRE_XALLOC xaligned_calloc(alignment, count, size))
#define Xfree(ptr) (EDUKE32_PRE_XALLOC xfree(ptr)) #define Xfree(ptr) (EDUKE32_PRE_XALLOC xfree(ptr))
#define Xaligned_free(ptr) (EDUKE32_PRE_XALLOC xaligned_free(ptr)) #define Xaligned_free(ptr) (EDUKE32_PRE_XALLOC xaligned_free(ptr))