From: Rusty Russell Date: Thu, 24 Feb 2011 05:33:46 +0000 (+1030) Subject: tdb2: make tdb2 compile clean under -Wshadow. X-Git-Url: https://git.ozlabs.org/?p=ccan;a=commitdiff_plain;h=5eaf46e9a0d38c371b50d5dd3a433fc721c1c4dc tdb2: make tdb2 compile clean under -Wshadow. This isn't a general requirement for CCAN modules, but Samba uses it, so make sure tdb2 doesn't upset it. --- diff --git a/ccan/tdb2/check.c b/ccan/tdb2/check.c index d614d4cb..5a238a1c 100644 --- a/ccan/tdb2/check.c +++ b/ccan/tdb2/check.c @@ -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, - tdb_off_t free[], + tdb_off_t fr[], 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 */ - 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, @@ -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, - tdb_off_t **free, size_t *num_free, + tdb_off_t **fr, size_t *num_free, 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 - && !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 @@ -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) { - 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) @@ -676,13 +676,13 @@ int tdb_check(struct tdb_context *tdb, 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; - 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++; diff --git a/ccan/tdb2/hash.c b/ccan/tdb2/hash.c index 18f6b172..e1b1dfe3 100644 --- a/ccan/tdb2/hash.c +++ b/ccan/tdb2/hash.c @@ -64,7 +64,7 @@ uint64_t hash_record(struct tdb_context *tdb, tdb_off_t off) } /* 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); @@ -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; - 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, @@ -119,8 +119,8 @@ static bool match(struct tdb_context *tdb, } /* 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; @@ -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 - | ((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); @@ -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_off_t hlock_start, hlock_range, off; + tdb_off_t hl_start, hl_range, off; 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); - 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; @@ -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, - hlock_start, hlock_range, - ltype); + hl_start, hl_range, ltype); 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); } - tdb_unlock_hashes(tdb, hlock_start, hlock_range, ltype); + tdb_unlock_hashes(tdb, hl_start, hl_range, ltype); 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 @@ -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; - group = bits(h, 64 - gbits, gbits); + group = bits_from(h, 64 - gbits, gbits); 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; - group = bits(h, 64 - gbits, gbits); + group = bits_from(h, 64 - gbits, gbits); lockstart = hlock_range(group, &locksize); diff --git a/ccan/tdb2/io.c b/ccan/tdb2/io.c index ae09597e..3a261a40 100644 --- a/ccan/tdb2/io.c +++ b/ccan/tdb2/io.c @@ -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, - bool write) + bool write_mode) { 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; } -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 = { diff --git a/ccan/tdb2/summary.c b/ccan/tdb2/summary.c index 56d36588..bb9f5cb5 100644 --- a/ccan/tdb2/summary.c +++ b/ccan/tdb2/summary.c @@ -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, - struct tally *free, + struct tally *fr, 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); - tally_add(free, len); + tally_add(fr, len); tally_add(buckets, size_to_bucket(len)); len += sizeof(p->u); unc++; diff --git a/ccan/tdb2/test/run-30-exhaust-before-expand.c b/ccan/tdb2/test/run-30-exhaust-before-expand.c index ff749aac..f887b8b4 100644 --- a/ccan/tdb2/test/run-30-exhaust-before-expand.c +++ b/ccan/tdb2/test/run-30-exhaust-before-expand.c @@ -11,15 +11,15 @@ 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 */ - 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(); - 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; diff --git a/ccan/tdb2/transaction.c b/ccan/tdb2/transaction.c index 6e0b1669..c29c4651 100644 --- a/ccan/tdb2/transaction.c +++ b/ccan/tdb2/transaction.c @@ -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, - size_t len, bool write) + size_t len, bool write_mode) { 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. */ - if (write) { + if (write_mode) { 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 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 = {