2 +--------------------------------------------------------------------+
3 | libmemcached - C/C++ Client Library for memcached |
4 +--------------------------------------------------------------------+
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted under the terms of the BSD license. |
7 | You should have received a copy of the license in a bundled file |
8 | named LICENSE; in case you did not receive a copy you can review |
9 | the terms online at: https://opensource.org/licenses/BSD-3-Clause |
10 +--------------------------------------------------------------------+
11 | Copyright (c) 2006-2014 Brian Aker https://datadifferential.com/ |
12 | Copyright (c) 2020 Michael Wallner <mike@php.net> |
13 +--------------------------------------------------------------------+
18 #include "mem_config.h"
20 #include "libmemcached/common.h"
30 static inline void libmemcached_free(const memcached_st
*self
, void *mem
) {
32 self
->allocators
.free(self
, mem
, self
->allocators
.context
);
42 static inline void *libmemcached_malloc(const memcached_st
*self
, const size_t size
) {
44 return self
->allocators
.malloc(self
, size
, self
->allocators
.context
);
48 return std::malloc(size
);
53 #define libmemcached_xmalloc(__memcachd_st, __type) \
54 ((__type *) libmemcached_malloc((__memcachd_st), sizeof(__type)))
56 static inline void *libmemcached_realloc(const memcached_st
*self
, void *mem
, size_t nmemb
,
59 return self
->allocators
.realloc(self
, mem
, nmemb
* size
, self
->allocators
.context
);
63 return std::realloc(mem
, size
);
65 return realloc(mem
, size
);
68 #define libmemcached_xrealloc(__memcachd_st, __mem, __nelem, __type) \
69 ((__type *) libmemcached_realloc((__memcachd_st), (__mem), (__nelem), sizeof(__type)))
70 #define libmemcached_xvalloc(__memcachd_st, __nelem, __type) \
71 ((__type *) libmemcached_realloc((__memcachd_st), NULL, (__nelem), sizeof(__type)))
73 static inline void *libmemcached_calloc(const memcached_st
*self
, size_t nelem
, size_t size
) {
75 return self
->allocators
.calloc(self
, nelem
, size
, self
->allocators
.context
);
79 return std::calloc(nelem
, size
);
81 return calloc(nelem
, size
);
84 #define libmemcached_xcalloc(__memcachd_st, __nelem, __type) \
85 ((__type *) libmemcached_calloc((__memcachd_st), (__nelem), sizeof(__type)))