From c9f472b091b351b206d34b9fa37e28b6d1e4202c Mon Sep 17 00:00:00 2001 From: Brian Aker Date: Thu, 1 Nov 2007 02:57:39 -0700 Subject: [PATCH] pkgconfig support done (need to write example) wrote wrapper for freeing memcached_stat_st structures moved my_errno to be chached_errno (aka removed conflict with MySQL) --- ChangeLog | 2 ++ configure.ac | 72 ++++++++++++++++++++++++++++++++++++++ configure.in | 32 ----------------- include/memcached.h | 4 +-- lib/Makefile.am | 1 + lib/memcached_connect.c | 12 +++---- lib/memcached_io.c | 4 +-- lib/memcached_stats.c | 5 +++ src/memcat.c | 4 +-- src/memcp.c | 4 +-- src/memflush.c | 4 +-- src/memrm.c | 4 +-- support/Makefile.am | 3 ++ support/libmemcached.pc.in | 11 ++++++ tests/test.c | 2 +- 15 files changed, 113 insertions(+), 51 deletions(-) create mode 100644 configure.ac delete mode 100644 configure.in create mode 100644 support/libmemcached.pc.in diff --git a/ChangeLog b/ChangeLog index df62657e..8b2f9a8a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,8 @@ * Adding support for CRC hash method * Adding support for UNIX sockets * Added additional HASHing methods of FNV1_64,FNV1A_64, FNV1_32, FNV1A_32 + * Added pkgconfig support + * Fixed conflict with defined type in MySQL 0.7 Tue Oct 30 09:24:05 PDT 2007 * Poved to poll() from select() diff --git a/configure.ac b/configure.ac new file mode 100644 index 00000000..5d392ca3 --- /dev/null +++ b/configure.ac @@ -0,0 +1,72 @@ +AC_INIT(src/memcat.c) +AC_CONFIG_AUX_DIR(config) +AM_CONFIG_HEADER(include/libmemcached_config.h) + +MEMCACHED_LIBRARY_NAME=libmemcached + +#release versioning +MEMCACHED_MAJOR_VERSION=0 +MEMCACHED_MINOR_VERSION=8 +MEMCACHED_MICRO_VERSION=0 + +#API version +MEMCACHED_API_VERSION=1.0 +AC_SUBST(MEMCACHED_API_VERSION) + +#shared library versioning +MEMCACHED_LIBRARY_VERSION=1:0:0 +# | | | +# +------+ | +---+ +# | | | +# current:revision:age +# | | | +# | | +- increment if interfaces have been added +# | | set to zero if interfaces have been removed or changed +# | +- increment if source code has changed +# | set to zero if current is incremented +# +- increment if interfaces have been added, removed or changed + +AC_SUBST(MEMCACHED_LIBRARY_VERSION) + +PACKAGE=$MEMCACHED_LIBRARY_NAME +AC_SUBST(MEMCACHED_LIBRARY_NAME) + +MEMCACHED_VERSION=$MEMCACHED_MAJOR_VERSION.$MEMCACHED_MINOR_VERSION.$MEMCACHED_MICRO_VERSION +MEMCACHED_RELEASE=$MEMCACHED_MAJOR_VERSION.$MEMCACHED_MINOR_VERSION +AC_SUBST(MEMCACHED_RELEASE) +AC_SUBST(MEMCACHED_VERSION) + +VERSION=$MEMCACHED_VERSION + +AM_INIT_AUTOMAKE($PACKAGE, $VERSION, no-define) + +AC_PROG_CC +AC_PROG_CXX +AC_PROG_LIBTOOL +AM_SANITY_CHECK +LIBTOOL="$LIBTOOL --preserve-dup-deps" +AC_SUBST(LIBTOOL)dnl +AC_LANG_CPLUSPLUS + +sinclude(config/debug.m4) +sinclude(config/dtrace.m4) + +# We only support GCC and Sun's forte at the moment +if test "$GCC" = "yes" +then + if test "$ENABLE_DEBUG" = "yes" + then + CFLAGS="-Wall -ggdb -DHAVE_DEBUG" + else + CFLAGS="-Wall -O3" + fi +else + CFLAGS="-Xa -xstrconst -mt -D_FORTEC_ -fast -m64" + LDFLAGS="-lsocket -lnsl" + DTRACEFLAGS="-64" +fi + +AC_C_CONST +AC_TYPE_SIZE_T +AC_CHECK_HEADERS(limits.h syslimits.h) +AC_OUTPUT(Makefile src/Makefile tests/Makefile docs/Makefile lib/Makefile include/Makefile support/Makefile support/libmemcached.pc) diff --git a/configure.in b/configure.in deleted file mode 100644 index 241212ee..00000000 --- a/configure.in +++ /dev/null @@ -1,32 +0,0 @@ -AC_INIT(src/memcat.c) -AC_CONFIG_AUX_DIR(config) -AM_CONFIG_HEADER(include/libmemcached_config.h) -AM_INIT_AUTOMAKE("libmemcached", 0.8) - -AC_PROG_CC -AC_PROG_LIBTOOL -LIBTOOL="$LIBTOOL --preserve-dup-deps" -AC_SUBST(LIBTOOL)dnl - -sinclude(config/debug.m4) -sinclude(config/dtrace.m4) - -# We only support GCC and Sun's forte at the moment -if test "$GCC" = "yes" -then - if test "$ENABLE_DEBUG" = "yes" - then - CFLAGS="-Wall -ggdb -DHAVE_DEBUG" - else - CFLAGS="-Wall -O3" - fi -else - CFLAGS="-Xa -xstrconst -mt -D_FORTEC_ -fast -m64" - LDFLAGS="-lsocket -lnsl" - DTRACEFLAGS="-64" -fi - -AC_C_CONST -AC_TYPE_SIZE_T -AC_CHECK_HEADERS(limits.h syslimits.h) -AC_OUTPUT(Makefile src/Makefile tests/Makefile docs/Makefile lib/Makefile include/Makefile support/Makefile) diff --git a/include/memcached.h b/include/memcached.h index a859b221..cff65513 100644 --- a/include/memcached.h +++ b/include/memcached.h @@ -28,7 +28,6 @@ typedef struct memcached_server_st memcached_server_st; #define SMALL_STRING_LEN 1024 #define HUGE_STRING_LEN 8196 #define MEMCACHED_MAX_KEY 251 /* We add one to have it null terminated */ -//#define MEMCACHED_MAX_BUFFER 8196 #define MEMCACHED_MAX_BUFFER HUGE_STRING_LEN typedef enum { @@ -151,7 +150,7 @@ struct memcached_st { char write_buffer[MEMCACHED_MAX_BUFFER]; size_t write_buffer_offset; char connected; - int my_errno; + int cached_errno; unsigned long long flags; int send_size; int recv_size; @@ -174,6 +173,7 @@ memcached_return memcached_decrement(memcached_st *ptr, char *key, size_t key_length, unsigned int offset, unsigned int *value); +void memcached_stat_free(memcached_st *, memcached_stat_st *); memcached_stat_st *memcached_stat(memcached_st *ptr, char *args, memcached_return *error); memcached_return memcached_stat_servername(memcached_stat_st *stat, char *args, char *hostname, unsigned int port); diff --git a/lib/Makefile.am b/lib/Makefile.am index 46534a5a..acb5fe56 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -46,6 +46,7 @@ libmemcached_la_SOURCES = crc.c \ memcached_strerror.c \ memcached_verbosity.c libmemcached_la_LIBADD = +libmemcached_la_LDFLAGS = -version-info $(MEMCACHED_LIBRARY_VERSION) -release $(MEMCACHED_RELEASE) if HAVE_DTRACE libmemcached_la_LIBADD += libmemcached_probes.o diff --git a/lib/memcached_connect.c b/lib/memcached_connect.c index f3097126..68b9c939 100644 --- a/lib/memcached_connect.c +++ b/lib/memcached_connect.c @@ -16,7 +16,7 @@ static memcached_return unix_socket_connect(memcached_st *ptr, unsigned int serv { if ((ptr->hosts[server_key].fd= socket(AF_UNIX, SOCK_STREAM, 0)) < 0) { - ptr->my_errno= errno; + ptr->cached_errno= errno; return MEMCACHED_CONNECTION_SOCKET_CREATE_FAILURE; } @@ -27,7 +27,7 @@ static memcached_return unix_socket_connect(memcached_st *ptr, unsigned int serv addrlen= strlen(servAddr.sun_path) + sizeof(servAddr.sun_family); test_connect: - if (connect(ptr->hosts[server_key].fd, (struct sockaddr_un *)&servAddr, sizeof(servAddr)) < 0) + if (connect(ptr->hosts[server_key].fd, (struct sockaddr *)&servAddr, sizeof(servAddr)) < 0) { switch (errno) { /* We are spinning waiting on connect */ @@ -38,7 +38,7 @@ test_connect: case EISCONN: /* We were spinning waiting on connect */ break; default: - ptr->my_errno= errno; + ptr->cached_errno= errno; return MEMCACHED_ERRNO; } ptr->connected++; @@ -59,7 +59,7 @@ static memcached_return tcp_connect(memcached_st *ptr, unsigned int server_key) if ((h= gethostbyname(ptr->hosts[server_key].hostname)) == NULL) { - ptr->my_errno= h_errno; + ptr->cached_errno= h_errno; return MEMCACHED_HOST_LOCKUP_FAILURE; } @@ -70,7 +70,7 @@ static memcached_return tcp_connect(memcached_st *ptr, unsigned int server_key) /* Create the socket */ if ((ptr->hosts[server_key].fd= socket(AF_INET, SOCK_STREAM, 0)) < 0) { - ptr->my_errno= errno; + ptr->cached_errno= errno; return MEMCACHED_CONNECTION_SOCKET_CREATE_FAILURE; } @@ -117,7 +117,7 @@ test_connect: case EISCONN: /* We were spinning waiting on connect */ break; default: - ptr->my_errno= errno; + ptr->cached_errno= errno; return MEMCACHED_ERRNO; } ptr->connected++; diff --git a/lib/memcached_io.c b/lib/memcached_io.c index d2c803f3..54844be4 100644 --- a/lib/memcached_io.c +++ b/lib/memcached_io.c @@ -62,7 +62,7 @@ ssize_t memcached_io_read(memcached_st *ptr, unsigned int server_key, break; default: { - ptr->my_errno= errno; + ptr->cached_errno= errno; return -1; } } @@ -156,7 +156,7 @@ ssize_t memcached_io_flush(memcached_st *ptr, unsigned int server_key) } /* Yes, we want to fall through */ default: - ptr->my_errno= errno; + ptr->cached_errno= errno; return -1; } } diff --git a/lib/memcached_stats.c b/lib/memcached_stats.c index f71deb46..e90f1c0f 100644 --- a/lib/memcached_stats.c +++ b/lib/memcached_stats.c @@ -345,3 +345,8 @@ char ** memcached_stat_get_keys(memcached_st *ptr, memcached_stat_st *stat, return list; } + +void memcached_stat_free(memcached_st *ptr, memcached_stat_st *stat) +{ + free(stat); +} diff --git a/src/memcat.c b/src/memcat.c index 057a585c..1ee02427 100644 --- a/src/memcat.c +++ b/src/memcat.c @@ -71,8 +71,8 @@ int main(int argc, char *argv[]) { fprintf(stderr, "memcat: %s: memcache error %s", argv[optind], memcached_strerror(memc, rc)); - if (memc->my_errno) - fprintf(stderr, " system error %s", strerror(memc->my_errno)); + if (memc->cached_errno) + fprintf(stderr, " system error %s", strerror(memc->cached_errno)); fprintf(stderr, "\n"); } optind++; diff --git a/src/memcp.c b/src/memcp.c index 0eb210a7..09d7e911 100644 --- a/src/memcp.c +++ b/src/memcp.c @@ -119,8 +119,8 @@ int main(int argc, char *argv[]) { fprintf(stderr, "memcp: %s: memcache error %s", ptr, memcached_strerror(memc, rc)); - if (memc->my_errno) - fprintf(stderr, " system error %s", strerror(memc->my_errno)); + if (memc->cached_errno) + fprintf(stderr, " system error %s", strerror(memc->cached_errno)); fprintf(stderr, "\n"); } diff --git a/src/memflush.c b/src/memflush.c index 075875a2..3c47fc3c 100644 --- a/src/memflush.c +++ b/src/memflush.c @@ -45,8 +45,8 @@ int main(int argc, char *argv[]) { fprintf(stderr, "memflush: memcache error %s", memcached_strerror(memc, rc)); - if (memc->my_errno) - fprintf(stderr, " system error %s", strerror(memc->my_errno)); + if (memc->cached_errno) + fprintf(stderr, " system error %s", strerror(memc->cached_errno)); fprintf(stderr, "\n"); } diff --git a/src/memrm.c b/src/memrm.c index acfbf53f..09f58ea4 100644 --- a/src/memrm.c +++ b/src/memrm.c @@ -50,8 +50,8 @@ int main(int argc, char *argv[]) { fprintf(stderr, "memrm: %s: memcache error %s", argv[optind], memcached_strerror(memc, rc)); - if (memc->my_errno) - fprintf(stderr, " system error %s", strerror(memc->my_errno)); + if (memc->cached_errno) + fprintf(stderr, " system error %s", strerror(memc->cached_errno)); fprintf(stderr, "\n"); } diff --git a/support/Makefile.am b/support/Makefile.am index 103bd257..34c4cc98 100644 --- a/support/Makefile.am +++ b/support/Makefile.am @@ -1 +1,4 @@ EXTRA_DIST = libmemcached.spec set_benchmark.sh + +pkgconfigdir = $(libdir)/pkgconfig +pkgconfig_DATA = libmemcached.pc diff --git a/support/libmemcached.pc.in b/support/libmemcached.pc.in new file mode 100644 index 00000000..cb9d8c38 --- /dev/null +++ b/support/libmemcached.pc.in @@ -0,0 +1,11 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: libmemcached +Description: libmemcached C library. +Version: @VERSION@ +Libs: -L${libdir} -lmemcached +Cflags: -I${includedir}/@MEMCACHED_LIBRARY_NAME@ + diff --git a/tests/test.c b/tests/test.c index 7b8c462e..523f3034 100644 --- a/tests/test.c +++ b/tests/test.c @@ -477,7 +477,7 @@ void get_stats(memcached_st *memc) free(list); } - free(stat); + memcached_stat_free(NULL, stat); } void add_host_test(memcached_st *memc) -- 2.30.2