From 56bb95c23210147d45b792e4e494e995d9de76dc Mon Sep 17 00:00:00 2001 From: Trond Norbye Date: Fri, 5 Feb 2010 20:06:14 +0100 Subject: [PATCH] Use bool instead of bool:1 if your compiler doesn't create correct code --- .bzrignore | 1 + configure.ac | 2 ++ libhashkit/configure.h.in | 21 +++++++++++++++ libhashkit/hashkit.h | 7 ++--- libhashkit/include.am | 5 ++++ libmemcached/configure.h.in | 1 + libmemcached/memcached.h | 40 ++++++++++++++--------------- libmemcached/result.h | 4 +-- libmemcached/server.h | 6 ++--- libmemcached/string.h | 6 ++--- m4/bitfield.m4 | 51 +++++++++++++++++++++++++++++++++++++ 11 files changed, 113 insertions(+), 31 deletions(-) create mode 100644 libhashkit/configure.h.in create mode 100644 m4/bitfield.m4 diff --git a/.bzrignore b/.bzrignore index 527ee066..e3646657 100644 --- a/.bzrignore +++ b/.bzrignore @@ -59,6 +59,7 @@ hashkit_jenkins.pop hashkit_md5.pop hashkit_murmur.pop hashkit_value.pop +libhashkit/configure.h libmemcached-*.tar.gz libmemcached-0.30-1.src.rpm libmemcached-0.30-1.x86_64.rpm diff --git a/configure.ac b/configure.ac index c8054fe3..dc560daf 100644 --- a/configure.ac +++ b/configure.ac @@ -54,6 +54,7 @@ WITH_MEMCACHED ENABLE_DEPRECATED PANDORA_HAVE_LIBINNODB PANDORA_PRINT_CALLSTACK +DETECT_BITFIELD AC_CHECK_HEADERS([atomic.h]) AS_IF([test "x$ac_cv_header_atomic_h" = "xyes"],[ @@ -67,6 +68,7 @@ AS_IF([test "x$ac_cv_header_atomic_h" = "xyes"],[ AC_CONFIG_FILES([ Makefile docs/Makefile + libhashkit/configure.h libmemcached/configure.h support/libmemcached.pc support/libmemcached.spec diff --git a/libhashkit/configure.h.in b/libhashkit/configure.h.in new file mode 100644 index 00000000..6fa78177 --- /dev/null +++ b/libhashkit/configure.h.in @@ -0,0 +1,21 @@ +/* HashKit + * Copyright (C) 2009-2010 Brian Aker + * All rights reserved. + * + * Use and distribution licensed under the BSD license. See + * the COPYING file in the parent directory for full text. + */ +#ifndef LIBHASHKIT_CONFIGURE_H +#define LIBHASHKIT_CONFIGURE_H + +#ifdef __cplusplus +extern "C" { +#endif + +@HASHKIT_BITFIELD@ + +#ifdef __cplusplus +} +#endif + +#endif /* LIBHASHKIT_CONFIGURE_H */ diff --git a/libhashkit/hashkit.h b/libhashkit/hashkit.h index bab3bc08..e3d5862e 100644 --- a/libhashkit/hashkit.h +++ b/libhashkit/hashkit.h @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -57,11 +58,11 @@ struct hashkit_st } base_hash, distribution_hash; struct { - bool is_base_same_distributed:1; + bool is_base_same_distributed HASHKIT_BITFIELD; } flags; struct { - bool is_allocated:1; + bool is_allocated HASHKIT_BITFIELD; } options; }; @@ -81,7 +82,7 @@ public: } Hashkit& operator=(const Hashkit& source) - { + { hashkit_free(this); hashkit_clone(this, &source); diff --git a/libhashkit/include.am b/libhashkit/include.am index f0dfe754..e800d798 100644 --- a/libhashkit/include.am +++ b/libhashkit/include.am @@ -11,9 +11,14 @@ lib_LTLIBRARIES+= libhashkit/libhashkit.la +EXTRA_DIST+= \ + libhashkit/configure.h.in + + nobase_include_HEADERS+= \ libhashkit/algorithm.h \ libhashkit/behavior.h \ + libhashkit/configure.h \ libhashkit/digest.h \ libhashkit/function.h \ libhashkit/hashkit.h \ diff --git a/libmemcached/configure.h.in b/libmemcached/configure.h.in index 17ec8645..064f3b73 100644 --- a/libmemcached/configure.h.in +++ b/libmemcached/configure.h.in @@ -16,6 +16,7 @@ extern "C" { #endif +@MEMCACHED_BITFIELD@ @DEPRECATED@ #define LIBMEMCACHED_VERSION_STRING "@VERSION@" diff --git a/libmemcached/memcached.h b/libmemcached/memcached.h index 32879c9f..9415f432 100644 --- a/libmemcached/memcached.h +++ b/libmemcached/memcached.h @@ -58,27 +58,27 @@ struct memcached_st { @note these are static and should not change without a call to behavior. */ struct { - bool is_purging:1; - bool is_processing_input:1; + bool is_purging MEMCACHED_BITFIELD; + bool is_processing_input MEMCACHED_BITFIELD; } state; struct { // Everything below here is pretty static. - bool auto_eject_hosts:1; - bool binary_protocol:1; - bool buffer_requests:1; - bool cork:1; - bool hash_with_prefix_key:1; - bool ketama_weighted:1; - bool no_block:1; - bool no_reply:1; - bool randomize_replica_read:1; - bool reuse_memory:1; - bool support_cas:1; - bool tcp_nodelay:1; - bool use_cache_lookups:1; - bool use_sort_hosts:1; - bool use_udp:1; - bool verify_key:1; + bool auto_eject_hosts MEMCACHED_BITFIELD; + bool binary_protocol MEMCACHED_BITFIELD; + bool buffer_requests MEMCACHED_BITFIELD; + bool cork MEMCACHED_BITFIELD; + bool hash_with_prefix_key MEMCACHED_BITFIELD; + bool ketama_weighted MEMCACHED_BITFIELD; + bool no_block MEMCACHED_BITFIELD; + bool no_reply MEMCACHED_BITFIELD; + bool randomize_replica_read MEMCACHED_BITFIELD; + bool reuse_memory MEMCACHED_BITFIELD; + bool support_cas MEMCACHED_BITFIELD; + bool tcp_nodelay MEMCACHED_BITFIELD; + bool use_cache_lookups MEMCACHED_BITFIELD; + bool use_sort_hosts MEMCACHED_BITFIELD; + bool use_udp MEMCACHED_BITFIELD; + bool verify_key MEMCACHED_BITFIELD; } flags; memcached_server_distribution_t distribution; hashkit_st hashkit; @@ -122,7 +122,7 @@ struct memcached_st { memcached_callback_st *callbacks; char prefix_key[MEMCACHED_PREFIX_KEY_MAX_SIZE]; struct { - bool is_allocated:1; + bool is_allocated MEMCACHED_BITFIELD; } options; }; @@ -180,7 +180,7 @@ public: } Memcached& operator=(const Memcached& source) - { + { memcached_free(this); memcached_clone(this, &source); diff --git a/libmemcached/result.h b/libmemcached/result.h index ea057569..a7fe00b4 100644 --- a/libmemcached/result.h +++ b/libmemcached/result.h @@ -21,8 +21,8 @@ struct memcached_result_st { memcached_string_st value; char item_key[MEMCACHED_MAX_KEY]; struct { - bool is_allocated:1; - bool is_initialized:1; + bool is_allocated MEMCACHED_BITFIELD; + bool is_initialized MEMCACHED_BITFIELD; } options; /* Add result callback function */ }; diff --git a/libmemcached/server.h b/libmemcached/server.h index 141d71d2..109f9d50 100644 --- a/libmemcached/server.h +++ b/libmemcached/server.h @@ -15,9 +15,9 @@ struct memcached_server_st { struct { - bool is_allocated:1; - bool is_initialized:1; - bool sockaddr_inited:1; + bool is_allocated MEMCACHED_BITFIELD; + bool is_initialized MEMCACHED_BITFIELD; + bool sockaddr_inited MEMCACHED_BITFIELD; } options; uint32_t number_of_hosts; uint32_t cursor_active; diff --git a/libmemcached/string.h b/libmemcached/string.h index 168172ea..605ac57b 100644 --- a/libmemcached/string.h +++ b/libmemcached/string.h @@ -17,7 +17,7 @@ about them. 1) is_initialized is always valid. - 2) A string once intialized will always be, until free where we + 2) A string once intialized will always be, until free where we unset this flag. 3) A string always has a root. */ @@ -28,8 +28,8 @@ struct memcached_string_st { size_t current_size; const memcached_st *root; struct { - bool is_allocated:1; - bool is_initialized:1; + bool is_allocated MEMCACHED_BITFIELD; + bool is_initialized MEMCACHED_BITFIELD; } options; }; diff --git a/m4/bitfield.m4 b/m4/bitfield.m4 new file mode 100644 index 00000000..594855c2 --- /dev/null +++ b/m4/bitfield.m4 @@ -0,0 +1,51 @@ +AC_DEFUN([DETECT_BITFIELD], +[ + AC_CACHE_CHECK([for working bitfield],[ac_cv_have_bitfield],[ + AC_LANG_PUSH([C]) + save_CFLAGS="${CFLAGS}" + CFLAGS="${AM_CFLAGS} ${NO_WERROR}" + + AC_RUN_IFELSE([ + AC_LANG_PROGRAM([[ +#include + ]],[[ + struct flags { bool b0:1; bool b1:1; bool b2:1; bool b3:1; + bool b4:1; bool b5:1; bool b6:1; bool b7:1; + } f = { .b0 = false, .b1 = false, .b2 = false, .b3 = false, + .b4 = false, .b5 = false, .b6 = false, .b7 = false }; + + f.b0 = true; + f.b1 = false; + f.b2 = true; + f.b3 = false; + f.b4 = true; + f.b5 = false; + f.b6 = true; + f.b7 = false; + + if (f.b0 && !f.b1 && f.b2 && !f.b3 && f.b4 && !f.b5 && f.b6 && !f.b7) { + return 0; + } + + return 1; + ]]) + ], [ + ac_cv_have_bitfield=yes + ],[ + ac_cv_have_bitfield=no + ])]) + + CFLAGS=${save_CFLAGS} + AS_IF([test "x$ac_cv_have_bitfield" = "xyes"], + [ + MEMCACHED_BITFIELD="#define MEMCACHED_BITFIELD :1" + HASHKIT_BITFIELD="#define HASHKIT_BITFIELD :1" + ], + [ + MEMCACHED_BITFIELD="#define MEMCACHED_BITFIELD" + HASHKIT_BITFIELD="#define HASHKIT_BITFIELD" + ]) + AC_SUBST([MEMCACHED_BITFIELD]) + AC_SUBST([HASHKIT_BITFIELD]) + AC_LANG_POP() +]) -- 2.30.2