Browse Source

alloc: dont clash with libc's fls, avoid void pointer arithmetic

Rusty Russell 15 years ago
parent
commit
e5d378237f
5 changed files with 10 additions and 10 deletions
  1. 4 4
      ccan/alloc/alloc.c
  2. 2 2
      ccan/alloc/bitops.c
  3. 2 2
      ccan/alloc/bitops.h
  4. 1 1
      ccan/alloc/test/run.c
  5. 1 1
      ccan/alloc/tiny.c

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

+ 2 - 2
ccan/alloc/bitops.c

@@ -5,7 +5,7 @@
 #include <ccan/ilog/ilog.h>
 #include <limits.h>
 
-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! */

+ 2 - 2
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 */

+ 1 - 1
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)

+ 1 - 1
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;