FAQ

[memcached] plindner, r492: update clean-whitespace, add automated w...

Commits
Apr 10, 2007 at 11:51 am
update clean-whitespace, add automated whitespace test, and clean whitespace

U trunk/server/ChangeLog
U trunk/server/assoc.c
U trunk/server/configure.ac
U trunk/server/items.c
U trunk/server/memcached.c
U trunk/server/slabs.c
U trunk/server/slabs.h
A trunk/server/t/whitespace.t


Modified: trunk/server/ChangeLog
===================================================================
--- trunk/server/ChangeLog 2007-04-10 00:02:36 UTC (rev 491)
+++ trunk/server/ChangeLog 2007-04-10 11:51:57 UTC (rev 492)
@@ -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

Modified: trunk/server/assoc.c
===================================================================
--- trunk/server/assoc.c 2007-04-10 00:02:36 UTC (rev 491)
+++ trunk/server/assoc.c 2007-04-10 11:51:57 UTC (rev 492)
@@ -69,7 +69,7 @@
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 @@
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 @@
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 @@
}

#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 @@
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 @@
}

/*----------------------------- 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 @@
* 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 @@
}

/*----------------------------- 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 @@
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 @@

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,21 +560,21 @@

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");
}
+ }
}

/* Note: this isn't an assoc_update. The key must not already exist to call this */
@@ -613,7 +613,7 @@
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);
}

Modified: trunk/server/configure.ac
===================================================================
--- trunk/server/configure.ac 2007-04-10 00:02:36 UTC (rev 491)
+++ trunk/server/configure.ac 2007-04-10 11:51:57 UTC (rev 492)
@@ -101,10 +101,10 @@
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

Modified: trunk/server/items.c
===================================================================
--- trunk/server/items.c 2007-04-10 00:02:36 UTC (rev 491)
+++ trunk/server/items.c 2007-04-10 11:51:57 UTC (rev 492)
@@ -48,7 +48,7 @@
/*
* 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 @@
*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 @@

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

Modified: trunk/server/memcached.c
===================================================================
--- trunk/server/memcached.c 2007-04-10 00:02:36 UTC (rev 491)
+++ trunk/server/memcached.c 2007-04-10 11:51:57 UTC (rev 492)
@@ -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 @@
}

/*@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 @@
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 @@
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 @@
c->iov = newbuf;
c->iovsize = IOV_LIST_INITIAL;
}
- /* TODO check return value */
+ /* TODO check return value */
}
}

@@ -749,14 +749,14 @@
#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 @@
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 @@
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 @@
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 @@

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 @@
c->ilist = new_list;
} else break;
}
-
+
/*
* Construct the response. Each hit adds three elements to the
* outgoing data list:
@@ -1072,9 +1072,9 @@
item_update(it);
*(c->ilist + i) = it;
i++;
-
+
} else stats.get_misses++;
-
+
key_token++;
}

@@ -1086,16 +1086,16 @@
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 @@
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 @@
c->sbytes = vlen + 2;
return;
}
-
+
c->item_comm = comm;
c->item = it;
c->ritem = ITEM_data(it);
@@ -1178,15 +1178,15 @@
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 @@
}

delta = strtoul(tokens[2].value, NULL, 10);
-
+
if(errno == ERANGE) {
out_string(c, "CLIENT_ERROR bad command line format");
return;
@@ -1215,14 +1215,14 @@

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 @@
size_t nkey;
item *it;
time_t exptime = 0;
-
+
assert(c != NULL);

if (settings.managed) {
@@ -1269,7 +1269,7 @@
return;
}
}
-
+
key = tokens[KEY_TOKEN].value;
nkey = tokens[KEY_TOKEN].length;

@@ -1280,7 +1280,7 @@

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 @@
out_string(c, "NOT_FOUND");
return;
}
-
+
if (exptime == 0) {
item_unlink(it);
out_string(c, "DELETED");
@@ -1303,8 +1303,8 @@
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 @@
return;
}
}
-
+
it->refcount++;
/* use its expiration time as its deletion time now */
it->exptime = realtime(exptime);
@@ -1323,7 +1323,7 @@
}

static void process_command(conn *c, char *command) {
-
+
token_t tokens[MAX_TOKENS];
size_t ntokens;
int comm;
@@ -1333,11 +1333,11 @@
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 @@
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 @@
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 @@
}

} 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 @@
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 @@
} 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

Modified: trunk/server/slabs.c
===================================================================
--- trunk/server/slabs.c 2007-04-10 00:02:36 UTC (rev 491)
+++ trunk/server/slabs.c 2007-04-10 11:51:57 UTC (rev 492)
@@ -78,8 +78,8 @@
* 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) {

Modified: trunk/server/slabs.h
===================================================================
--- trunk/server/slabs.h 2007-04-10 00:02:36 UTC (rev 491)
+++ trunk/server/slabs.h 2007-04-10 11:51:57 UTC (rev 492)
@@ -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
*/

Added: trunk/server/t/whitespace.t
===================================================================
--- trunk/server/t/whitespace.t 2007-04-10 00:02:36 UTC (rev 491)
+++ trunk/server/t/whitespace.t 2007-04-10 11:51:57 UTC (rev 492)
@@ -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)");
+}


Property changes on: trunk/server/t/whitespace.t
___________________________________________________________________
Name: svn:executable
+ *
reply

Search Discussions

Discussion Navigation
viewthread | post

1 user in discussion

Commits: 1 post