tests: fix parser test with config file
[awesomized/libmemcached] / libmemcached / memory.h
index 65d06b8c77a2b8940485db8d43d7258513372933..12d02849124263cce017a35ee6a054d2c101c22f 100644 (file)
 
 #pragma once
 
+#include <mem_config.h>
+
+#include <libmemcached/common.h>
+
+#ifdef __cplusplus
+#include <cstddef>
+#include <cstdlib>
+#else
+#include <stddef.h>
+#include <stdlib.h>
+#endif
+
 static inline void libmemcached_free(const memcached_st *self, void *mem)
 {
   if (self)
@@ -44,7 +56,11 @@ static inline void libmemcached_free(const memcached_st *self, void *mem)
   }
   else if (mem)
   {
+#ifdef __cplusplus
+    std::free(mem);
+#else
     free(mem);
+#endif
   }
 }
 
@@ -55,18 +71,29 @@ static inline void *libmemcached_malloc(const memcached_st *self, const size_t s
     return self->allocators.malloc(self, size, self->allocators.context);
   }
 
+#ifdef __cplusplus
+  return std::malloc(size);
+#else
   return malloc(size);
+#endif
 }
+#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);
+#ifdef __cplusplus
+    return std::realloc(mem, size);
+#else
+    return realloc(mem, size);
+#endif
 }
+#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)
 {
@@ -75,5 +102,10 @@ static inline void *libmemcached_calloc(const memcached_st *self, size_t nelem,
     return self->allocators.calloc(self, nelem, size, self->allocators.context);
   }
 
-  return calloc(nelem, size);
+#ifdef __cplusplus
+    return std::calloc(nelem, size);
+#else
+    return calloc(nelem, size);
+#endif
 }
+#define libmemcached_xcalloc(__memcachd_st, __nelem, __type) ((__type *)libmemcached_calloc((__memcachd_st), (__nelem), sizeof(__type)))