X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libmemcached%2Fallocators.cc;h=f1caf71ec373eab433bd3832d5d010a3218f2b45;hb=61b948a92ab79734b009a438b5cf3bfad03cb59d;hp=aaa66dbaf21219dbe9645062b70f072287387814;hpb=09b4ff9a9b7c62b4511ab10c9305eba757fea34b;p=awesomized%2Flibmemcached diff --git a/libmemcached/allocators.cc b/libmemcached/allocators.cc index aaa66dba..f1caf71e 100644 --- a/libmemcached/allocators.cc +++ b/libmemcached/allocators.cc @@ -59,8 +59,8 @@ void *_libmemcached_calloc(const memcached_st *self, size_t nelem, size_t size, { if (self->allocators.malloc != _libmemcached_malloc) { - void *ret = _libmemcached_malloc(self, nelem * size, context); - if (ret == NULL) + void *ret= _libmemcached_malloc(self, nelem * size, context); + if (ret) { memset(ret, 0, nelem * size); } @@ -77,13 +77,14 @@ struct memcached_allocator_t memcached_allocators_return_default(void) return global_default_allocator; } -memcached_return_t memcached_set_memory_allocators(memcached_st *self, +memcached_return_t memcached_set_memory_allocators(memcached_st *shell, memcached_malloc_fn mem_malloc, memcached_free_fn mem_free, memcached_realloc_fn mem_realloc, memcached_calloc_fn mem_calloc, void *context) { + Memcached* self= memcached2Memcached(shell); if (self == NULL) { return MEMCACHED_INVALID_ARGUMENTS; @@ -110,39 +111,44 @@ memcached_return_t memcached_set_memory_allocators(memcached_st *self, return MEMCACHED_SUCCESS; } -void *memcached_get_memory_allocators_context(const memcached_st *self) +void *memcached_get_memory_allocators_context(const memcached_st *shell) { - return self->allocators.context; + const Memcached* self= memcached2Memcached(shell); + if (self) + { + return self->allocators.context; + } + + return NULL; } -void memcached_get_memory_allocators(const memcached_st *self, +void memcached_get_memory_allocators(const memcached_st *shell, memcached_malloc_fn *mem_malloc, memcached_free_fn *mem_free, memcached_realloc_fn *mem_realloc, memcached_calloc_fn *mem_calloc) { - if (self == NULL) - { - return; - } - - if (mem_malloc) - { - *mem_malloc= self->allocators.malloc; - } - - if (mem_free) - { - *mem_free= self->allocators.free; - } - - if (mem_realloc) - { - *mem_realloc= self->allocators.realloc; - } - - if (mem_calloc) + const Memcached* self= memcached2Memcached(shell); + if (self) { - *mem_calloc= self->allocators.calloc; + if (mem_malloc) + { + *mem_malloc= self->allocators.malloc; + } + + if (mem_free) + { + *mem_free= self->allocators.free; + } + + if (mem_realloc) + { + *mem_realloc= self->allocators.realloc; + } + + if (mem_calloc) + { + *mem_calloc= self->allocators.calloc; + } } }