#include <libmemcached/common.h>
+#include <cassert>
inline static memcached_return_t _string_check(memcached_string_st *string, size_t need)
{
{
WATCHPOINT_ASSERT(self->options.is_initialized == false);
- self->options.is_allocated= false;
+ memcached_set_allocated(self, false);
}
else
{
return NULL;
}
- self->options.is_allocated= true;
+ memcached_set_allocated(self, true);
}
self->root= memc;
if (memcached_failed(_string_check(self, initial_size)))
{
- libmemcached_free(memc, self);
+ if (memcached_is_allocated(self))
+ {
+ libmemcached_free(memc, self);
+ }
return NULL;
}
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;