From e5d378237fd2c9dd0c710bed9d8f9e1538de6d02 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 22 Mar 2011 12:44:03 +1030 Subject: [PATCH] alloc: dont clash with libc's fls, avoid void pointer arithmetic --- ccan/alloc/alloc.c | 8 ++++---- ccan/alloc/bitops.c | 4 ++-- ccan/alloc/bitops.h | 4 ++-- ccan/alloc/test/run.c | 2 +- ccan/alloc/tiny.c | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/ccan/alloc/alloc.c b/ccan/alloc/alloc.c index 4b3c03ce..181f6302 100644 --- a/ccan/alloc/alloc.c +++ b/ccan/alloc/alloc.c @@ -124,7 +124,7 @@ static unsigned long bucket_to_size(unsigned int bucket) */ static unsigned int size_to_bucket(unsigned long size) { - unsigned int base = fls(size/2); + unsigned int base = afls(size/2); unsigned long overshoot; overshoot = size - (1UL << base); @@ -134,7 +134,7 @@ static unsigned int size_to_bucket(unsigned long size) static unsigned int small_page_bits(unsigned long poolsize) { - return fls(poolsize / MAX_SMALL_PAGES - 1); + return afls(poolsize / MAX_SMALL_PAGES - 1); } static struct page_header *from_pgnum(struct header *head, @@ -313,7 +313,7 @@ static unsigned int find_free_bit(const unsigned long bitmap[]) unsigned int i; for (i = 0; bitmap[i] == -1UL; i++); - return (i*BITS_PER_LONG) + ffsl(~bitmap[i]) - 1; + return (i*BITS_PER_LONG) + affsl(~bitmap[i]) - 1; } /* How many elements can we fit in a page? */ @@ -422,7 +422,7 @@ static void del_large_from_small_free_list(struct header *head, for (i = 0; i < SMALL_PAGES_PER_LARGE_PAGE; i++) { del_from_list(head, &head->small_free_list, - (struct page_header *)((char *)ph + (struct page_header *)((char *)ph + (i << sp_bits)), sp_bits); } diff --git a/ccan/alloc/bitops.c b/ccan/alloc/bitops.c index b408a20f..e1f25f97 100644 --- a/ccan/alloc/bitops.c +++ b/ccan/alloc/bitops.c @@ -5,7 +5,7 @@ #include #include -unsigned int fls(unsigned long val) +unsigned int afls(unsigned long val) { BUILD_ASSERT(sizeof(val) == sizeof(u32) || sizeof(val) == sizeof(u64)); if (sizeof(val) == sizeof(u32)) @@ -15,7 +15,7 @@ unsigned int fls(unsigned long val) } /* FIXME: Move to bitops. */ -unsigned int ffsl(unsigned long val) +unsigned int affsl(unsigned long val) { #if HAVE_BUILTIN_FFSL /* This is significantly faster! */ diff --git a/ccan/alloc/bitops.h b/ccan/alloc/bitops.h index 11ec950e..c6509c31 100644 --- a/ccan/alloc/bitops.h +++ b/ccan/alloc/bitops.h @@ -1,7 +1,7 @@ #ifndef CCAN_ALLOC_BITOPS_H #define CCAN_ALLOC_BITOPS_H -unsigned int fls(unsigned long val); -unsigned int ffsl(unsigned long val); +unsigned int afls(unsigned long val); +unsigned int affsl(unsigned long val); unsigned int popcount(unsigned long val); unsigned long align_up(unsigned long x, unsigned long align); #endif /* CCAN_ALLOC_BITOPS_H */ diff --git a/ccan/alloc/test/run.c b/ccan/alloc/test/run.c index a6d021ff..d5b40c8c 100644 --- a/ccan/alloc/test/run.c +++ b/ccan/alloc/test/run.c @@ -11,7 +11,7 @@ static int addr_cmp(void **a, void **b) { - return (*a) - (*b); + return (char *)(*a) - (char *)(*b); } static bool unique(void *p[], unsigned int num) diff --git a/ccan/alloc/tiny.c b/ccan/alloc/tiny.c index c27c601f..8ab3f7e4 100644 --- a/ccan/alloc/tiny.c +++ b/ccan/alloc/tiny.c @@ -19,7 +19,7 @@ /* Val is usually offset by MIN_BLOCK_SIZE here. */ static unsigned encode_length(unsigned long val) { - unsigned int bits = fls(val); + unsigned int bits = afls(val); /* 5 bits in first byte. */ if (bits <= 5) return 1; -- 2.39.2