return NULL; /* MEMCACHED_MEMORY_ALLOCATION_FAILURE */
memset(ptr, 0, sizeof(memcached_st));
- ptr->is_allocated= MEMCACHED_ALLOCATED;
+ ptr->is_allocated= true;
}
else
{
free(ptr->continuum);
}
- if (ptr->is_allocated == MEMCACHED_ALLOCATED)
+ if (ptr->is_allocated)
{
if (ptr->call_free)
ptr->call_free(ptr, ptr);
free(ptr);
}
else
- ptr->is_allocated= MEMCACHED_USED;
+ memset(ptr, 0, sizeof(memcached_st));
}
/*
if (source == NULL)
return memcached_create(clone);
- if (clone && clone->is_allocated == MEMCACHED_USED)
+ if (clone && clone->is_allocated)
{
return NULL;
}
#include <stdlib.h>
#include <inttypes.h>
+#if !defined(__cplusplus)
+# include <stdbool.h>
+#endif
#include <sys/types.h>
#include <netinet/in.h>
struct memcached_st {
uint8_t purging;
- memcached_allocated is_allocated;
+ bool is_allocated;
memcached_server_st *hosts;
uint32_t number_of_hosts;
uint32_t cursor_server;
}
}
- if (ptr->sockaddr_inited == MEMCACHED_NOT_ALLOCATED ||
+ if (ptr->sockaddr_inited ||
(!(ptr->root->flags & MEM_USE_CACHE_LOOKUPS)))
{
memcached_return rc;
rc= set_hostinfo(ptr);
if (rc != MEMCACHED_SUCCESS)
return rc;
- ptr->sockaddr_inited= MEMCACHED_ALLOCATED;
+ ptr->sockaddr_inited= true;
}
use= ptr->address_info;
MEMCACHED_CONNECTION_UNIX_SOCKET
} memcached_connection;
-typedef enum {
- MEMCACHED_NOT_ALLOCATED,
- MEMCACHED_ALLOCATED,
- MEMCACHED_USED
-} memcached_allocated;
-
-
#ifdef __cplusplus
}
#endif
if (result == NULL)
result= memcached_result_create(ptr, NULL);
- WATCHPOINT_ASSERT(result->value.is_allocated != MEMCACHED_USED);
-
#ifdef UNUSED
if (ptr->flags & MEM_NO_BLOCK)
memcached_io_preread(ptr);
}
/* We have completed reading data */
- if (result->is_allocated == MEMCACHED_ALLOCATED)
+ if (result->is_allocated)
memcached_result_free(result);
else
memcached_string_reset(&result->value);
{
/* Saving malloc calls :) */
if (ptr)
- {
memset(ptr, 0, sizeof(memcached_result_st));
- ptr->is_allocated= MEMCACHED_NOT_ALLOCATED;
- }
else
{
if (memc->call_malloc)
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;
}
memcached_string_free(&ptr->value);
- if (ptr->is_allocated == MEMCACHED_ALLOCATED)
+ if (ptr->is_allocated)
free(ptr);
- else
- ptr->is_allocated= MEMCACHED_USED;
}
#endif
struct memcached_result_st {
- memcached_allocated is_allocated;
+ bool is_allocated;
memcached_st *root;
char key[MEMCACHED_MAX_KEY];
size_t key_length;
return NULL; /* MEMCACHED_MEMORY_ALLOCATION_FAILURE */
memset(ptr, 0, sizeof(memcached_server_st));
- ptr->is_allocated= MEMCACHED_ALLOCATED;
+ ptr->is_allocated= true;
}
else
- {
- ptr->is_allocated= MEMCACHED_USED;
memset(ptr, 0, sizeof(memcached_server_st));
- }
ptr->root= memc;
host->read_ptr= host->read_buffer;
if (memc)
host->next_retry= memc->retry_timeout;
- host->sockaddr_inited= MEMCACHED_NOT_ALLOCATED;
return host;
}
ptr->address_info= NULL;
}
- if (ptr->is_allocated == MEMCACHED_ALLOCATED)
+ if (ptr->is_allocated)
{
if (ptr->root && ptr->root->call_free)
ptr->root->call_free(ptr->root, ptr);
else
free(ptr);
}
+ else
+ memset(ptr, 0, sizeof(memcached_server_st));
}
/*
*/
memcached_server_st *memcached_server_clone(memcached_server_st *clone, memcached_server_st *ptr)
{
- memcached_server_st *new_clone;
-
/* We just do a normal create if ptr is missing */
if (ptr == NULL)
return NULL;
- if (clone && clone->is_allocated == MEMCACHED_USED)
- {
- WATCHPOINT_ASSERT(0);
- return NULL;
- }
-
- new_clone= memcached_server_create(ptr->root, clone);
-
- if (new_clone == NULL)
- return NULL;
-
- new_clone->root= ptr->root;
-
/* TODO We should check return type */
- memcached_server_create_with(new_clone->root, new_clone,
- ptr->hostname, ptr->port, ptr->weight,
- ptr->type);
-
- return new_clone;
+ return memcached_server_create_with(ptr->root, clone,
+ ptr->hostname, ptr->port, ptr->weight,
+ ptr->type);
}
memcached_return memcached_server_cursor(memcached_st *ptr,
#endif
struct memcached_server_st {
- memcached_allocated is_allocated;
+ bool is_allocated;
char hostname[MEMCACHED_MAX_HOST_LENGTH];
unsigned int port;
int fd;
size_t read_data_length;
size_t read_buffer_length;
char *read_ptr;
- memcached_allocated sockaddr_inited;
+ bool sockaddr_inited;
struct addrinfo *address_info;
memcached_connection type;
uint8_t major_version;
/* Saving malloc calls :) */
if (string)
- {
memset(string, 0, sizeof(memcached_string_st));
- string->is_allocated= MEMCACHED_NOT_ALLOCATED;
- }
else
{
if (ptr->call_malloc)
if (string == NULL)
return NULL;
memset(string, 0, sizeof(memcached_string_st));
- string->is_allocated= MEMCACHED_ALLOCATED;
+ string->is_allocated= true;
}
string->block_size= MEMCACHED_BLOCK_SIZE;
string->root= ptr;
{
memcached_return rc;
- WATCHPOINT_ASSERT(string->is_allocated != MEMCACHED_USED);
-
rc= memcached_string_check(string, 1);
if (rc != MEMCACHED_SUCCESS)
{
memcached_return rc;
- WATCHPOINT_ASSERT(string->is_allocated != MEMCACHED_USED);
-
rc= memcached_string_check(string, length);
if (rc != MEMCACHED_SUCCESS)
{
char *c_ptr;
- WATCHPOINT_ASSERT(string->is_allocated != MEMCACHED_USED);
-
if (memcached_string_length(string) == 0)
return NULL;
memcached_return memcached_string_reset(memcached_string_st *string)
{
- WATCHPOINT_ASSERT(string->is_allocated != MEMCACHED_USED);
string->end= string->string;
return MEMCACHED_SUCCESS;
free(ptr->string);
}
- if (ptr->is_allocated == MEMCACHED_ALLOCATED)
+ if (ptr->is_allocated)
{
if (ptr->root->call_free)
ptr->root->call_free(ptr->root, ptr);
free(ptr);
}
else
- ptr->is_allocated= MEMCACHED_USED;
+ memset(ptr, 0, sizeof(memcached_string_st));
}
struct memcached_string_st {
memcached_st *root;
- memcached_allocated is_allocated;
+ bool is_allocated;
char *end;
size_t current_size;
size_t block_size;
memcached_server_free(s);
memcached_free(m);
+
+ return 0;
}
#include "ketama_test_cases.h"
/* VDEAAAAA hashes to fffcd1b5, after the last continuum point, and lets
* us test the boundary wraparound.
*/
- assert(memcached_generate_hash(memc, (unsigned char *)"VDEAAAAA", 8) == memc->continuum[0].index);
+ assert(memcached_generate_hash(memc, (char *)"VDEAAAAA", 8) == memc->continuum[0].index);
/* verify the standard ketama set. */
for (i= 0; i < 99; i++)
memcached_result_st *result_ptr;
result_ptr= memcached_result_create(memc, &result);
- assert(result.is_allocated == MEMCACHED_NOT_ALLOCATED);
+ assert(result.is_allocated == false);
assert(result_ptr);
memcached_result_free(&result);
memcached_string_st *string_ptr;
string_ptr= memcached_string_create(memc, &string, 0);
- assert(string.is_allocated == MEMCACHED_NOT_ALLOCATED);
+ assert(string.is_allocated == false);
assert(string_ptr);
memcached_string_free(&string);