Changeset 492

Show
Ignore:
Timestamp:
04/10/07 11:51:57 (2 years ago)
Author:
plindner
Message:

update clean-whitespace, add automated whitespace test, and clean whitespace

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/server/ChangeLog

    r489 r492  
    55          null checks, adds asserts at the top of each function for any 
    66          use of conn *c without checking to see if c is NULL first. 
     7 
     8        * Also adjust clean-whitespace.pl to clean *.ac files.  Add 
     9          script to test-suite to test for tabs. 
    710 
    8112007-04-04  Paul Lindner  <lindner@inuus.com> 
  • trunk/server/assoc.c

    r468 r492  
    7070  is commonly produced by subtraction) look like a single 1-bit 
    7171  difference. 
    72 * the base values were pseudorandom, all zero but one bit set, or  
     72* the base values were pseudorandom, all zero but one bit set, or 
    7373  all zero plus a counter that starts at zero. 
    7474 
     
    8080Well, "9 15 3 18 27 15" didn't quite get 32 bits diffing 
    8181for "differ" defined as + with a one-bit base and a two-bit delta.  I 
    82 used http://burtleburtle.net/bob/hash/avalanche.html to choose  
     82used http://burtleburtle.net/bob/hash/avalanche.html to choose 
    8383the operations, constants, and arrangements of the variables. 
    8484 
     
    119119  is commonly produced by subtraction) look like a single 1-bit 
    120120  difference. 
    121 * the base values were pseudorandom, all zero but one bit set, or  
     121* the base values were pseudorandom, all zero but one bit set, or 
    122122  all zero plus a counter that starts at zero. 
    123123 
     
    143143 
    144144#if HASH_LITTLE_ENDIAN == 1 
    145 static uint32_t hash(  
     145static uint32_t hash( 
    146146  const void *key,       /* the key to hash */ 
    147147  size_t      length,    /* length of the key */ 
     
    151151  union { const void *ptr; size_t i; } u;     /* needed for Mac Powerbook G4 */ 
    152152 
    153   /* Set up the internal state */   
     153  /* Set up the internal state */ 
    154154  a = b = c = 0xdeadbeef + ((uint32_t)length) + initval; 
    155155 
     
    173173 
    174174    /*----------------------------- handle the last (probably partial) block */ 
    175     /*  
     175    /* 
    176176     * "k[2]&0xffffff" actually reads beyond the end of the string, but 
    177177     * then masks off the part it's not allowed to read.  Because the 
     
    322322 * This is the same as hashword() on big-endian machines.  It is different 
    323323 * from hashlittle() on all machines.  hashbig() takes advantage of 
    324  * big-endian byte ordering.  
     324 * big-endian byte ordering. 
    325325 */ 
    326326static uint32_t hash( const void *key, size_t length, const uint32_t initval) 
     
    351351 
    352352    /*----------------------------- handle the last (probably partial) block */ 
    353     /*  
     353    /* 
    354354     * "k[2]<<8" actually reads beyond the end of the string, but 
    355355     * then shifts out the part it's not allowed to read.  Because the 
     
    448448} 
    449449#else // HASH_XXX_ENDIAN == 1 
    450 #error Must define HASH_BIG_ENDIAN or HASH_LITTLE_ENDIAN  
     450#error Must define HASH_BIG_ENDIAN or HASH_LITTLE_ENDIAN 
    451451#endif // hash_XXX_ENDIAN == 1 
    452452 
     
    542542    primary_hashtable = calloc(hashsize(hashpower + 1), sizeof(void *)); 
    543543    if (primary_hashtable) { 
    544        if (settings.verbose > 1) 
    545            fprintf(stderr, "Hash table expansion starting\n"); 
     544    if (settings.verbose > 1) 
     545        fprintf(stderr, "Hash table expansion starting\n"); 
    546546        hashpower++; 
    547547        expanding = 1; 
    548548        expand_bucket = 0; 
    549        assoc_move_next_bucket(); 
     549    assoc_move_next_bucket(); 
    550550    } else { 
    551551        primary_hashtable = old_hashtable; 
    552        /* Bad news, but we can keep running. */ 
     552    /* Bad news, but we can keep running. */ 
    553553    } 
    554554} 
     
    561561    if (expanding) { 
    562562        for (it = old_hashtable[expand_bucket]; NULL != it; it = next) { 
    563            next = it->h_next; 
     563        next = it->h_next; 
    564564 
    565565            bucket = hash(ITEM_key(it), it->nkey, 0) & hashmask(hashpower); 
    566566            it->h_next = primary_hashtable[bucket]; 
    567567            primary_hashtable[bucket] = it; 
    568        
    569  
    570        expand_bucket++; 
    571        if (expand_bucket == hashsize(hashpower - 1)) { 
    572            expanding = 0; 
    573            free(old_hashtable); 
    574            if (settings.verbose > 1) 
    575                fprintf(stderr, "Hash table expansion done\n"); 
    576        
     568   
     569 
     570    expand_bucket++; 
     571    if (expand_bucket == hashsize(hashpower - 1)) { 
     572        expanding = 0; 
     573        free(old_hashtable); 
     574        if (settings.verbose > 1) 
     575            fprintf(stderr, "Hash table expansion done\n"); 
     576   
    577577    } 
    578578} 
     
    614614        return; 
    615615    } 
    616     /* Note:  we never actually get here.  the callers don't delete things  
     616    /* Note:  we never actually get here.  the callers don't delete things 
    617617       they can't find. */ 
    618618    assert(*before != 0); 
  • trunk/server/configure.ac

    r468 r492  
    102102AC_CHECK_HEADER(malloc.h, AC_DEFINE(HAVE_MALLOC_H,,[do we have malloc.h?])) 
    103103AC_CHECK_MEMBER([struct mallinfo.arena], [ 
    104                AC_DEFINE(HAVE_STRUCT_MALLINFO,,[do we have stuct mallinfo?]) 
    105        ], ,[ 
    106 #      include <malloc.h> 
    107        
     104        AC_DEFINE(HAVE_STRUCT_MALLINFO,,[do we have stuct mallinfo?]) 
     105    ], ,[ 
     106#    include <malloc.h> 
     107   
    108108) 
    109109 
  • trunk/server/items.c

    r489 r492  
    4949 * Generates the variable-sized part of the header for an object. 
    5050 * 
    51  * key     - The key  
     51 * key     - The key 
    5252 * nkey    - The length of the key 
    5353 * flags   - key flags 
     
    6464    return sizeof(item) + nkey + *nsuffix + nbytes; 
    6565} 
    66   
     66 
    6767/*@null@*/ 
    6868item *item_alloc(char *key, const size_t nkey, const int flags, const rel_time_t exptime, const int nbytes) { 
     
    8787        if (settings.evict_to_free == 0) return NULL; 
    8888 
    89         /*  
    90          * try to get one off the right LRU  
     89        /* 
     90         * try to get one off the right LRU 
    9191         * don't necessariuly unlink the tail because it may be locked: refcount>0 
    9292         * search up from tail an item with refcount==0 and unlink it; give up after 50 
  • trunk/server/memcached.c

    r489 r492  
    6868 
    6969/* 
    70  * forward declarations  
     70 * forward declarations 
    7171 */ 
    7272static void drive_machine(conn *c); 
     
    275275 
    276276/*@null@*/ 
    277 static conn *conn_new(const int sfd, const int init_state, const int event_flags,  
     277static conn *conn_new(const int sfd, const int init_state, const int event_flags, 
    278278                      const int read_buffer_size, const bool is_udp) { 
    279279    conn *c; 
     
    487487            c->isize = ITEM_LIST_INITIAL; 
    488488        } 
    489        /* TODO check error condition? */ 
     489    /* TODO check error condition? */ 
    490490    } 
    491491 
     
    496496            c->msgsize = MSG_LIST_INITIAL; 
    497497        } 
    498        /* TODO check error condition? */ 
     498    /* TODO check error condition? */ 
    499499    } 
    500500 
     
    505505            c->iovsize = IOV_LIST_INITIAL; 
    506506        } 
    507        /* TODO check return value */ 
     507    /* TODO check return value */ 
    508508    } 
    509509} 
     
    750750#define KEY_MAX_LENGTH 250 
    751751 
    752 #define MAX_TOKENS 6  
     752#define MAX_TOKENS 6 
    753753 
    754754/* 
     
    757757 * Returns total number of tokens.  The last valid token is the terminal 
    758758 * token (value points to the first unprocessed character of the string and 
    759  * length zero).   
     759 * length zero). 
    760760 * 
    761761 * Usage example: 
     
    775775    size_t ntokens = 0; 
    776776 
    777     assert(command != NULL && tokens != NULL && max_tokens > 1);  
     777    assert(command != NULL && tokens != NULL && max_tokens > 1); 
    778778 
    779779    cp = command; 
    780780    while(*cp != '\0' && ntokens < max_tokens - 1) { 
    781781        if(*cp == ' ') { 
    782             // If we've accumulated a token, this is the end of it.  
     782            // If we've accumulated a token, this is the end of it. 
    783783            if(length > 0) { 
    784784                tokens[ntokens].value = value; 
     
    905905            return; 
    906906        } 
    907              
     907 
    908908        fd = open("/proc/self/maps", O_RDONLY); 
    909909        if (fd == -1) { 
     
    927927        c->write_and_free = wbuf; 
    928928        c->wcurr = wbuf; 
    929         c->wbytes = res + 5; // Don't write the terminal '\0'  
     929        c->wbytes = res + 5; // Don't write the terminal '\0' 
    930930        conn_set_state(c, conn_write); 
    931931        c->write_and_go = conn_read; 
     
    10321032    do { 
    10331033        while(key_token->length != 0) { 
    1034              
     1034 
    10351035            key = key_token->value; 
    10361036            nkey = key_token->length; 
    1037              
     1037 
    10381038            if(nkey > KEY_MAX_LENGTH) { 
    10391039                out_string(c, "CLIENT_ERROR bad command line format"); 
    10401040                return; 
    10411041            } 
    1042                  
     1042 
    10431043            stats.get_cmds++; 
    10441044            it = get_item(key, nkey); 
     
    10511051                    } else break; 
    10521052                } 
    1053                      
     1053 
    10541054                /* 
    10551055                 * Construct the response. Each hit adds three elements to the 
     
    10731073                *(c->ilist + i) = it; 
    10741074                i++; 
    1075                  
     1075 
    10761076            } else stats.get_misses++; 
    1077              
     1077 
    10781078            key_token++; 
    10791079        } 
     
    10871087            key_token = tokens; 
    10881088        } 
    1089          
     1089 
    10901090    } while(key_token->value != NULL); 
    10911091 
    10921092    c->icurr = c->ilist; 
    10931093    c->ileft = i; 
    1094              
     1094 
    10951095    if (settings.verbose > 1) 
    10961096        fprintf(stderr, ">%d END\n", c->sfd); 
    10971097    add_iov(c, "END\r\n", 5); 
    1098          
     1098 
    10991099    if (c->udp && build_udp_headers(c) != 0) { 
    11001100        out_string(c, "SERVER_ERROR out of memory"); 
     
    11281128    exptime = strtol(tokens[3].value, NULL, 10); 
    11291129    vlen = strtol(tokens[4].value, NULL, 10); 
    1130      
     1130 
    11311131    if(errno == ERANGE || ((flags == 0 || exptime == 0) && errno == EINVAL)) { 
    11321132        out_string(c, "CLIENT_ERROR bad command line format"); 
    11331133        return; 
    11341134    } 
    1135      
     1135 
    11361136    if (settings.managed) { 
    11371137        int bucket = c->bucket; 
     
    11591159        return; 
    11601160    } 
    1161      
     1161 
    11621162    c->item_comm = comm; 
    11631163    c->item = it; 
     
    11791179 
    11801180    assert(c != NULL); 
    1181      
    1182     if(tokens[KEY_TOKEN].length > KEY_MAX_LENGTH) {  
     1181 
     1182    if(tokens[KEY_TOKEN].length > KEY_MAX_LENGTH) { 
    11831183        out_string(c, "CLIENT_ERROR bad command line format"); 
    11841184        return; 
     
    11871187    key = tokens[KEY_TOKEN].value; 
    11881188    nkey = tokens[KEY_TOKEN].length; 
    1189          
     1189 
    11901190    if (settings.managed) { 
    11911191        int bucket = c->bucket; 
     
    12081208 
    12091209    delta = strtoul(tokens[2].value, NULL, 10); 
    1210          
     1210 
    12111211    if(errno == ERANGE) { 
    12121212        out_string(c, "CLIENT_ERROR bad command line format"); 
     
    12161216    ptr = ITEM_data(it); 
    12171217    while ((*ptr != '\0') && (*ptr < '0' && *ptr > '9')) ptr++;    // BUG: can't be true 
    1218          
     1218 
    12191219    value = strtol(ptr, NULL, 10); 
    12201220 
     
    12231223        return; 
    12241224    } 
    1225      
     1225 
    12261226    if (incr != 0) 
    12271227        value += delta; 
     
    12551255    item *it; 
    12561256    time_t exptime = 0; 
    1257      
     1257 
    12581258    assert(c != NULL); 
    12591259 
     
    12701270        } 
    12711271    } 
    1272      
     1272 
    12731273    key = tokens[KEY_TOKEN].value; 
    12741274    nkey = tokens[KEY_TOKEN].length; 
     
    12811281    if(ntokens == 4) { 
    12821282        exptime = strtol(tokens[2].value, NULL, 10); 
    1283          
     1283 
    12841284        if(errno == ERANGE) { 
    12851285            out_string(c, "CLIENT_ERROR bad command line format"); 
     
    12931293        return; 
    12941294    } 
    1295      
     1295 
    12961296    if (exptime == 0) { 
    12971297        item_unlink(it); 
     
    13041304            todelete = new_delete; 
    13051305            deltotal *= 2; 
    1306         } else {  
    1307             /*  
     1306        } else { 
     1307            /* 
    13081308             * can't delete it immediately, user wants a delay, 
    13091309             * but we ran out of memory for the delete queue 
     
    13131313        } 
    13141314    } 
    1315      
     1315 
    13161316    it->refcount++; 
    13171317    /* use its expiration time as its deletion time now */ 
     
    13241324 
    13251325static void process_command(conn *c, char *command) { 
    1326      
     1326 
    13271327    token_t tokens[MAX_TOKENS]; 
    13281328    size_t ntokens; 
     
    13341334        fprintf(stderr, "<%d %s\n", c->sfd, command); 
    13351335 
    1336     /*  
     1336    /* 
    13371337     * for commands set/add/replace, we build an item and read the data 
    13381338     * directly into it, then continue in nread_complete(). 
    1339      */  
    1340      
     1339     */ 
     1340 
    13411341    c->msgcurr = 0; 
    13421342    c->msgused = 0; 
     
    13521352        ((strcmp(tokens[COMMAND_TOKEN].value, "get") == 0) || 
    13531353         (strcmp(tokens[COMMAND_TOKEN].value, "bget") == 0))) { 
    1354          
     1354 
    13551355        process_get_command(c, tokens, ntokens); 
    13561356 
    1357     } else if (ntokens == 6 &&  
    1358                ((strcmp(tokens[COMMAND_TOKEN].value, "add") == 0 && (comm = NREAD_ADD)) ||  
     1357    } else if (ntokens == 6 && 
     1358               ((strcmp(tokens[COMMAND_TOKEN].value, "add") == 0 && (comm = NREAD_ADD)) || 
    13591359                (strcmp(tokens[COMMAND_TOKEN].value, "set") == 0 && (comm = NREAD_SET)) || 
    13601360                (strcmp(tokens[COMMAND_TOKEN].value, "replace") == 0 && (comm = NREAD_REPLACE)))) { 
    1361          
     1361 
    13621362        process_update_command(c, tokens, ntokens, comm); 
    13631363 
     
    13801380            return; 
    13811381        } 
    1382          
     1382 
    13831383        if (sscanf(tokens[1].value, "%u:%u", &bucket,&gen) == 2) { 
    13841384            if ((bucket < 0) || (bucket >= MAX_BUCKETS)) { 
     
    14361436 
    14371437    } else if (ntokens >= 2 && (strcmp(tokens[COMMAND_TOKEN].value, "stats") == 0)) { 
    1438          
     1438 
    14391439        process_stat(c, tokens, ntokens); 
    14401440 
     
    14601460        out_string(c, "OK"); 
    14611461        return; 
    1462   
     1462 
    14631463    } else if (ntokens == 2 && (strcmp(tokens[COMMAND_TOKEN].value, "version") == 0)) { 
    14641464 
     
    14681468 
    14691469        conn_set_state(c, conn_closing); 
    1470          
     1470 
    14711471    } else if (ntokens == 5 && (strcmp(tokens[COMMAND_TOKEN].value, "slabs") == 0 && 
    14721472                                strcmp(tokens[COMMAND_TOKEN + 1].value, "reassign") == 0)) { 
  • trunk/server/slabs.c

    r489 r492  
    7979 * a given size. 
    8080 * 
    81  * Given object size, return id to use when allocating/freeing memory for object  
    82  * 0 means error: can't store such a large object  
     81 * Given object size, return id to use when allocating/freeing memory for object 
     82 * 0 means error: can't store such a large object 
    8383 */ 
    8484 
  • trunk/server/slabs.h

    r468 r492  
    77 
    88 
    9 /*   
     9/* 
    1010 * Given object size, return id to use when allocating/freeing memory for object 
    1111 * 0 means error: can't store such a large object