From: Monty Taylor Date: Mon, 6 Jul 2009 17:13:14 +0000 (-0500) Subject: Rearranged some things and added the visibility.m4 macros. Started to lay the X-Git-Tag: 0.31~4^2~11 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=7425cb169f8318a1bfde88fdbf991934a690a970;p=m6w6%2Flibmemcached Rearranged some things and added the visibility.m4 macros. Started to lay the groundwork for being able to turn on -fvisibility=hidden, which in this lib will likely be a nice speed win. (At these speeds, the extra mem access might even be noticed) Moved code that was commented to only be private to private headers. Removed the need for installation of any of the private headers. --- diff --git a/configure.ac b/configure.ac index 80be7be3..0df44b0a 100644 --- a/configure.ac +++ b/configure.ac @@ -9,7 +9,7 @@ AC_PREREQ(2.59) AC_INIT([libmemcached],[0.30],[http://tangent.org/552/libmemcached.html]) AC_CONFIG_SRCDIR([libmemcached/memcached.c]) AC_CONFIG_AUX_DIR(config) -AM_CONFIG_HEADER(libmemcached/libmemcached_config.h) +AM_CONFIG_HEADER([config.h]) AC_CONFIG_MACRO_DIR([m4]) #shared library versioning @@ -98,6 +98,8 @@ fi AC_SUBST(LD_VERSION_SCRIPT) AC_SUBST(LD_UTIL_VERSION_SCRIPT) +gl_VISIBILITY + # Build optimized or debug version ? # First check for gcc and g++ if test "$GCC" = "yes" diff --git a/libmemcached/Makefile.am b/libmemcached/Makefile.am index 69265073..b7659eb2 100644 --- a/libmemcached/Makefile.am +++ b/libmemcached/Makefile.am @@ -8,8 +8,7 @@ DTRACE = @DTRACE@ DTRACEFLAGS = @DTRACEFLAGS@ noinst_HEADERS = libmemcached_probes.h \ - libmemcached_config.h \ - memcached_io.h \ + memcached_io.h \ memcached_internal.h \ common.h \ memcached/protocol_binary.h @DTRACE_HEADER@ @@ -32,7 +31,7 @@ endif lib_LTLIBRARIES = libmemcached.la -libmemcached_la_CFLAGS= ${AM_CFLAGS} ${NO_CONVERSION} +libmemcached_la_CFLAGS= ${AM_CFLAGS} ${NO_CONVERSION} -DBUILDING_LIBMEMCACHED libmemcached_la_SOURCES = crc.c \ memcached.c \ memcached_auto.c \ @@ -76,7 +75,6 @@ if BUILD_BYTEORDER libmemcached_la_SOURCES += byteorder.c endif -DEFS += -DMEMCACHED_INTERNAL libmemcached_la_DEPENDENCIES = @DTRACE_OBJ@ libmemcached_la_LIBADD = @DTRACE_OBJ@ $(LIBM) libmemcached_la_LDFLAGS = -version-info $(MEMCACHED_LIBRARY_VERSION) $(LD_VERSION_SCRIPT) $(LIBM) diff --git a/libmemcached/common.h b/libmemcached/common.h index 10b434f1..c413b1fe 100644 --- a/libmemcached/common.h +++ b/libmemcached/common.h @@ -2,10 +2,10 @@ Common include file for libmemached */ -#ifndef __COMMON_H__ -#define __COMMON_H__ +#ifndef LIBMEMCACHED_COMMON_H +#define LIBMEMCACHED_COMMON_H -#include "libmemcached/libmemcached_config.h" +#include "config.h" #include #include @@ -23,13 +23,6 @@ #include #include #include - - -#include "libmemcached/memcached.h" -#include "libmemcached/memcached_io.h" - -#include "libmemcached/memcached/protocol_binary.h" - #ifdef TIME_WITH_SYS_TIME # include # include @@ -42,6 +35,26 @@ #endif +#include "libmemcached/memcached.h" +#include "libmemcached/memcached_watchpoint.h" + +#if defined(BUILDING_LIBMEMCACHED) +/* These are private not to be installed headers */ +#include "libmemcached/memcached_io.h" +#include "libmemcached/memcached_internal.h" +#include "libmemcached/libmemcached_probes.h" +#include "libmemcached/memcached/protocol_binary.h" + +/* string value */ +struct memcached_continuum_item_st { + uint32_t index; + uint32_t value; +}; + +#endif + + + #if !defined(__GNUC__) || (__GNUC__ == 2 && __GNUC_MINOR__ < 96) @@ -54,7 +67,6 @@ #define unlikely(x) if(__builtin_expect((x), 0)) #endif -#include "libmemcached_probes.h" #define MEMCACHED_BLOCK_SIZE 1024 #define MEMCACHED_DEFAULT_COMMAND_SIZE 350 @@ -83,6 +95,7 @@ typedef enum { MEM_AUTO_EJECT_HOSTS= (1 << 16) } memcached_flags; +#if defined(BUILDING_LIBMEMCACHED) /* Hashing algo */ void md5_signature(const unsigned char *key, unsigned int length, unsigned char *result); uint32_t hash_crc32(const char *data, @@ -144,5 +157,6 @@ static inline memcached_return memcached_validate_key_length(size_t key_length, return MEMCACHED_SUCCESS; } +#endif /* BUILDING_LIBMEMCACHED */ -#endif /* __COMMON_H__ */ +#endif /* !defined(LIBMEMCACHED_COMMON_H) && defined(BUILDING_LIBMEMCACHED) */ diff --git a/libmemcached/memcached.h b/libmemcached/memcached.h index 9ac0df70..4693c55d 100644 --- a/libmemcached/memcached.h +++ b/libmemcached/memcached.h @@ -18,13 +18,9 @@ #include #include -#ifdef MEMCACHED_INTERNAL -#include -#endif #include #include #include -#include #include #include #include @@ -34,15 +30,7 @@ extern "C" { #endif -/* These are Private and should not be used by applications */ #define MEMCACHED_VERSION_STRING_LENGTH 24 - -/* string value */ -struct memcached_continuum_item_st { - uint32_t index; - uint32_t value; -}; - #define LIBMEMCACHED_VERSION_STRING "0.30" struct memcached_analysis_st { @@ -254,8 +242,4 @@ void *memcached_set_user_data(memcached_st *ptr, void *data); #include -#ifdef MEMCACHED_INTERNAL -#include -#endif - #endif /* __MEMCACHED_H__ */ diff --git a/libmemcached/memcached/protocol_binary.h b/libmemcached/memcached/protocol_binary.h index 08df72e8..7a59ade3 100644 --- a/libmemcached/memcached/protocol_binary.h +++ b/libmemcached/memcached/protocol_binary.h @@ -32,8 +32,10 @@ * Author: Trond Norbye */ -#ifndef PROTOCOL_BINARY_H -#define PROTOCOL_BINARY_H +#ifndef LIBMEMCACHED_MEMCACHED_PROTOCOL_BINARY_H +#define LIBMEMCACHED_MEMCACHED_PROTOCOL_BINARY_H + +#if defined(BUILDING_LIBMEMCACHED) #include @@ -358,4 +360,6 @@ extern "C" #ifdef __cplusplus } #endif -#endif /* PROTOCOL_BINARY_H */ + +#endif /* BUILDING_LIBMEMCACHED */ +#endif /* LIBMEMCACHED_MEMCACHED_PROTOCOL_BINARY_H */ diff --git a/libmemcached/memcached_allocators.c b/libmemcached/memcached_allocators.c index 3192f9e9..bf57e357 100644 --- a/libmemcached/memcached_allocators.c +++ b/libmemcached/memcached_allocators.c @@ -1,24 +1,24 @@ #include "common.h" -void libmemcached_free(memcached_st *ptr __attribute__((unused)), void *mem) +void libmemcached_free(memcached_st *ptr, void *mem) { + (void) ptr; free(mem); } -void *libmemcached_malloc(memcached_st *ptr __attribute__((unused)), - size_t size) +void *libmemcached_malloc(memcached_st *ptr, size_t size) { + (void) ptr; return malloc(size); } -void *libmemcached_realloc(memcached_st *ptr __attribute__((unused)), - void *mem, size_t size) +void *libmemcached_realloc(memcached_st *ptr, void *mem, size_t size) { + (void) ptr; return realloc(mem, size); } -void *libmemcached_calloc(memcached_st *ptr __attribute__((unused)), - size_t nelem, size_t size) +void *libmemcached_calloc(memcached_st *ptr, size_t nelem, size_t size) { if (ptr->call_malloc != libmemcached_malloc) { diff --git a/libmemcached/memcached_internal.h b/libmemcached/memcached_internal.h index 086915aa..13a896f2 100644 --- a/libmemcached/memcached_internal.h +++ b/libmemcached/memcached_internal.h @@ -5,22 +5,23 @@ * Author: Trond Norbye */ -#if !defined(MEMCACHED_INTERNAL_H) && defined(MEMCACHED_INTERNAL) -#define MEMCACHED_INTERNAL_H +#ifndef LIBMEMCACHED_MEMCACHED_INTERNAL_H +#define LIBMEMCACHED_MEMCACHED_INTERNAL_H + +#if defined(BUILDING_LIBMEMCACHED) #ifdef __cplusplus extern "C" { #endif -void libmemcached_free(memcached_st *ptr __attribute__((unused)), void *mem); -void *libmemcached_malloc(memcached_st *ptr __attribute__((unused)), - const size_t size); -void *libmemcached_realloc(memcached_st *ptr __attribute__((unused)), - void *mem, const size_t size); -void *libmemcached_calloc(memcached_st *ptr __attribute__((unused)), - size_t nelem, size_t size); +void libmemcached_free(memcached_st *ptr, void *mem); +void *libmemcached_malloc(memcached_st *ptr, const size_t size); +void *libmemcached_realloc(memcached_st *ptr, void *mem, const size_t size); +void *libmemcached_calloc(memcached_st *ptr, size_t nelem, size_t size); + #ifdef __cplusplus } #endif -#endif /* MEMCACHED_INTERNAL_H */ +#endif /* BUILDING_LIBMEMCACHED */ +#endif /* LIBMEMCACHED_MEMCACHED_INTERNAL_H */ diff --git a/libmemcached/memcached_io.h b/libmemcached/memcached_io.h index 6bcf871b..da253955 100644 --- a/libmemcached/memcached_io.h +++ b/libmemcached/memcached_io.h @@ -1,8 +1,17 @@ -/* Server IO, Not public! */ -#include "libmemcached/memcached.h" +/* + * Summary: Server IO, Not public! + * + * Copy: See Copyright for the status of this software. + * + * Author: Brian Aker + */ + +#ifndef LIBMEMCACHED_MEMCACHED_IO_H +#define LIBMEMCACHED_MEMCACHED_IO_H -#ifndef __MEMCACHED_IO_H__ -#define __MEMCACHED_IO_H__ +#if defined(BUILDING_LIBMEMCACHED) + +#include "libmemcached/memcached.h" #define MAX_UDP_DATAGRAM_LENGTH 1400 #define UDP_DATAGRAM_HEADER_LENGTH 8 @@ -46,4 +55,5 @@ memcached_return memcached_io_init_udp_header(memcached_server_st *ptr, memcached_server_st *memcached_io_get_readable_server(memcached_st *memc); -#endif /* __MEMCACHED_IO_H__ */ +#endif /* BUILDING_LIBMEMCACHED */ +#endif /* LIBMEMCACHED_MEMCACHED_IO_H */ diff --git a/libmemcached/memcached_watchpoint.h b/libmemcached/memcached_watchpoint.h index ab479f17..dc8045aa 100644 --- a/libmemcached/memcached_watchpoint.h +++ b/libmemcached/memcached_watchpoint.h @@ -6,15 +6,12 @@ * Author: Brian Aker */ -#ifndef __MEMCACHED_WATCHPOINT_H__ -#define __MEMCACHED_WATCHPOINT_H__ - -#ifdef __cplusplus -extern "C" { -#endif +#ifndef LIBMEMCACHED_MEMCACHED_WATCHPOINT_H +#define LIBMEMCACHED_MEMCACHED_WATCHPOINT_H /* Some personal debugging functions */ -#if defined(MEMCACHED_INTERNAL) && defined(DEBUG) +#if defined(DEBUG) + #include #define WATCHPOINT fprintf(stderr, "\nWATCHPOINT %s:%d (%s)\n", __FILE__, __LINE__,__func__);fflush(stdout); @@ -36,10 +33,6 @@ extern "C" { #define WATCHPOINT_ASSERT_PRINT(A,B,C) #define WATCHPOINT_ASSERT(A) -#endif /* MEMCACHED_INTERNAL && DEBUG */ - -#ifdef __cplusplus -} -#endif +#endif /* DEBUG */ -#endif /* __MEMCACHED_WATCHPOINT_H__ */ +#endif /* LIBMEMCACHED_MEMCACHED_WATCHPOINT_H */ diff --git a/libmemcached/visibility.h b/libmemcached/visibility.h new file mode 100644 index 00000000..049137e3 --- /dev/null +++ b/libmemcached/visibility.h @@ -0,0 +1,45 @@ +/* + * Summary: interface for memcached server + * Description: visibitliy macros for libmemcached + * + * Use and distribution licensed under the BSD license. See + * the COPYING file in this directory for full text. + * + * Author: Monty Taylor + */ + +/** + * @file + * @brief Visibility control macros + */ + +#ifndef __LIBMEMCACHED_VISIBILITY_H +#define __LIBMEMCACHED_VISIBILITY_H + +/** + * + * LIBMEMCACHED_API is used for the public API symbols. It either DLL imports or + * DLL exports (or does nothing for static build). + * + * LIBMEMCACHED_LOCAL is used for non-api symbols. + */ + +#if defined(BUILDING_LIBMEMCACHED) +# if defined(HAVE_VISIBILITY) +# define LIBMEMCACHED_API __attribute__ ((visibility("default"))) +# define LIBMEMCACHED_LOCAL __attribute__ ((visibility("hidden"))) +# elif defined(_MSC_VER) +# define LIBMEMCACHED_API extern __declspec(dllexport) +# define LIBMEMCACHED_LOCAL +# endif /* defined(HAVE_VISIBILITY) */ +#else /* defined(BUILDING_LIBMEMCACHED) */ +# if defined(_MSC_VER) +# define LIBMEMCACHED_API extern __declspec(dllimport) +# define LIBMEMCACHED_LOCAL +# else +# define LIBMEMCACHED_API +# define LIBMEMCACHED_LOCAL +# endif /* defined(_MSC_VER) */ +#endif /* defined(BUILDING_LIBMEMCACHED) */ + +#endif /* __LIBMEMCACHED_VISIBILITY_H */ diff --git a/libmemcachedutil/memcached_pool.c b/libmemcachedutil/memcached_pool.c index a1fc8c30..5c122eb6 100644 --- a/libmemcachedutil/memcached_pool.c +++ b/libmemcachedutil/memcached_pool.c @@ -1,5 +1,7 @@ -#include "libmemcached/common.h" +#include "config.h" #include "libmemcached/memcached_pool.h" + +#include #include struct memcached_pool_st diff --git a/m4/visibility.m4 b/m4/visibility.m4 new file mode 100644 index 00000000..70bca564 --- /dev/null +++ b/m4/visibility.m4 @@ -0,0 +1,52 @@ +# visibility.m4 serial 2 (gettext-0.18) +dnl Copyright (C) 2005, 2008 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl From Bruno Haible. + +dnl Tests whether the compiler supports the command-line option +dnl -fvisibility=hidden and the function and variable attributes +dnl __attribute__((__visibility__("hidden"))) and +dnl __attribute__((__visibility__("default"))). +dnl Does *not* test for __visibility__("protected") - which has tricky +dnl semantics (see the 'vismain' test in glibc) and does not exist e.g. on +dnl MacOS X. +dnl Does *not* test for __visibility__("internal") - which has processor +dnl dependent semantics. +dnl Does *not* test for #pragma GCC visibility push(hidden) - which is +dnl "really only recommended for legacy code". +dnl Set the variable CFLAG_VISIBILITY. +dnl Defines and sets the variable HAVE_VISIBILITY. + +AC_DEFUN([gl_VISIBILITY], +[ + AC_REQUIRE([AC_PROG_CC]) + CFLAG_VISIBILITY= + HAVE_VISIBILITY=0 + if test -n "$GCC"; then + AC_MSG_CHECKING([for simple visibility declarations]) + AC_CACHE_VAL([gl_cv_cc_visibility], [ + gl_save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS -fvisibility=hidden" + AC_TRY_COMPILE( + [extern __attribute__((__visibility__("hidden"))) int hiddenvar; + extern __attribute__((__visibility__("default"))) int exportedvar; + extern __attribute__((__visibility__("hidden"))) int hiddenfunc (void); + extern __attribute__((__visibility__("default"))) int exportedfunc (void);], + [], + [gl_cv_cc_visibility=yes], + [gl_cv_cc_visibility=no]) + CFLAGS="$gl_save_CFLAGS"]) + AC_MSG_RESULT([$gl_cv_cc_visibility]) + if test $gl_cv_cc_visibility = yes; then + CFLAG_VISIBILITY="-fvisibility=hidden" + HAVE_VISIBILITY=1 + fi + fi + AC_SUBST([CFLAG_VISIBILITY]) + AC_SUBST([HAVE_VISIBILITY]) + AC_DEFINE_UNQUOTED([HAVE_VISIBILITY], [$HAVE_VISIBILITY], + [Define to 1 or 0, depending whether the compiler supports simple visibility declarations.]) +]) diff --git a/tests/function.c b/tests/function.c index 5d0c64b9..128d9f8f 100644 --- a/tests/function.c +++ b/tests/function.c @@ -1,6 +1,14 @@ /* Sample test application. */ + +/* TODO: I'm torn about this. The file seems like a functional test, which + * should use only the exported API of the library. On the other hand, + * something needs to test some of the internals - so we're going to turn on + * internal symbols here... but I'd like to come up with another way to test + * the internals + */ +#define BUILDING_LIBMEMCACHED 1 #include "libmemcached/common.h" #include @@ -424,7 +432,7 @@ static test_return cas2_test(memcached_st *memc) assert(results); assert(results->cas); assert(rc == MEMCACHED_SUCCESS); - WATCHPOINT_ASSERT(memcached_result_cas(results)); + assert(memcached_result_cas(results)); assert(!memcmp(value, "we the people", strlen("we the people"))); assert(strlen("we the people") == value_length); @@ -468,7 +476,7 @@ static test_return cas_test(memcached_st *memc) results= memcached_fetch_result(memc, &results_obj, &rc); assert(results); assert(rc == MEMCACHED_SUCCESS); - WATCHPOINT_ASSERT(memcached_result_cas(results)); + assert(memcached_result_cas(results)); assert(!memcmp(value, memcached_result_value(results), value_length)); assert(strlen(memcached_result_value(results)) == value_length); assert(rc == MEMCACHED_SUCCESS); @@ -1647,8 +1655,7 @@ static test_return user_supplied_bug2(memcached_st *memc) errors++; else { - WATCHPOINT_ERROR(rc); - assert(0); + assert(rc); } continue; diff --git a/tests/server.c b/tests/server.c index e06fbd57..f0926695 100644 --- a/tests/server.c +++ b/tests/server.c @@ -4,7 +4,7 @@ #define TEST_PORT_BASE MEMCACHED_DEFAULT_PORT+10 -#include "libmemcached/libmemcached_config.h" +#include "config.h" #include #include diff --git a/tests/test.h b/tests/test.h index 63b75ef0..d0e089dd 100644 --- a/tests/test.h +++ b/tests/test.h @@ -6,7 +6,7 @@ extern "C" { #endif #include -#include "../libmemcached/common.h" +#include typedef struct world_st world_st; typedef struct collection_st collection_st;