X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libmemcached%2Fmemcached_result.c;h=fac3b8c554d7c794676059ae594d7b8e48747ec5;hb=c5e09c0c3bc8b558f63cb752792ef808076b767f;hp=cf3894bef3b7545fcdaca9be56d6e1883f25b2a3;hpb=34a8c3858f30b02568c87f56a827f618aba6d6be;p=awesomized%2Flibmemcached diff --git a/libmemcached/memcached_result.c b/libmemcached/memcached_result.c index cf3894be..fac3b8c5 100644 --- a/libmemcached/memcached_result.c +++ b/libmemcached/memcached_result.c @@ -11,31 +11,43 @@ memcached_result_st *memcached_result_create(memcached_st *memc, { /* Saving malloc calls :) */ if (ptr) - { memset(ptr, 0, sizeof(memcached_result_st)); - ptr->is_allocated= MEMCACHED_NOT_ALLOCATED; - } else { if (memc->call_malloc) ptr= (memcached_result_st *)memc->call_malloc(memc, sizeof(memcached_result_st)); else - ptr= (memcached_result_st *)malloc(sizeof(memcached_result_st)); + ptr= (memcached_result_st *)calloc(1, sizeof(memcached_result_st)); if (ptr == NULL) return NULL; - memset(ptr, 0, sizeof(memcached_result_st)); - ptr->is_allocated= MEMCACHED_ALLOCATED; + ptr->is_allocated= true; } ptr->root= memc; memcached_string_create(memc, &ptr->value, 0); WATCHPOINT_ASSERT(ptr->value.string == NULL); - WATCHPOINT_ASSERT(ptr->value.is_allocated == MEMCACHED_NOT_ALLOCATED); return ptr; } +void memcached_result_reset(memcached_result_st *ptr) +{ + ptr->key_length= 0; + memcached_string_reset(&ptr->value); + ptr->flags= 0; + ptr->cas= 0; + ptr->expiration= 0; +} + +/* + NOTE turn into macro +*/ +memcached_return memcached_result_set_value(memcached_result_st *ptr, char *value, size_t length) +{ + return memcached_string_append(&ptr->value, value, length); +} + void memcached_result_free(memcached_result_st *ptr) { if (ptr == NULL) @@ -43,8 +55,6 @@ void memcached_result_free(memcached_result_st *ptr) memcached_string_free(&ptr->value); - if (ptr->is_allocated == MEMCACHED_ALLOCATED) + if (ptr->is_allocated) free(ptr); - else - ptr->is_allocated= MEMCACHED_USED; }