X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libmemcached%2Fmemory.h;h=dd0092370aa7e35e21455f06885f8c1fa5f71458;hb=c6581942a9f3089c1d14e2cbc749d47a93247e78;hp=65d06b8c77a2b8940485db8d43d7258513372933;hpb=fbe4a2e21817d0c106db22ab83aab053ccc89a05;p=m6w6%2Flibmemcached diff --git a/libmemcached/memory.h b/libmemcached/memory.h index 65d06b8c..dd009237 100644 --- a/libmemcached/memory.h +++ b/libmemcached/memory.h @@ -36,6 +36,16 @@ #pragma once +#include + +#ifdef __cplusplus +#include +#include +#else +#include +#include +#endif + static inline void libmemcached_free(const memcached_st *self, void *mem) { if (self) @@ -57,16 +67,19 @@ static inline void *libmemcached_malloc(const memcached_st *self, const size_t s return malloc(size); } +#define libmemcached_xmalloc(__memcachd_st, __type) ((__type *)libmemcached_malloc((__memcachd_st), sizeof(__type))) -static inline void *libmemcached_realloc(const memcached_st *self, void *mem, const size_t size) +static inline void *libmemcached_realloc(const memcached_st *self, void *mem, size_t nmemb, const size_t size) { if (self) { - return self->allocators.realloc(self, mem, size, self->allocators.context); + return self->allocators.realloc(self, mem, nmemb * size, self->allocators.context); } return realloc(mem, size); } +#define libmemcached_xrealloc(__memcachd_st, __mem, __nelem, __type) ((__type *)libmemcached_realloc((__memcachd_st), (__mem), (__nelem), sizeof(__type))) +#define libmemcached_xvalloc(__memcachd_st, __nelem, __type) ((__type *)libmemcached_realloc((__memcachd_st), NULL, (__nelem), sizeof(__type))) static inline void *libmemcached_calloc(const memcached_st *self, size_t nelem, size_t size) { @@ -77,3 +90,4 @@ static inline void *libmemcached_calloc(const memcached_st *self, size_t nelem, return calloc(nelem, size); } +#define libmemcached_xcalloc(__memcachd_st, __nelem, __type) ((__type *)libmemcached_calloc((__memcachd_st), (__nelem), sizeof(__type)))