if (flags)
*flags= result_buffer->item_flags;
- return memcached_string_c_copy(&result_buffer->value);
+ return memcached_string_take_value(&result_buffer->value);
}
memcached_result_st *memcached_fetch_result(memcached_st *ptr,
{
if (ptr->get_key_failure && *error == MEMCACHED_NOTFOUND)
{
-
memcached_result_reset(&ptr->result);
memcached_return_t rc= ptr->get_key_failure(ptr, key, key_length, &ptr->result);
*error= rc;
*value_length= memcached_result_length(&ptr->result);
*flags= memcached_result_flags(&ptr->result);
- return memcached_string_c_copy(&ptr->result.value);
+ return memcached_string_take_value(&ptr->result.value);
}
}
}
#include <libmemcached/common.h>
+#include <cassert>
inline static memcached_return_t _string_check(memcached_string_st *string, size_t need)
{
return self;
}
+static memcached_return_t memcached_string_append_null(memcached_string_st *string)
+{
+ if (memcached_failed(_string_check(string, 1)))
+ {
+ return MEMCACHED_MEMORY_ALLOCATION_FAILURE;
+ }
+
+ *string->end= 0;
+
+ return MEMCACHED_SUCCESS;
+}
+
memcached_return_t memcached_string_append_character(memcached_string_st *string,
char character)
{
return self->string;
}
+char *memcached_string_take_value(memcached_string_st *self)
+{
+ assert(self);
+ // If we fail at adding the null, we copy and move on
+ if (memcached_success(memcached_string_append_null(self)))
+ {
+ return memcached_string_c_copy(self);
+ }
+
+ char *value= self->string;
+
+ _init_string(self);
+
+ return value;
+}
+
char *memcached_string_value_mutable(const memcached_string_st *self)
{
return self->string;
LIBMEMCACHED_LOCAL
const char *memcached_string_value(const memcached_string_st *self);
+LIBMEMCACHED_LOCAL
+char *memcached_string_take_value(memcached_string_st *self);
+
LIBMEMCACHED_LOCAL
char *memcached_string_value_mutable(const memcached_string_st *self);
&string_length, &flags, &rc);
test_compare(MEMCACHED_SUCCESS, rc);
- test_compare(string_length, strlen(READ_THROUGH_VALUE));
+ test_compare(string_length, sizeof(READ_THROUGH_VALUE) -1);
+ test_true(string[sizeof(READ_THROUGH_VALUE) -1] == 0);
test_strcmp(READ_THROUGH_VALUE, string);
free(string);
&string_length, &flags, &rc);
test_compare(MEMCACHED_SUCCESS, rc);
- test_compare(string_length, strlen(READ_THROUGH_VALUE));
+ test_true(string);
+ test_compare(string_length, sizeof(READ_THROUGH_VALUE) -1);
+ test_true(string[sizeof(READ_THROUGH_VALUE) -1] == 0);
test_strcmp(READ_THROUGH_VALUE, string);
free(string);
uint32_t x;
memcached_return_t rc;
const char *key= "mykey";
- char *value;
size_t length;
uint32_t flags;
test_compare(MEMCACHED_SUCCESS, rc);
- value= memcached_get(memc, key, strlen(key),
- &length, &flags, &rc);
+ char *value= memcached_get(memc, key, strlen(key),
+ &length, &flags, &rc);
test_compare(MEMCACHED_SUCCESS, rc);
- test_true(value == NULL);
- test_true(length == 0);
- test_true(flags == 0);
+ test_false(value);
+ test_false(length);
+ test_false(flags);
value= memcached_get(memc, key, strlen(key),
&length, &flags, &rc);