From c7729ca25ceb8656a4b9b5377d4d34615c297bfc Mon Sep 17 00:00:00 2001 From: eehouse Date: Sat, 2 Jan 2010 01:42:07 +0000 Subject: [PATCH] add a calloc to mempool --- xwords4/common/comtypes.h | 2 ++ xwords4/common/mempool.c | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/xwords4/common/comtypes.h b/xwords4/common/comtypes.h index c6a7c215f..8c58253fa 100644 --- a/xwords4/common/comtypes.h +++ b/xwords4/common/comtypes.h @@ -178,6 +178,8 @@ typedef struct CommonPrefs { #ifdef MEM_DEBUG # define XP_MALLOC(pool,nbytes) \ mpool_alloc((pool),(nbytes),__FILE__,__func__, __LINE__) +# define XP_CALLOC(pool,nbytes) \ + mpool_calloc((pool),(nbytes),__FILE__,__func__, __LINE__) # define XP_REALLOC(pool,p,s) \ mpool_realloc((pool),(p),(s),__FILE__,__func__,__LINE__) # define XP_FREE(pool,p) \ diff --git a/xwords4/common/mempool.c b/xwords4/common/mempool.c index 68cfe878a..31c06f9d4 100644 --- a/xwords4/common/mempool.c +++ b/xwords4/common/mempool.c @@ -161,6 +161,15 @@ mpool_alloc( MemPoolCtx* mpool, XP_U32 size, const char* file, return entry->ptr; } /* mpool_alloc */ +void* +mpool_calloc( MemPoolCtx* mpool, XP_U32 size, const char* file, + const char* func, XP_U32 lineNo ) +{ + void* ptr = mpool_alloc( mpool, size, file, func, lineNo ); + XP_MEMSET( ptr, 0, size ); + return ptr; +} + static MemPoolEntry* findEntryFor( MemPoolCtx* mpool, void* ptr, MemPoolEntry** prevP ) {