memcached_result_create, memcached_result_free,
memcached_result_key_value, memcached_result_key_length,
memcached_result_value, memcached_result_length,
-memcached_result_flags, memcached_result_cas - Work with results
+memcached_result_flags, memcached_result_cas - Work with memcached_result_st
=head1 LIBRARY
memcached_result_create (memcached_st *ptr,
memcached_result_st *result);
- void memcached_result_free(memcached_result_st *result);
+ void memcached_result_free (memcached_result_st *result);
- char * memcached_result_key_value (memcached_result_st *result);
+ const char * memcached_result_key_value (memcached_result_st *result);
- size_t memcached_result_key_length (memcached_result_st *result);
+ size_t memcached_result_key_length (const memcached_result_st *result);
- char *memcached_result_value (memcached_result_st *ptr);
+ const char *memcached_result_value (memcached_result_st *ptr);
- size_t memcached_result_length (memcached_result_st *ptr);
+ size_t memcached_result_length (const memcached_result_st *ptr);
- uint32_t memcached_result_flags (memcached_result_st *result)
+ uint32_t memcached_result_flags (const memcached_result_st *result)
- uint64_t memcached_result_cas (memcached_result_st *result);
+ uint64_t memcached_result_cas (const memcached_result_st *result);
memcached_return_t
memcached_result_set_value (memcached_result_st *ptr,
#define memcached_is_processing_input(__object) ((__object)->flags.is_processing_input)
#define memcached_set_purging(__object, __value) ((__object)->flags.is_purging= (__value))
#define memcached_set_processing_input(__object, __value) ((__object)->flags.is_processing_input= (__value))
+#define memcached_set_initialized(__object, __value) ((__object)->options.is_initialized(= (__value))
+#define memcached_set_allocated(__object, __value) ((__object)->options.is_allocated(= (__value))
#ifdef __cplusplus
}
ptr->expiration= 0;
}
-/*
- NOTE turn into macro
-*/
-memcached_return_t memcached_result_set_value(memcached_result_st *ptr, const char *value, size_t length)
-{
- return memcached_string_append(&ptr->value, value, length);
-}
-
void memcached_result_free(memcached_result_st *ptr)
{
if (ptr == NULL)
ptr->options.is_initialized= false;
}
}
-
-
-char *memcached_result_value(memcached_result_st *ptr)
-{
- memcached_string_st *sptr= &ptr->value;
- return memcached_string_value(sptr);
-}
-
-size_t memcached_result_length(memcached_result_st *ptr)
-{
- memcached_string_st *sptr= &ptr->value;
- return memcached_string_length(sptr);
-}
-
LIBMEMCACHED_API
memcached_result_st *memcached_result_create(memcached_st *ptr,
memcached_result_st *result);
-#define memcached_result_key_value(A) (A)->key
-#define memcached_result_key_length(A) (A)->key_length
-#define memcached_result_string_st(A) ((A)->value)
-#ifdef FIX
-#define memcached_result_value(A) memcached_string_value((A)->value)
-#define memcached_result_length(A) memcached_string_length((A)->value)
-#else
-LIBMEMCACHED_API
-char *memcached_result_value(memcached_result_st *ptr);
+static inline const char *memcached_result_key_value(const memcached_result_st *self)
+{
+ return self->key;
+}
-LIBMEMCACHED_API
-size_t memcached_result_length(memcached_result_st *ptr);
+static inline size_t memcached_result_key_length(const memcached_result_st *self)
+{
+ return self->key_length;
+}
-#endif
-#define memcached_result_flags(A) (A)->flags
-#define memcached_result_cas(A) (A)->cas
-LIBMEMCACHED_API
-memcached_return_t memcached_result_set_value(memcached_result_st *ptr, const char *value, size_t length);
-#define memcached_result_set_flags(A,B) (A)->flags=(B)
-#define memcached_result_set_expiration(A,B) (A)->expiration=(B)
+static inline const char *memcached_result_value(const memcached_result_st *self)
+{
+ const memcached_string_st *sptr= &self->value;
+ return memcached_string_value(sptr);
+}
+
+static inline size_t memcached_result_length(const memcached_result_st *self)
+{
+ const memcached_string_st *sptr= &self->value;
+ return memcached_string_length(sptr);
+}
+
+static inline uint32_t memcached_result_flags(const memcached_result_st *self)
+{
+ return self->flags;
+}
+
+static inline uint64_t memcached_result_cas(const memcached_result_st *self)
+{
+ return self->cas;
+}
+
+static inline memcached_return_t memcached_result_set_value(memcached_result_st *ptr, const char *value, size_t length)
+{
+ return memcached_string_append(&ptr->value, value, length);
+}
+
+static inline void memcached_result_set_flags(memcached_result_st *self, uint32_t flags)
+{
+ self->flags= flags;
+}
+
+static inline void memcached_result_set_expiration(memcached_result_st *self, uint32_t expiration)
+{
+ self->expiration= expiration;
+}
#ifdef __cplusplus
}
size_t new_size;
/* This is the block multiplier. To keep it larger and surive division errors we must round it up */
- adjust= (need - (size_t)(string->current_size - (size_t)(string->end - string->string))) / string->block_size;
+ adjust= (need - (size_t)(string->current_size - (size_t)(string->end - string->string))) / MEMCACHED_BLOCK_SIZE;
adjust++;
- new_size= sizeof(char) * (size_t)((adjust * string->block_size) + string->current_size);
+ new_size= sizeof(char) * (size_t)((adjust * MEMCACHED_BLOCK_SIZE) + string->current_size);
/* Test for overflow */
if (new_size < need)
return MEMCACHED_MEMORY_ALLOCATION_FAILURE;
string->string= new_value;
string->end= string->string + current_offset;
- string->current_size+= (string->block_size * adjust);
+ string->current_size+= (MEMCACHED_BLOCK_SIZE * adjust);
}
return MEMCACHED_SUCCESS;
}
-memcached_string_st *memcached_string_create(memcached_st *memc, memcached_string_st *string, size_t initial_size)
+static inline void _init_string(memcached_string_st *self)
+{
+ self->current_size= 0;
+ self->end= self->string= NULL;
+}
+
+memcached_string_st *memcached_string_create(memcached_st *memc, memcached_string_st *self, size_t initial_size)
{
memcached_return_t rc;
+ WATCHPOINT_ASSERT(memc);
+
/* Saving malloc calls :) */
- if (string)
+ if (self)
{
- WATCHPOINT_ASSERT(string->options.is_initialized == false);
+ WATCHPOINT_ASSERT(self->options.is_initialized == false);
- memset(string, 0, sizeof(memcached_string_st));
+ self->options.is_allocated= false;
}
else
{
- string= memc->call_calloc(memc, 1, sizeof(memcached_string_st));
+ self= memc->call_malloc(memc, sizeof(memcached_string_st));
- if (string == NULL)
+ if (self == NULL)
{
return NULL;
}
- string->options.is_allocated= true;
+ self->options.is_allocated= true;
}
- string->block_size= MEMCACHED_BLOCK_SIZE;
- string->root= memc;
+ self->root= memc;
+
+ _init_string(self);
- rc= _string_check(string, initial_size);
+ rc= _string_check(self, initial_size);
if (rc != MEMCACHED_SUCCESS)
{
- memc->call_free(memc, string);
+ memc->call_free(memc, self);
return NULL;
}
- string->options.is_initialized= true;
+ self->options.is_initialized= true;
- WATCHPOINT_ASSERT(string->string == string->end);
+ WATCHPOINT_ASSERT(self->string == self->end);
- return string;
+ return self;
}
memcached_return_t memcached_string_append_character(memcached_string_st *string,
else
{
ptr->options.is_initialized= false;
- memset(ptr, 0, sizeof(memcached_string_st));
}
}
extern "C" {
#endif
+/**
+ Strings are always under our control so we make some assumptions
+ about them.
+
+ 1) is_initialized is always valid.
+ 2) A string once intialized will always be, until free where we
+ unset this flag.
+ 3) A string always has a root.
+*/
+
struct memcached_string_st {
memcached_st *root;
char *end;
char *string;
size_t current_size;
- size_t block_size;
struct {
bool is_allocated:1;
bool is_initialized:1;