]> git.ozlabs.org Git - ccan/commitdiff
tdb2: make tdb2 compile clean under -Wshadow.
authorRusty Russell <rusty@rustcorp.com.au>
Thu, 24 Feb 2011 05:33:46 +0000 (16:03 +1030)
committerRusty Russell <rusty@rustcorp.com.au>
Thu, 24 Feb 2011 05:33:46 +0000 (16:03 +1030)
This isn't a general requirement for CCAN modules, but Samba uses it, so
make sure tdb2 doesn't upset it.

ccan/tdb2/check.c
ccan/tdb2/hash.c
ccan/tdb2/io.c
ccan/tdb2/summary.c
ccan/tdb2/test/run-30-exhaust-before-expand.c
ccan/tdb2/transaction.c

index d614d4cbf7778a9ebc5927c09ca71dc7736f3574..5a238a1c48274c507511518bea9d060daaa2e8de 100644 (file)
@@ -453,7 +453,7 @@ static bool check_free(struct tdb_context *tdb,
 static bool check_free_table(struct tdb_context *tdb,
                             tdb_off_t ftable_off,
                             unsigned ftable_num,
 static bool check_free_table(struct tdb_context *tdb,
                             tdb_off_t ftable_off,
                             unsigned ftable_num,
-                            tdb_off_t free[],
+                            tdb_off_t fr[],
                             size_t num_free,
                             size_t *num_found)
 {
                             size_t num_free,
                             size_t *num_found)
 {
@@ -487,7 +487,7 @@ static bool check_free_table(struct tdb_context *tdb,
                                return false;
 
                        /* FIXME: Check hash bits */
                                return false;
 
                        /* FIXME: Check hash bits */
-                       p = asearch(&off, free, num_free, off_cmp);
+                       p = asearch(&off, fr, num_free, off_cmp);
                        if (!p) {
                                tdb_logerr(tdb, TDB_ERR_CORRUPT,
                                           TDB_DEBUG_ERROR,
                        if (!p) {
                                tdb_logerr(tdb, TDB_ERR_CORRUPT,
                                           TDB_DEBUG_ERROR,
@@ -522,7 +522,7 @@ size_t dead_space(struct tdb_context *tdb, tdb_off_t off)
 
 static bool check_linear(struct tdb_context *tdb,
                         tdb_off_t **used, size_t *num_used,
 
 static bool check_linear(struct tdb_context *tdb,
                         tdb_off_t **used, size_t *num_used,
-                        tdb_off_t **free, size_t *num_free,
+                        tdb_off_t **fr, size_t *num_free,
                         tdb_off_t recovery)
 {
        tdb_off_t off;
                         tdb_off_t recovery)
 {
        tdb_off_t off;
@@ -603,7 +603,7 @@ static bool check_linear(struct tdb_context *tdb,
                        }
                        /* This record should be in free lists. */
                        if (frec_ftable(&rec.f) != TDB_FTABLE_NONE
                        }
                        /* This record should be in free lists. */
                        if (frec_ftable(&rec.f) != TDB_FTABLE_NONE
-                           && !append(free, num_free, off))
+                           && !append(fr, num_free, off))
                                return false;
                } else if (rec_magic(&rec.u) == TDB_USED_MAGIC
                           || rec_magic(&rec.u) == TDB_CHAIN_MAGIC
                                return false;
                } else if (rec_magic(&rec.u) == TDB_USED_MAGIC
                           || rec_magic(&rec.u) == TDB_CHAIN_MAGIC
@@ -661,7 +661,7 @@ int tdb_check(struct tdb_context *tdb,
              int (*check)(TDB_DATA key, TDB_DATA data, void *private_data),
              void *private_data)
 {
              int (*check)(TDB_DATA key, TDB_DATA data, void *private_data),
              void *private_data)
 {
-       tdb_off_t *free = NULL, *used = NULL, ft, recovery;
+       tdb_off_t *fr = NULL, *used = NULL, ft, recovery;
        size_t num_free = 0, num_used = 0, num_found = 0, num_ftables = 0;
 
        if (tdb_allrecord_lock(tdb, F_RDLCK, TDB_LOCK_WAIT, false) != 0)
        size_t num_free = 0, num_used = 0, num_found = 0, num_ftables = 0;
 
        if (tdb_allrecord_lock(tdb, F_RDLCK, TDB_LOCK_WAIT, false) != 0)
@@ -676,13 +676,13 @@ int tdb_check(struct tdb_context *tdb,
                goto fail;
 
        /* First we do a linear scan, checking all records. */
                goto fail;
 
        /* First we do a linear scan, checking all records. */
-       if (!check_linear(tdb, &used, &num_used, &free, &num_free, recovery))
+       if (!check_linear(tdb, &used, &num_used, &fr, &num_free, recovery))
                goto fail;
 
        for (ft = first_ftable(tdb); ft; ft = next_ftable(tdb, ft)) {
                if (ft == TDB_OFF_ERR)
                        goto fail;
                goto fail;
 
        for (ft = first_ftable(tdb); ft; ft = next_ftable(tdb, ft)) {
                if (ft == TDB_OFF_ERR)
                        goto fail;
-               if (!check_free_table(tdb, ft, num_ftables, free, num_free,
+               if (!check_free_table(tdb, ft, num_ftables, fr, num_free,
                                      &num_found))
                        goto fail;
                num_ftables++;
                                      &num_found))
                        goto fail;
                num_ftables++;
index 18f6b1720eb662b2a0f140a6d23f7c844269b223..e1b1dfe34bdbfa071e8e4b8a43595c56af247b9d 100644 (file)
@@ -64,7 +64,7 @@ uint64_t hash_record(struct tdb_context *tdb, tdb_off_t off)
 }
 
 /* Get bits from a value. */
 }
 
 /* Get bits from a value. */
-static uint32_t bits(uint64_t val, unsigned start, unsigned num)
+static uint32_t bits_from(uint64_t val, unsigned start, unsigned num)
 {
        assert(num <= 32);
        return (val >> start) & ((1U << num) - 1);
 {
        assert(num <= 32);
        return (val >> start) & ((1U << num) - 1);
@@ -75,7 +75,7 @@ static uint32_t bits(uint64_t val, unsigned start, unsigned num)
 static uint32_t use_bits(struct hash_info *h, unsigned num)
 {
        h->hash_used += num;
 static uint32_t use_bits(struct hash_info *h, unsigned num)
 {
        h->hash_used += num;
-       return bits(h->h, 64 - h->hash_used, num);
+       return bits_from(h->h, 64 - h->hash_used, num);
 }
 
 static bool key_matches(struct tdb_context *tdb,
 }
 
 static bool key_matches(struct tdb_context *tdb,
@@ -119,8 +119,8 @@ static bool match(struct tdb_context *tdb,
        }
 
        /* Top bits of offset == next bits of hash. */
        }
 
        /* Top bits of offset == next bits of hash. */
-       if (bits(val, TDB_OFF_HASH_EXTRA_BIT, TDB_OFF_UPPER_STEAL_EXTRA)
-           != bits(h->h, 64 - h->hash_used - TDB_OFF_UPPER_STEAL_EXTRA,
+       if (bits_from(val, TDB_OFF_HASH_EXTRA_BIT, TDB_OFF_UPPER_STEAL_EXTRA)
+           != bits_from(h->h, 64 - h->hash_used - TDB_OFF_UPPER_STEAL_EXTRA,
                    TDB_OFF_UPPER_STEAL_EXTRA)) {
                add_stat(tdb, compare_wrong_offsetbits, 1);
                return false;
                    TDB_OFF_UPPER_STEAL_EXTRA)) {
                add_stat(tdb, compare_wrong_offsetbits, 1);
                return false;
@@ -378,7 +378,7 @@ static tdb_off_t encode_offset(tdb_off_t new_off, struct hash_info *h)
 {
        return h->home_bucket
                | new_off
 {
        return h->home_bucket
                | new_off
-               | ((uint64_t)bits(h->h,
+               | ((uint64_t)bits_from(h->h,
                                  64 - h->hash_used - TDB_OFF_UPPER_STEAL_EXTRA,
                                  TDB_OFF_UPPER_STEAL_EXTRA)
                   << TDB_OFF_HASH_EXTRA_BIT);
                                  64 - h->hash_used - TDB_OFF_UPPER_STEAL_EXTRA,
                                  TDB_OFF_UPPER_STEAL_EXTRA)
                   << TDB_OFF_HASH_EXTRA_BIT);
@@ -683,13 +683,13 @@ int next_in_hash(struct tdb_context *tdb, int ltype,
                 TDB_DATA *kbuf, size_t *dlen)
 {
        const unsigned group_bits = TDB_TOPLEVEL_HASH_BITS-TDB_HASH_GROUP_BITS;
                 TDB_DATA *kbuf, size_t *dlen)
 {
        const unsigned group_bits = TDB_TOPLEVEL_HASH_BITS-TDB_HASH_GROUP_BITS;
-       tdb_off_t hlock_start, hlock_range, off;
+       tdb_off_t hl_start, hl_range, off;
 
        while (tinfo->toplevel_group < (1 << group_bits)) {
 
        while (tinfo->toplevel_group < (1 << group_bits)) {
-               hlock_start = (tdb_off_t)tinfo->toplevel_group
+               hl_start = (tdb_off_t)tinfo->toplevel_group
                        << (64 - group_bits);
                        << (64 - group_bits);
-               hlock_range = 1ULL << group_bits;
-               if (tdb_lock_hashes(tdb, hlock_start, hlock_range, ltype,
+               hl_range = 1ULL << group_bits;
+               if (tdb_lock_hashes(tdb, hl_start, hl_range, ltype,
                                    TDB_LOCK_WAIT) != 0)
                        return -1;
 
                                    TDB_LOCK_WAIT) != 0)
                        return -1;
 
@@ -699,8 +699,7 @@ int next_in_hash(struct tdb_context *tdb, int ltype,
 
                        if (tdb_read_convert(tdb, off, &rec, sizeof(rec))) {
                                tdb_unlock_hashes(tdb,
 
                        if (tdb_read_convert(tdb, off, &rec, sizeof(rec))) {
                                tdb_unlock_hashes(tdb,
-                                                 hlock_start, hlock_range,
-                                                 ltype);
+                                                 hl_start, hl_range, ltype);
                                return -1;
                        }
                        if (rec_magic(&rec) != TDB_USED_MAGIC) {
                                return -1;
                        }
                        if (rec_magic(&rec) != TDB_USED_MAGIC) {
@@ -726,11 +725,11 @@ int next_in_hash(struct tdb_context *tdb, int ltype,
                                                            off + sizeof(rec),
                                                            kbuf->dsize);
                        }
                                                            off + sizeof(rec),
                                                            kbuf->dsize);
                        }
-                       tdb_unlock_hashes(tdb, hlock_start, hlock_range, ltype);
+                       tdb_unlock_hashes(tdb, hl_start, hl_range, ltype);
                        return kbuf->dptr ? 1 : -1;
                }
 
                        return kbuf->dptr ? 1 : -1;
                }
 
-               tdb_unlock_hashes(tdb, hlock_start, hlock_range, ltype);
+               tdb_unlock_hashes(tdb, hl_start, hl_range, ltype);
 
                tinfo->toplevel_group++;
                tinfo->levels[0].hashtable
 
                tinfo->toplevel_group++;
                tinfo->levels[0].hashtable
@@ -767,7 +766,7 @@ static int chainlock(struct tdb_context *tdb, const TDB_DATA *key,
        unsigned int group, gbits;
 
        gbits = TDB_TOPLEVEL_HASH_BITS - TDB_HASH_GROUP_BITS;
        unsigned int group, gbits;
 
        gbits = TDB_TOPLEVEL_HASH_BITS - TDB_HASH_GROUP_BITS;
-       group = bits(h, 64 - gbits, gbits);
+       group = bits_from(h, 64 - gbits, gbits);
 
        lockstart = hlock_range(group, &locksize);
 
 
        lockstart = hlock_range(group, &locksize);
 
@@ -790,7 +789,7 @@ int tdb_chainunlock(struct tdb_context *tdb, TDB_DATA key)
        unsigned int group, gbits;
 
        gbits = TDB_TOPLEVEL_HASH_BITS - TDB_HASH_GROUP_BITS;
        unsigned int group, gbits;
 
        gbits = TDB_TOPLEVEL_HASH_BITS - TDB_HASH_GROUP_BITS;
-       group = bits(h, 64 - gbits, gbits);
+       group = bits_from(h, 64 - gbits, gbits);
 
        lockstart = hlock_range(group, &locksize);
 
 
        lockstart = hlock_range(group, &locksize);
 
index ae09597ec4eecacaf362f7c9af616103d9857f1f..3a261a4053ec9fb369077664c66c88ed69e484b8 100644 (file)
@@ -552,7 +552,7 @@ int tdb_access_commit(struct tdb_context *tdb, void *p)
 }
 
 static void *tdb_direct(struct tdb_context *tdb, tdb_off_t off, size_t len,
 }
 
 static void *tdb_direct(struct tdb_context *tdb, tdb_off_t off, size_t len,
-                       bool write)
+                       bool write_mode)
 {
        if (unlikely(!tdb->map_ptr))
                return NULL;
 {
        if (unlikely(!tdb->map_ptr))
                return NULL;
@@ -562,10 +562,10 @@ static void *tdb_direct(struct tdb_context *tdb, tdb_off_t off, size_t len,
        return (char *)tdb->map_ptr + off;
 }
 
        return (char *)tdb->map_ptr + off;
 }
 
-void add_stat_(struct tdb_context *tdb, uint64_t *stat, size_t val)
+void add_stat_(struct tdb_context *tdb, uint64_t *s, size_t val)
 {
 {
-       if ((uintptr_t)stat < (uintptr_t)tdb->stats + tdb->stats->size)
-               *stat += val;
+       if ((uintptr_t)s < (uintptr_t)tdb->stats + tdb->stats->size)
+               *s += val;
 }
 
 static const struct tdb_methods io_methods = {
 }
 
 static const struct tdb_methods io_methods = {
index 56d365883030dce6e85961022c7ac3d7f7e694aa..bb9f5cb54eb5fd3e5dc8fb6257899546e046823b 100644 (file)
@@ -38,7 +38,7 @@ static int count_hash(struct tdb_context *tdb,
 static bool summarize(struct tdb_context *tdb,
                      struct tally *hashes,
                      struct tally *ftables,
 static bool summarize(struct tdb_context *tdb,
                      struct tally *hashes,
                      struct tally *ftables,
-                     struct tally *free,
+                     struct tally *fr,
                      struct tally *keys,
                      struct tally *data,
                      struct tally *extra,
                      struct tally *keys,
                      struct tally *data,
                      struct tally *extra,
@@ -69,7 +69,7 @@ static bool summarize(struct tdb_context *tdb,
                        len = sizeof(p->r) + p->r.max_len;
                } else if (frec_magic(&p->f) == TDB_FREE_MAGIC) {
                        len = frec_len(&p->f);
                        len = sizeof(p->r) + p->r.max_len;
                } else if (frec_magic(&p->f) == TDB_FREE_MAGIC) {
                        len = frec_len(&p->f);
-                       tally_add(free, len);
+                       tally_add(fr, len);
                        tally_add(buckets, size_to_bucket(len));
                        len += sizeof(p->u);
                        unc++;
                        tally_add(buckets, size_to_bucket(len));
                        len += sizeof(p->u);
                        unc++;
index ff749aac7ad144e3ed306017a9fa92fcd94feb7f..f887b8b4cee27c7a143732ede894e7d90aa55580 100644 (file)
 
 static bool empty_freetable(struct tdb_context *tdb)
 {
 
 static bool empty_freetable(struct tdb_context *tdb)
 {
-       struct tdb_freetable free;
+       struct tdb_freetable ftab;
        unsigned int i;
 
        /* Now, free table should be completely exhausted in zone 0 */
        unsigned int i;
 
        /* Now, free table should be completely exhausted in zone 0 */
-       if (tdb_read_convert(tdb, tdb->ftable_off, &free, sizeof(free)) != 0)
+       if (tdb_read_convert(tdb, tdb->ftable_off, &ftab, sizeof(ftab)) != 0)
                abort();
 
                abort();
 
-       for (i = 0; i < sizeof(free.buckets)/sizeof(free.buckets[0]); i++) {
-               if (free.buckets[i])
+       for (i = 0; i < sizeof(ftab.buckets)/sizeof(ftab.buckets[0]); i++) {
+               if (ftab.buckets[i])
                        return false;
        }
        return true;
                        return false;
        }
        return true;
index 6e0b1669fcd9fa1e2276282e621856f1f8236c3c..c29c46510cffea170ea9d6f8079433902fb5f29d 100644 (file)
@@ -363,7 +363,7 @@ static int transaction_expand_file(struct tdb_context *tdb, tdb_off_t addition)
 }
 
 static void *transaction_direct(struct tdb_context *tdb, tdb_off_t off,
 }
 
 static void *transaction_direct(struct tdb_context *tdb, tdb_off_t off,
-                               size_t len, bool write)
+                               size_t len, bool write_mode)
 {
        size_t blk = off / getpagesize(), end_blk;
 
 {
        size_t blk = off / getpagesize(), end_blk;
 
@@ -371,7 +371,7 @@ static void *transaction_direct(struct tdb_context *tdb, tdb_off_t off,
        end_blk = (off + len - 1) / getpagesize();
 
        /* Can only do direct if in single block and we've already copied. */
        end_blk = (off + len - 1) / getpagesize();
 
        /* Can only do direct if in single block and we've already copied. */
-       if (write) {
+       if (write_mode) {
                if (blk != end_blk)
                        return NULL;
                if (blk >= tdb->transaction->num_blocks)
                if (blk != end_blk)
                        return NULL;
                if (blk >= tdb->transaction->num_blocks)
@@ -395,7 +395,7 @@ static void *transaction_direct(struct tdb_context *tdb, tdb_off_t off,
                        return NULL;
                blk++;
        }
                        return NULL;
                blk++;
        }
-       return tdb->transaction->io_methods->direct(tdb, off, len, write);
+       return tdb->transaction->io_methods->direct(tdb, off, len, false);
 }
 
 static const struct tdb_methods transaction_methods = {
 }
 
 static const struct tdb_methods transaction_methods = {