From: Trond Norbye Date: Thu, 17 Sep 2009 12:39:18 +0000 (+0200) Subject: Refactor: move ntohll to a separate helper library X-Git-Tag: 0.34~29^2~1 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=4a1c481fd0e342bc2339a1998c408c318171d392;p=awesomized%2Flibmemcached Refactor: move ntohll to a separate helper library --- diff --git a/libmemcached/Makefile.am b/libmemcached/Makefile.am index 087290e9..659f5658 100644 --- a/libmemcached/Makefile.am +++ b/libmemcached/Makefile.am @@ -1,8 +1,8 @@ EXTRA_DIST = libmemcached_probes.d memcached/README.txt libmemcached.ver \ memcached_configure.h.in -EXTRA_HEADERS = -BUILT_SOURCES= +EXTRA_HEADERS = +BUILT_SOURCES= noinst_HEADERS = libmemcached_probes.h \ memcached_io.h \ @@ -73,14 +73,17 @@ if INCLUDE_HSIEH_SRC libmemcached_la_SOURCES += hsieh_hash.c endif -if BUILD_BYTEORDER -libmemcached_la_SOURCES += byteorder.c -endif - libmemcached_la_DEPENDENCIES= libmemcachedcallbacks.la libmemcached_la_LIBADD= $(LIBM) libmemcachedcallbacks.la libmemcached_la_LDFLAGS = -version-info $(MEMCACHED_LIBRARY_VERSION) $(LD_VERSION_SCRIPT) $(LIBM) +if BUILD_BYTEORDER +noinst_LTLIBRARIES += libbyteorder.la +libbyteorder_la_SOURCES= byteorder.c byteorder.h +libmemcached_la_LIBADD += libbyteorder.la +libmemcached_la_DEPENDENCIES+= libbyteorder.la +endif + if HAVE_DTRACE BUILT_SOURCES+= dtrace_probes.h libmemcached_la_SOURCES += libmemcached_probes.d diff --git a/libmemcached/byteorder.c b/libmemcached/byteorder.c index 28889aae..5b1cf88b 100644 --- a/libmemcached/byteorder.c +++ b/libmemcached/byteorder.c @@ -1,14 +1,14 @@ -#include "common.h" +#include "byteorder.h" /* Byte swap a 64-bit number. */ -static inline uint64_t swap64(uint64_t in) +static inline uint64_t swap64(uint64_t in) { #ifndef BYTEORDER_BIG_ENDIAN /* Little endian, flip the bytes around until someone makes a faster/better * way to do this. */ uint64_t rv= 0; uint8_t x= 0; - for(x= 0; x < 8; x++) + for(x= 0; x < 8; x++) { rv= (rv << 8) | (in & 0xff); in >>= 8; diff --git a/libmemcached/byteorder.h b/libmemcached/byteorder.h new file mode 100644 index 00000000..0964b61a --- /dev/null +++ b/libmemcached/byteorder.h @@ -0,0 +1,20 @@ +#ifndef LIBMEMCACHED_BYTEORDER_H +#define LIBMEMCACHED_BYTEORDER_H + +#include "config.h" + +/* Define this here, which will turn on the visibilty controls while we're + * building libmemcached. + */ +#define BUILDING_LIBMEMCACHED 1 + +#include "libmemcached/memcached.h" + +#ifndef HAVE_HTONLL +LIBMEMCACHED_LOCAL +extern uint64_t ntohll(uint64_t); +LIBMEMCACHED_LOCAL +extern uint64_t htonll(uint64_t); +#endif + +#endif /* LIBMEMCACHED_BYTEORDER_H */ diff --git a/libmemcached/common.h b/libmemcached/common.h index d37fede9..96b83463 100644 --- a/libmemcached/common.h +++ b/libmemcached/common.h @@ -48,6 +48,7 @@ #include "libmemcached/memcached_internal.h" #include "libmemcached/libmemcached_probes.h" #include "libmemcached/memcached/protocol_binary.h" +#include "libmemcached/byteorder.h" /* string value */ struct memcached_continuum_item_st { @@ -142,21 +143,14 @@ memcached_return memcached_key_test(const char **keys, size_t *key_length, LIBMEMCACHED_LOCAL uint32_t generate_hash(memcached_st *ptr, const char *key, size_t key_length); -#ifndef HAVE_HTONLL -LIBMEMCACHED_LOCAL -extern uint64_t ntohll(uint64_t); -LIBMEMCACHED_LOCAL -extern uint64_t htonll(uint64_t); -#endif - LIBMEMCACHED_LOCAL memcached_return memcached_purge(memcached_server_st *ptr); -static inline memcached_return memcached_validate_key_length(size_t key_length, +static inline memcached_return memcached_validate_key_length(size_t key_length, bool binary) { unlikely (key_length == 0) return MEMCACHED_BAD_KEY_PROVIDED; - + if (binary) { unlikely (key_length > 0xffff) @@ -164,7 +158,7 @@ static inline memcached_return memcached_validate_key_length(size_t key_length, } else { - unlikely (key_length >= MEMCACHED_MAX_KEY) + unlikely (key_length >= MEMCACHED_MAX_KEY) return MEMCACHED_BAD_KEY_PROVIDED; }