summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Lindner <plindner@hi5.com>2007-04-10 11:51:57 +0000
committerPaul Lindner <plindner@hi5.com>2007-04-10 11:51:57 +0000
commitb80ab7cf2884ae0ddcff553a6449a5644198cd08 (patch)
tree5a825ffd5e7c25e2b3d581e6a8ae39877d0049bc
parent36b3076675338d40c2d3a1dc352a19144bea9f1d (diff)
downloadmemcached-b80ab7cf2884ae0ddcff553a6449a5644198cd08.tar.gz
update clean-whitespace, add automated whitespace test, and clean whitespace
git-svn-id: http://code.sixapart.com/svn/memcached/trunk/server@492 b0b603af-a30f-0410-a34e-baf09ae79d0b
-rw-r--r--ChangeLog3
-rw-r--r--assoc.c48
-rw-r--r--configure.ac8
-rw-r--r--items.c8
-rw-r--r--memcached.c96
-rw-r--r--slabs.c4
-rw-r--r--slabs.h2
-rwxr-xr-xt/whitespace.t21
8 files changed, 107 insertions, 83 deletions
diff --git a/ChangeLog b/ChangeLog
index c76f7e4..e79dde6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -5,6 +5,9 @@
null checks, adds asserts at the top of each function for any
use of conn *c without checking to see if c is NULL first.
+ * Also adjust clean-whitespace.pl to clean *.ac files. Add
+ script to test-suite to test for tabs.
+
2007-04-04 Paul Lindner <lindner@inuus.com>
* Add clarification of flush_all in the protocol docs
diff --git a/assoc.c b/assoc.c
index e057284..90593aa 100644
--- a/assoc.c
+++ b/assoc.c
@@ -69,7 +69,7 @@ This was tested for:
the output delta to a Gray code (a^(a>>1)) so a string of 1's (as
is commonly produced by subtraction) look like a single 1-bit
difference.
-* the base values were pseudorandom, all zero but one bit set, or
+* the base values were pseudorandom, all zero but one bit set, or
all zero plus a counter that starts at zero.
Some k values for my "a-=c; a^=rot(c,k); c+=b;" arrangement that
@@ -79,7 +79,7 @@ satisfy this are
14 9 3 7 17 3
Well, "9 15 3 18 27 15" didn't quite get 32 bits diffing
for "differ" defined as + with a one-bit base and a two-bit delta. I
-used http://burtleburtle.net/bob/hash/avalanche.html to choose
+used http://burtleburtle.net/bob/hash/avalanche.html to choose
the operations, constants, and arrangements of the variables.
This does not achieve avalanche. There are input bits of (a,b,c)
@@ -118,7 +118,7 @@ produce values of c that look totally different. This was tested for
the output delta to a Gray code (a^(a>>1)) so a string of 1's (as
is commonly produced by subtraction) look like a single 1-bit
difference.
-* the base values were pseudorandom, all zero but one bit set, or
+* the base values were pseudorandom, all zero but one bit set, or
all zero plus a counter that starts at zero.
These constants passed:
@@ -142,7 +142,7 @@ and these came close:
}
#if HASH_LITTLE_ENDIAN == 1
-static uint32_t hash(
+static uint32_t hash(
const void *key, /* the key to hash */
size_t length, /* length of the key */
const uint32_t initval) /* initval */
@@ -150,7 +150,7 @@ static uint32_t hash(
uint32_t a,b,c; /* internal state */
union { const void *ptr; size_t i; } u; /* needed for Mac Powerbook G4 */
- /* Set up the internal state */
+ /* Set up the internal state */
a = b = c = 0xdeadbeef + ((uint32_t)length) + initval;
u.ptr = key;
@@ -172,7 +172,7 @@ static uint32_t hash(
}
/*----------------------------- handle the last (probably partial) block */
- /*
+ /*
* "k[2]&0xffffff" actually reads beyond the end of the string, but
* then masks off the part it's not allowed to read. Because the
* string is aligned, the masked-off tail is in the same word as the
@@ -321,7 +321,7 @@ static uint32_t hash(
* hashbig():
* This is the same as hashword() on big-endian machines. It is different
* from hashlittle() on all machines. hashbig() takes advantage of
- * big-endian byte ordering.
+ * big-endian byte ordering.
*/
static uint32_t hash( const void *key, size_t length, const uint32_t initval)
{
@@ -350,7 +350,7 @@ static uint32_t hash( const void *key, size_t length, const uint32_t initval)
}
/*----------------------------- handle the last (probably partial) block */
- /*
+ /*
* "k[2]<<8" actually reads beyond the end of the string, but
* then shifts out the part it's not allowed to read. Because the
* string is aligned, the illegal read is in the same word as the
@@ -447,7 +447,7 @@ static uint32_t hash( const void *key, size_t length, const uint32_t initval)
return c;
}
#else // HASH_XXX_ENDIAN == 1
-#error Must define HASH_BIG_ENDIAN or HASH_LITTLE_ENDIAN
+#error Must define HASH_BIG_ENDIAN or HASH_LITTLE_ENDIAN
#endif // hash_XXX_ENDIAN == 1
typedef unsigned long int ub4; /* unsigned 4-byte quantities */
@@ -541,15 +541,15 @@ static void assoc_expand(void) {
primary_hashtable = calloc(hashsize(hashpower + 1), sizeof(void *));
if (primary_hashtable) {
- if (settings.verbose > 1)
- fprintf(stderr, "Hash table expansion starting\n");
+ if (settings.verbose > 1)
+ fprintf(stderr, "Hash table expansion starting\n");
hashpower++;
expanding = 1;
expand_bucket = 0;
- assoc_move_next_bucket();
+ assoc_move_next_bucket();
} else {
primary_hashtable = old_hashtable;
- /* Bad news, but we can keep running. */
+ /* Bad news, but we can keep running. */
}
}
@@ -560,20 +560,20 @@ void assoc_move_next_bucket(void) {
if (expanding) {
for (it = old_hashtable[expand_bucket]; NULL != it; it = next) {
- next = it->h_next;
+ next = it->h_next;
bucket = hash(ITEM_key(it), it->nkey, 0) & hashmask(hashpower);
it->h_next = primary_hashtable[bucket];
primary_hashtable[bucket] = it;
- }
-
- expand_bucket++;
- if (expand_bucket == hashsize(hashpower - 1)) {
- expanding = 0;
- free(old_hashtable);
- if (settings.verbose > 1)
- fprintf(stderr, "Hash table expansion done\n");
- }
+ }
+
+ expand_bucket++;
+ if (expand_bucket == hashsize(hashpower - 1)) {
+ expanding = 0;
+ free(old_hashtable);
+ if (settings.verbose > 1)
+ fprintf(stderr, "Hash table expansion done\n");
+ }
}
}
@@ -613,7 +613,7 @@ void assoc_delete(const char *key, const size_t nkey) {
hash_items--;
return;
}
- /* Note: we never actually get here. the callers don't delete things
+ /* Note: we never actually get here. the callers don't delete things
they can't find. */
assert(*before != 0);
}
diff --git a/configure.ac b/configure.ac
index 126e0bc..19caccb 100644
--- a/configure.ac
+++ b/configure.ac
@@ -101,10 +101,10 @@ AC_HEADER_STDBOOL
AC_C_CONST
AC_CHECK_HEADER(malloc.h, AC_DEFINE(HAVE_MALLOC_H,,[do we have malloc.h?]))
AC_CHECK_MEMBER([struct mallinfo.arena], [
- AC_DEFINE(HAVE_STRUCT_MALLINFO,,[do we have stuct mallinfo?])
- ], ,[
-# include <malloc.h>
- ]
+ AC_DEFINE(HAVE_STRUCT_MALLINFO,,[do we have stuct mallinfo?])
+ ], ,[
+# include <malloc.h>
+ ]
)
dnl From licq: Copyright (c) 2000 Dirk Mueller
diff --git a/items.c b/items.c
index ca6c04b..5a10082 100644
--- a/items.c
+++ b/items.c
@@ -48,7 +48,7 @@ void item_init(void) {
/*
* Generates the variable-sized part of the header for an object.
*
- * key - The key
+ * key - The key
* nkey - The length of the key
* flags - key flags
* nbytes - Number of bytes to hold value and addition CRLF terminator
@@ -63,7 +63,7 @@ static size_t item_make_header(const uint8_t nkey, const int flags, const int nb
*nsuffix = (uint8_t) snprintf(suffix, 40, " %d %d\r\n", flags, nbytes - 2);
return sizeof(item) + nkey + *nsuffix + nbytes;
}
-
+
/*@null@*/
item *item_alloc(char *key, const size_t nkey, const int flags, const rel_time_t exptime, const int nbytes) {
uint8_t nsuffix;
@@ -86,8 +86,8 @@ item *item_alloc(char *key, const size_t nkey, const int flags, const rel_time_t
if (settings.evict_to_free == 0) return NULL;
- /*
- * try to get one off the right LRU
+ /*
+ * try to get one off the right LRU
* don't necessariuly unlink the tail because it may be locked: refcount>0
* search up from tail an item with refcount==0 and unlink it; give up after 50
* tries
diff --git a/memcached.c b/memcached.c
index 2c8f356..03a8128 100644
--- a/memcached.c
+++ b/memcached.c
@@ -67,7 +67,7 @@
#include "memcached.h"
/*
- * forward declarations
+ * forward declarations
*/
static void drive_machine(conn *c);
static int new_socket(const bool is_udp);
@@ -274,7 +274,7 @@ static void conn_init(void) {
}
/*@null@*/
-static conn *conn_new(const int sfd, const int init_state, const int event_flags,
+static conn *conn_new(const int sfd, const int init_state, const int event_flags,
const int read_buffer_size, const bool is_udp) {
conn *c;
@@ -486,7 +486,7 @@ static void conn_shrink(conn *c) {
c->ilist = newbuf;
c->isize = ITEM_LIST_INITIAL;
}
- /* TODO check error condition? */
+ /* TODO check error condition? */
}
if (c->msgsize > MSG_LIST_HIGHWAT) {
@@ -495,7 +495,7 @@ static void conn_shrink(conn *c) {
c->msglist = newbuf;
c->msgsize = MSG_LIST_INITIAL;
}
- /* TODO check error condition? */
+ /* TODO check error condition? */
}
if (c->iovsize > IOV_LIST_HIGHWAT) {
@@ -504,7 +504,7 @@ static void conn_shrink(conn *c) {
c->iov = newbuf;
c->iovsize = IOV_LIST_INITIAL;
}
- /* TODO check return value */
+ /* TODO check return value */
}
}
@@ -749,14 +749,14 @@ typedef struct token_s {
#define KEY_TOKEN 1
#define KEY_MAX_LENGTH 250
-#define MAX_TOKENS 6
+#define MAX_TOKENS 6
/*
* Tokenize the command string by replacing whitespace with '\0' and update
* the token array tokens with pointer to start of each token and length.
* Returns total number of tokens. The last valid token is the terminal
* token (value points to the first unprocessed character of the string and
- * length zero).
+ * length zero).
*
* Usage example:
*
@@ -774,12 +774,12 @@ static size_t tokenize_command(char *command, token_t *tokens, const size_t max_
size_t length = 0;
size_t ntokens = 0;
- assert(command != NULL && tokens != NULL && max_tokens > 1);
+ assert(command != NULL && tokens != NULL && max_tokens > 1);
cp = command;
while(*cp != '\0' && ntokens < max_tokens - 1) {
if(*cp == ' ') {
- // If we've accumulated a token, this is the end of it.
+ // If we've accumulated a token, this is the end of it.
if(length > 0) {
tokens[ntokens].value = value;
tokens[ntokens].length = length;
@@ -904,7 +904,7 @@ static void process_stat(conn *c, token_t *tokens, const size_t ntokens) {
out_string(c, "SERVER_ERROR out of memory");
return;
}
-
+
fd = open("/proc/self/maps", O_RDONLY);
if (fd == -1) {
out_string(c, "SERVER_ERROR cannot open the maps file");
@@ -926,7 +926,7 @@ static void process_stat(conn *c, token_t *tokens, const size_t ntokens) {
strcpy(wbuf + res, "END\r\n");
c->write_and_free = wbuf;
c->wcurr = wbuf;
- c->wbytes = res + 5; // Don't write the terminal '\0'
+ c->wbytes = res + 5; // Don't write the terminal '\0'
conn_set_state(c, conn_write);
c->write_and_go = conn_read;
close(fd);
@@ -1031,15 +1031,15 @@ static inline void process_get_command(conn *c, token_t *tokens, size_t ntokens)
do {
while(key_token->length != 0) {
-
+
key = key_token->value;
nkey = key_token->length;
-
+
if(nkey > KEY_MAX_LENGTH) {
out_string(c, "CLIENT_ERROR bad command line format");
return;
}
-
+
stats.get_cmds++;
it = get_item(key, nkey);
if (it) {
@@ -1050,7 +1050,7 @@ static inline void process_get_command(conn *c, token_t *tokens, size_t ntokens)
c->ilist = new_list;
} else break;
}
-
+
/*
* Construct the response. Each hit adds three elements to the
* outgoing data list:
@@ -1072,9 +1072,9 @@ static inline void process_get_command(conn *c, token_t *tokens, size_t ntokens)
item_update(it);
*(c->ilist + i) = it;
i++;
-
+
} else stats.get_misses++;
-
+
key_token++;
}
@@ -1086,16 +1086,16 @@ static inline void process_get_command(conn *c, token_t *tokens, size_t ntokens)
ntokens = tokenize_command(key_token->value, tokens, MAX_TOKENS);
key_token = tokens;
}
-
+
} while(key_token->value != NULL);
c->icurr = c->ilist;
c->ileft = i;
-
+
if (settings.verbose > 1)
fprintf(stderr, ">%d END\n", c->sfd);
add_iov(c, "END\r\n", 5);
-
+
if (c->udp && build_udp_headers(c) != 0) {
out_string(c, "SERVER_ERROR out of memory");
}
@@ -1127,12 +1127,12 @@ static void process_update_command(conn *c, token_t *tokens, const size_t ntoken
flags = strtoul(tokens[2].value, NULL, 10);
exptime = strtol(tokens[3].value, NULL, 10);
vlen = strtol(tokens[4].value, NULL, 10);
-
+
if(errno == ERANGE || ((flags == 0 || exptime == 0) && errno == EINVAL)) {
out_string(c, "CLIENT_ERROR bad command line format");
return;
}
-
+
if (settings.managed) {
int bucket = c->bucket;
if (bucket == -1) {
@@ -1158,7 +1158,7 @@ static void process_update_command(conn *c, token_t *tokens, const size_t ntoken
c->sbytes = vlen + 2;
return;
}
-
+
c->item_comm = comm;
c->item = it;
c->ritem = ITEM_data(it);
@@ -1178,15 +1178,15 @@ static void process_arithmetic_command(conn *c, token_t *tokens, const size_t nt
char *ptr;
assert(c != NULL);
-
- if(tokens[KEY_TOKEN].length > KEY_MAX_LENGTH) {
+
+ if(tokens[KEY_TOKEN].length > KEY_MAX_LENGTH) {
out_string(c, "CLIENT_ERROR bad command line format");
return;
}
key = tokens[KEY_TOKEN].value;
nkey = tokens[KEY_TOKEN].length;
-
+
if (settings.managed) {
int bucket = c->bucket;
if (bucket == -1) {
@@ -1207,7 +1207,7 @@ static void process_arithmetic_command(conn *c, token_t *tokens, const size_t nt
}
delta = strtoul(tokens[2].value, NULL, 10);
-
+
if(errno == ERANGE) {
out_string(c, "CLIENT_ERROR bad command line format");
return;
@@ -1215,14 +1215,14 @@ static void process_arithmetic_command(conn *c, token_t *tokens, const size_t nt
ptr = ITEM_data(it);
while ((*ptr != '\0') && (*ptr < '0' && *ptr > '9')) ptr++; // BUG: can't be true
-
+
value = strtol(ptr, NULL, 10);
if(errno == ERANGE) {
out_string(c, "CLIENT_ERROR cannot increment or decrement non-numeric value");
return;
}
-
+
if (incr != 0)
value += delta;
else {
@@ -1254,7 +1254,7 @@ static void process_delete_command(conn *c, token_t *tokens, const size_t ntoken
size_t nkey;
item *it;
time_t exptime = 0;
-
+
assert(c != NULL);
if (settings.managed) {
@@ -1269,7 +1269,7 @@ static void process_delete_command(conn *c, token_t *tokens, const size_t ntoken
return;
}
}
-
+
key = tokens[KEY_TOKEN].value;
nkey = tokens[KEY_TOKEN].length;
@@ -1280,7 +1280,7 @@ static void process_delete_command(conn *c, token_t *tokens, const size_t ntoken
if(ntokens == 4) {
exptime = strtol(tokens[2].value, NULL, 10);
-
+
if(errno == ERANGE) {
out_string(c, "CLIENT_ERROR bad command line format");
return;
@@ -1292,7 +1292,7 @@ static void process_delete_command(conn *c, token_t *tokens, const size_t ntoken
out_string(c, "NOT_FOUND");
return;
}
-
+
if (exptime == 0) {
item_unlink(it);
out_string(c, "DELETED");
@@ -1303,8 +1303,8 @@ static void process_delete_command(conn *c, token_t *tokens, const size_t ntoken
if (new_delete) {
todelete = new_delete;
deltotal *= 2;
- } else {
- /*
+ } else {
+ /*
* can't delete it immediately, user wants a delay,
* but we ran out of memory for the delete queue
*/
@@ -1312,7 +1312,7 @@ static void process_delete_command(conn *c, token_t *tokens, const size_t ntoken
return;
}
}
-
+
it->refcount++;
/* use its expiration time as its deletion time now */
it->exptime = realtime(exptime);
@@ -1323,7 +1323,7 @@ static void process_delete_command(conn *c, token_t *tokens, const size_t ntoken
}
static void process_command(conn *c, char *command) {
-
+
token_t tokens[MAX_TOKENS];
size_t ntokens;
int comm;
@@ -1333,11 +1333,11 @@ static void process_command(conn *c, char *command) {
if (settings.verbose > 1)
fprintf(stderr, "<%d %s\n", c->sfd, command);
- /*
+ /*
* for commands set/add/replace, we build an item and read the data
* directly into it, then continue in nread_complete().
- */
-
+ */
+
c->msgcurr = 0;
c->msgused = 0;
c->iovused = 0;
@@ -1351,14 +1351,14 @@ static void process_command(conn *c, char *command) {
if (ntokens >= 3 &&
((strcmp(tokens[COMMAND_TOKEN].value, "get") == 0) ||
(strcmp(tokens[COMMAND_TOKEN].value, "bget") == 0))) {
-
+
process_get_command(c, tokens, ntokens);
- } else if (ntokens == 6 &&
- ((strcmp(tokens[COMMAND_TOKEN].value, "add") == 0 && (comm = NREAD_ADD)) ||
+ } else if (ntokens == 6 &&
+ ((strcmp(tokens[COMMAND_TOKEN].value, "add") == 0 && (comm = NREAD_ADD)) ||
(strcmp(tokens[COMMAND_TOKEN].value, "set") == 0 && (comm = NREAD_SET)) ||
(strcmp(tokens[COMMAND_TOKEN].value, "replace") == 0 && (comm = NREAD_REPLACE)))) {
-
+
process_update_command(c, tokens, ntokens, comm);
} else if (ntokens == 4 && (strcmp(tokens[COMMAND_TOKEN].value, "incr") == 0)) {
@@ -1379,7 +1379,7 @@ static void process_command(conn *c, char *command) {
out_string(c, "CLIENT_ERROR not a managed instance");
return;
}
-
+
if (sscanf(tokens[1].value, "%u:%u", &bucket,&gen) == 2) {
if ((bucket < 0) || (bucket >= MAX_BUCKETS)) {
out_string(c, "CLIENT_ERROR bucket number out of range");
@@ -1435,7 +1435,7 @@ static void process_command(conn *c, char *command) {
}
} else if (ntokens >= 2 && (strcmp(tokens[COMMAND_TOKEN].value, "stats") == 0)) {
-
+
process_stat(c, tokens, ntokens);
} else if (ntokens >= 2 && ntokens <= 3 && (strcmp(tokens[COMMAND_TOKEN].value, "flush_all") == 0)) {
@@ -1459,7 +1459,7 @@ static void process_command(conn *c, char *command) {
item_flush_expired();
out_string(c, "OK");
return;
-
+
} else if (ntokens == 2 && (strcmp(tokens[COMMAND_TOKEN].value, "version") == 0)) {
out_string(c, "VERSION " VERSION);
@@ -1467,7 +1467,7 @@ static void process_command(conn *c, char *command) {
} else if (ntokens == 2 && (strcmp(tokens[COMMAND_TOKEN].value, "quit") == 0)) {
conn_set_state(c, conn_closing);
-
+
} else if (ntokens == 5 && (strcmp(tokens[COMMAND_TOKEN].value, "slabs") == 0 &&
strcmp(tokens[COMMAND_TOKEN + 1].value, "reassign") == 0)) {
#ifdef ALLOW_SLABS_REASSIGN
diff --git a/slabs.c b/slabs.c
index 50547f7..70dcf04 100644
--- a/slabs.c
+++ b/slabs.c
@@ -78,8 +78,8 @@ static void slabs_preallocate (const unsigned int maxslabs);
* Figures out which slab class (chunk size) is required to store an item of
* a given size.
*
- * Given object size, return id to use when allocating/freeing memory for object
- * 0 means error: can't store such a large object
+ * Given object size, return id to use when allocating/freeing memory for object
+ * 0 means error: can't store such a large object
*/
unsigned int slabs_clsid(const size_t size) {
diff --git a/slabs.h b/slabs.h
index 5388795..3ab538b 100644
--- a/slabs.h
+++ b/slabs.h
@@ -6,7 +6,7 @@
void slabs_init(const size_t limit, const double factor);
-/*
+/*
* Given object size, return id to use when allocating/freeing memory for object
* 0 means error: can't store such a large object
*/
diff --git a/t/whitespace.t b/t/whitespace.t
new file mode 100755
index 0000000..8ed24b2
--- /dev/null
+++ b/t/whitespace.t
@@ -0,0 +1,21 @@
+#!/usr/bin/perl
+use strict;
+use FindBin qw($Bin);
+our @files;
+
+BEGIN {
+ chdir "$Bin/.." or die;
+ @files = (glob("*.h"), glob("*.c"), glob("*.ac"));
+}
+use Test::More tests => scalar(@files);
+
+foreach my $f (@files) {
+ open(my $fh, $f) or die;
+ my $before = do { local $/; <$fh>; };
+ close ($fh);
+ my $after = $before;
+ $after =~ s/\t/ /g;
+ $after =~ s/ +$//mg;
+ $after .= "\n" unless $after =~ /\n$/;
+ ok ($after eq $before, "$f (see devtools/clean-whitespace.pl)");
+}