if((servers[x]= memcached_create(NULL)) == NULL)
{
fprintf(stderr, "Failed to memcached_create()\n");
+ if (x > 0)
+ memcached_free(servers[0]);
x--;
- for (; x >= 0; x--)
+ for (; x > 0; x--)
memcached_free(servers[x]);
+
free(servers);
return;
}
AC_INIT(clients/memcat.c)
AC_CONFIG_AUX_DIR(config)
AM_CONFIG_HEADER(libmemcached/libmemcached_config.h)
-AC_CANONICAL_SYSTEM
+
+# Setting CFLAGS here prevents AC_CANONICAL_TARGET from injecting them
+SAVE_CFLAGS=${CFLAGS}
+SAVE_CXXFLAGS=${CXXFLAGS}
+CFLAGS=
+CXXFLAGS=
+
+AC_CANONICAL_TARGET
+
+CFLAGS=${SAVE_CFLAGS}
+CXXFLAGS=${SAVE_CXXFLAGS}
MEMCACHED_LIBRARY_NAME=libmemcached
VERSION=$MEMCACHED_RELEASE
-AM_INIT_AUTOMAKE($PACKAGE, $VERSION, no-define)
+AM_INIT_AUTOMAKE($PACKAG$, $VERSION, nostdinc no-define -Wall -Werror)
AC_PROG_CC
AC_PROG_CC_C99
AC_SEARCH_LIBS(getopt_long, gnugetopt)
AC_SEARCH_LIBS(socket, socket)
AC_SEARCH_LIBS(gethostbyname, nsl)
+AC_SEARCH_LIBS(floorf, m)
sinclude(config/pod2man.m4)
sinclude(config/debug.m4)
if test "$GCC" = "yes"
then
#CFLAGS="-W -std=iso9899:1999 -Wall -Wextra -Wstrict-aliasing -pedantic -Wundef -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -O3 $CFLAGS"
- CFLAGS="-Wall -O3 $CFLAGS"
+ CFLAGS="-W -Wall -Wextra -Wno-strict-aliasing -pedantic -Werror -O3 -ggdb $CFLAGS"
if test "$ENABLE_DEBUG" = "yes"
then
fi
fi
-LDFLAGS="-lm"
+
+AM_CPPFLAGS="${CPPFLAGS}"
+AM_CFLAGS="${CFLAGS}"
+AM_CXXFLAGS="${CXXFLAGS}"
+
+AC_SUBST([AM_CPPFLAGS])
+AC_SUBST([AM_CFLAGS])
+AC_SUBST([AM_CXXFLAGS])
+
+dnl We've collected the flags in AM_*FLAGS now, so blank these.
+CFLAGS=""
+CXXFLAGS=""
+CPPFLAGS=""
AC_OUTPUT(Makefile clients/Makefile tests/Makefile docs/Makefile libmemcached/Makefile libmemcachedutil/Makefile support/Makefile support/libmemcached.pc support/libmemcached.spec support/libmemcached-fc.spec)
BUILT_SOURCES= @DTRACE_HEADER@
-INCLUDES = -I$(top_builddir)
-LIBS = @LIBS@
+INCLUDES = -I$(top_builddir) -I$(top_srcdir)
EXTRA_HEADERS =
DTRACE = @DTRACE@
libmemcached_la_SOURCES += byteorder.c
endif
-AM_CFLAGS = -DMEMCACHED_INTERNAL
+DEFS += -DMEMCACHED_INTERNAL
libmemcached_la_DEPENDENCIES = @DTRACE_OBJ@
libmemcached_la_LIBADD = @DTRACE_OBJ@
-libmemcached_la_LDFLAGS = -version-info $(MEMCACHED_LIBRARY_VERSION)
+libmemcached_la_LDFLAGS = -version-info $(MEMCACHED_LIBRARY_VERSION) $(LIBM)
dtrace_probes.h: libmemcached_probes.d
$(DTRACE) $(DTRACEFLAGS) -o dtrace_probes.tmp -h -s libmemcached_probes.d
#ifndef __COMMON_H__
#define __COMMON_H__
+#include "libmemcached_config.h"
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/un.h>
#include <netinet/tcp.h>
+
+#include <memcached.h>
+#include "memcached_io.h"
+
+#include "memcached/protocol_binary.h"
+
#ifdef TIME_WITH_SYS_TIME
# include <sys/time.h>
# include <time.h>
-#include <memcached.h>
-#include "memcached_io.h"
-
-#include "memcached/protocol_binary.h"
-#include "libmemcached_config.h"
-
#if !defined(__GNUC__) || (__GNUC__ == 2 && __GNUC_MINOR__ < 96)
#define likely(x) if((x))
const long max_allowed_bytes,
const long used_bytes)
{
- long remaining_bytes= max_allowed_bytes - used_bytes;
+ uint64_t remaining_bytes= (uint64_t)max_allowed_bytes - used_bytes;
if (result->least_remaining_bytes == 0 ||
remaining_bytes < result->least_remaining_bytes)
}
case MEMCACHED_CALLBACK_CLEANUP_FUNCTION:
{
- memcached_cleanup_func func= (memcached_cleanup_func)data;
+ memcached_cleanup_func func= *(memcached_cleanup_func *)&data;
ptr->on_cleanup= func;
break;
}
case MEMCACHED_CALLBACK_CLONE_FUNCTION:
{
- memcached_clone_func func= (memcached_clone_func)data;
+ memcached_clone_func func= *(memcached_clone_func *)&data;
ptr->on_clone= func;
break;
}
case MEMCACHED_CALLBACK_MALLOC_FUNCTION:
{
- memcached_malloc_function func= (memcached_malloc_function)data;
+ memcached_malloc_function func= *(memcached_malloc_function *)&data;
ptr->call_malloc= func;
break;
}
case MEMCACHED_CALLBACK_REALLOC_FUNCTION:
{
- memcached_realloc_function func= (memcached_realloc_function)data;
+ memcached_realloc_function func= *(memcached_realloc_function *)&data;
ptr->call_realloc= func;
break;
}
case MEMCACHED_CALLBACK_FREE_FUNCTION:
{
- memcached_free_function func= (memcached_free_function)data;
+ memcached_free_function func= *(memcached_free_function *)&data;
ptr->call_free= func;
break;
}
case MEMCACHED_CALLBACK_GET_FAILURE:
{
- memcached_trigger_key func= (memcached_trigger_key)data;
+ memcached_trigger_key func= *(memcached_trigger_key *)&data;
ptr->get_key_failure= func;
break;
}
case MEMCACHED_CALLBACK_DELETE_TRIGGER:
{
- memcached_trigger_delete_key func= (memcached_trigger_delete_key)data;
+ memcached_trigger_delete_key func= *(memcached_trigger_delete_key *)&data;
ptr->delete_trigger= func;
break;
}
memcached_return *error)
{
memcached_return local_error;
+
if (!error)
error = &local_error;
case MEMCACHED_CALLBACK_CLEANUP_FUNCTION:
{
*error= ptr->on_cleanup ? MEMCACHED_SUCCESS : MEMCACHED_FAILURE;
- return (void *)ptr->on_cleanup;
+ return *(void **)&ptr->on_cleanup;
}
case MEMCACHED_CALLBACK_CLONE_FUNCTION:
{
*error= ptr->on_clone ? MEMCACHED_SUCCESS : MEMCACHED_FAILURE;
- return (void *)ptr->on_clone;
+ return *(void **)&ptr->on_clone;
}
case MEMCACHED_CALLBACK_MALLOC_FUNCTION:
{
*error= ptr->call_malloc ? MEMCACHED_SUCCESS : MEMCACHED_FAILURE;
- return (void *)ptr->call_malloc;
+ return *(void **)&ptr->call_malloc;
}
case MEMCACHED_CALLBACK_REALLOC_FUNCTION:
{
*error= ptr->call_realloc ? MEMCACHED_SUCCESS : MEMCACHED_FAILURE;
- return (void *)ptr->call_realloc;
+ return *(void **)&ptr->call_realloc;
}
case MEMCACHED_CALLBACK_FREE_FUNCTION:
{
*error= ptr->call_free ? MEMCACHED_SUCCESS : MEMCACHED_FAILURE;
- return (void *)ptr->call_free;
+ return *(void **)&ptr->call_free;
}
case MEMCACHED_CALLBACK_GET_FAILURE:
{
*error= ptr->get_key_failure ? MEMCACHED_SUCCESS : MEMCACHED_FAILURE;
- return (void *)ptr->get_key_failure;
+ return *(void **)&ptr->get_key_failure;
}
case MEMCACHED_CALLBACK_DELETE_TRIGGER:
{
*error= ptr->delete_trigger ? MEMCACHED_SUCCESS : MEMCACHED_FAILURE;
- return (void *)ptr->delete_trigger;
+ return *(void **)&ptr->delete_trigger;
}
default:
WATCHPOINT_ASSERT(0);
if (errno == EINPROGRESS || /* nonblocking mode - first return, */
errno == EALREADY) /* nonblocking mode - subsequent returns */
{
- struct pollfd fds[1] = { [0].fd = ptr->fd, [0].events = POLLOUT };
+ struct pollfd fds[1];
+ fds[0].fd = ptr->fd;
+ fds[0].events = POLLOUT;
int error= poll(fds, 1, ptr->root->connect_timeout);
if (error != 1 || fds[0].revents & POLLERR)
if (fds[0].revents & POLLERR)
{
int err;
- int len = sizeof (err);
+ socklen_t len = sizeof (err);
(void)getsockopt(ptr->fd, SOL_SOCKET, SO_ERROR, &err, &len);
ptr->cached_errno= (err == 0) ? errno : err;
}
{
memcached_return ret= MEMCACHED_SUCCESS;
- for (int x= 0; x < mem->number_of_hosts; ++x)
+ for (uint32_t x= 0; x < mem->number_of_hosts; ++x)
if (mem->hosts[x].write_buffer_offset != 0)
{
if (mem->hosts[x].fd == -1 &&
memcached_return rc= MEMCACHED_NOTFOUND;
char *get_command= "get ";
uint8_t get_command_length= 4;
- unsigned int master_server_key; /* 0 is a valid server id! */
+ unsigned int master_server_key= (unsigned int)-1; /* 0 is a valid server id! */
bool is_master_key_set= false;
if (ptr->flags & MEM_USE_UDP)
#include "common.h"
+
/* Defines */
static uint64_t FNV_64_INIT= 0xcbf29ce484222325LL;
static uint64_t FNV_64_PRIME= 0x100000001b3LL;
}
}
break;
-#ifdef HAVE_HSIEH_HASH
case MEMCACHED_HASH_HSIEH:
{
+#ifdef HAVE_HSIEH_HASH
hash= hsieh_hash(key, key_length);
+#endif
break;
}
-#endif
case MEMCACHED_HASH_MURMUR:
{
hash= murmur_hash(key, key_length);
if (is_ketama_weighted)
{
- int i;
+ unsigned int i;
for (i = 0; i < pointer_per_hash; i++)
{
value= ketama_server_hash(sort_host, sort_host_length, i);
/* If io_flush calls memcached_purge, sent_length may be 0 */
if (sent_length != 0)
+ {
WATCHPOINT_ASSERT(sent_length == buffer_end);
+ }
}
}
{
#define MAX_SERVERS_TO_POLL 100
struct pollfd fds[MAX_SERVERS_TO_POLL];
- int index= 0;
+ unsigned int index= 0;
- for (int x= 0; x< memc->number_of_hosts && index < MAX_SERVERS_TO_POLL; ++x)
+ for (unsigned int x= 0;
+ x< memc->number_of_hosts && index < MAX_SERVERS_TO_POLL;
+ ++x)
{
if (memc->hosts[x].read_buffer_length > 0) /* I have data in the buffer */
return &memc->hosts[x];
if (index < 2)
{
/* We have 0 or 1 server with pending events.. */
- for (int x= 0; x< memc->number_of_hosts; ++x)
+ for (unsigned int x= 0; x< memc->number_of_hosts; ++x)
if (memcached_server_response_count(&memc->hosts[x]) > 0)
return &memc->hosts[x];
case 0:
break;
default:
- for (int x= 0; x < index; ++x)
+ for (unsigned int x= 0; x < index; ++x)
if (fds[x].revents & POLLIN)
- for (int y= 0; y < memc->number_of_hosts; ++y)
+ for (unsigned int y= 0; y < memc->number_of_hosts; ++y)
if (memc->hosts[y].fd == fds[x].fd)
return &memc->hosts[y];
}
}
}
- if (ptr->type == MEMCACHED_CONNECTION_UDP && sent_length != write_length)
+ if (ptr->type == MEMCACHED_CONNECTION_UDP &&
+ (size_t)sent_length != write_length)
{
memcached_quit_server(ptr, 1);
return -1;
size_t size)
{
bool line_complete= false;
- int total_nr= 0;
+ size_t total_nr= 0;
while (!line_complete)
{
}
WATCHPOINT_ASSERT(ptr->fd != -1);
- int no_msg= memcached_server_response_count(ptr) - 1;
+ uint32_t no_msg= memcached_server_response_count(ptr) - 1;
if (no_msg > 0)
{
memcached_result_st result;
if (rrc != MEMCACHED_SUCCESS)
return rrc;
- if (read_length != (size_t)(value_length + 2))
+ if (read_length != (ssize_t)(value_length + 2))
{
goto read_error;
}
/* Try to create the initial size of the pool. An allocation failure at
* this time is not fatal..
*/
- for (int ii=0; ii < initial; ++ii)
+ for (unsigned int ii=0; ii < initial; ++ii)
if (grow_pool(ret) == -1)
break;
}
LDADDS+= $(top_builddir)/libmemcachedutil/libmemcachedutil.la
endif
-
EXTRA_DIST = output.res output2.res\
r/memcat.res\
r/memcp.res\
char *string;
size_t string_length;
uint32_t flags;
+ memcached_trigger_key cb= (memcached_trigger_key)read_through_trigger;
string= memcached_get(memc, key, strlen(key),
&string_length, &flags, &rc);
assert(string_length == 0);
assert(!string);
- rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_GET_FAILURE, (void *)read_through_trigger);
+ rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_GET_FAILURE,
+ *(void **)&cb);
assert(rc == MEMCACHED_SUCCESS);
string= memcached_get(memc, key, strlen(key),
memcached_trigger_delete_key callback;
memcached_return rc;
- callback= delete_trigger;
+ callback= (memcached_trigger_delete_key)delete_trigger;
- rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_DELETE_TRIGGER, (void*)callback);
+ rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_DELETE_TRIGGER, *(void**)&callback);
assert(rc == MEMCACHED_SUCCESS);
return 0;
/* Test Clone Callback */
{
- memcached_clone_func temp_function;
+ memcached_clone_func clone_cb= (memcached_clone_func)clone_test_callback;
+ void *clone_cb_ptr= *(void **)&clone_cb;
+ void *temp_function= NULL;
memcached_return rc;
- rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_CLONE_FUNCTION, (void*)clone_test_callback);
+ rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_CLONE_FUNCTION,
+ clone_cb_ptr);
assert(rc == MEMCACHED_SUCCESS);
- temp_function= (memcached_clone_func)memcached_callback_get(memc, MEMCACHED_CALLBACK_CLONE_FUNCTION, &rc);
- assert(temp_function == clone_test_callback);
+ temp_function= memcached_callback_get(memc, MEMCACHED_CALLBACK_CLONE_FUNCTION, &rc);
+ assert(temp_function == clone_cb_ptr);
}
/* Test Cleanup Callback */
{
- memcached_cleanup_func temp_function;
+ memcached_cleanup_func cleanup_cb=
+ (memcached_cleanup_func)cleanup_test_callback;
+ void *cleanup_cb_ptr= *(void **)&cleanup_cb;
+ void *temp_function= NULL;
memcached_return rc;
- rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_CLONE_FUNCTION, (void*)cleanup_test_callback);
+ rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_CLONE_FUNCTION,
+ cleanup_cb_ptr);
assert(rc == MEMCACHED_SUCCESS);
- temp_function= (memcached_cleanup_func)memcached_callback_get(memc, MEMCACHED_CALLBACK_CLONE_FUNCTION, &rc);
- assert(temp_function == cleanup_test_callback);
+ temp_function= memcached_callback_get(memc, MEMCACHED_CALLBACK_CLONE_FUNCTION, &rc);
+ assert(temp_function == cleanup_cb_ptr);
}
return 0;
test_return auto_eject_hosts(memcached_st *trash)
{
+ (void) trash;
+
memcached_return rc;
memcached_st *memc= memcached_create(NULL);
assert(memc);
return 0;
}
-static test_return free_data(memcached_st *memc __attribute__((unused)))
-{
- pairs_free(global_pairs);
-
- return 0;
-}
-
static test_return add_host_test1(memcached_st *memc)
{
unsigned int x;
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, (uint64_t)MEMCACHED_HASH_HSIEH);
return MEMCACHED_SUCCESS;
#else
+ (void) memc;
return MEMCACHED_FAILURE;
#endif
}
static memcached_return set_memory_alloc(memcached_st *memc)
{
+ void *test_ptr= NULL;
+ void *cb_ptr= NULL;
{
- memcached_malloc_function test_ptr;
+ memcached_malloc_function malloc_cb=
+ (memcached_malloc_function)my_malloc;
+ cb_ptr= *(void **)&malloc_cb;
memcached_return rc;
- rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_MALLOC_FUNCTION, (void*)&my_malloc);
+ rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_MALLOC_FUNCTION, cb_ptr);
assert(rc == MEMCACHED_SUCCESS);
- test_ptr= (memcached_malloc_function)memcached_callback_get(memc, MEMCACHED_CALLBACK_MALLOC_FUNCTION, &rc);
+ test_ptr= memcached_callback_get(memc, MEMCACHED_CALLBACK_MALLOC_FUNCTION, &rc);
assert(rc == MEMCACHED_SUCCESS);
- assert(test_ptr == my_malloc);
+ assert(test_ptr == cb_ptr);
}
{
- memcached_realloc_function test_ptr;
+ memcached_realloc_function realloc_cb=
+ (memcached_realloc_function)my_realloc;
+ cb_ptr= *(void **)&realloc_cb;
memcached_return rc;
- rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_REALLOC_FUNCTION, (void*)&my_realloc);
+ rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_REALLOC_FUNCTION, cb_ptr);
assert(rc == MEMCACHED_SUCCESS);
- test_ptr= (memcached_realloc_function)memcached_callback_get(memc, MEMCACHED_CALLBACK_REALLOC_FUNCTION, &rc);
+ test_ptr= memcached_callback_get(memc, MEMCACHED_CALLBACK_REALLOC_FUNCTION, &rc);
assert(rc == MEMCACHED_SUCCESS);
- assert(test_ptr == my_realloc);
+ assert(test_ptr == cb_ptr);
}
{
- memcached_free_function test_ptr;
+ memcached_free_function free_cb=
+ (memcached_free_function)my_free;
+ cb_ptr= *(void **)&free_cb;
memcached_return rc;
- rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_FREE_FUNCTION, (void*)my_free);
+ rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_FREE_FUNCTION, cb_ptr);
assert(rc == MEMCACHED_SUCCESS);
- test_ptr= (memcached_free_function)memcached_callback_get(memc, MEMCACHED_CALLBACK_FREE_FUNCTION, &rc);
+ test_ptr= memcached_callback_get(memc, MEMCACHED_CALLBACK_FREE_FUNCTION, &rc);
assert(rc == MEMCACHED_SUCCESS);
- assert(test_ptr == my_free);
+ assert(test_ptr == cb_ptr);
}
return MEMCACHED_SUCCESS;
** way it is supposed to do!!!!
*/
int no_msg=0;
- for (int x=0; x < memc->number_of_hosts; ++x)
+ for (uint32_t x=0; x < memc->number_of_hosts; ++x)
no_msg+=memc->hosts[x].cursor_active;
assert(no_msg == 0);
usleep(250);
assert(memcached_pool_push(resource->pool, resource->mmc) == MEMCACHED_SUCCESS);
+ return arg;
}
static test_return connection_pool_test(memcached_st *memc)
rc= memcached_set(mmc[0], key, keylen, "0", 1, 0, 0);
assert(rc == MEMCACHED_SUCCESS);
- for (int x= 0; x < 10; ++x) {
+ for (unsigned int x= 0; x < 10; ++x) {
uint64_t number_value;
rc= memcached_increment(mmc[x], key, keylen, 1, &number_value);
assert(rc == MEMCACHED_SUCCESS);
{"server_sort", 0, server_sort_test},
{"server_sort2", 0, server_sort2_test},
{"clone_test", 0, clone_test },
+ {"connection_test", 0, connection_test},
+ {"callback_test", 0, callback_test},
+ {"behavior_test", 0, behavior_test},
{"error", 0, error_test },
{"set", 0, set_test },
{"set2", 0, set_test2 },