]> git.ozlabs.org Git - ccan/commitdiff
alloc: dont clash with libc's fls, avoid void pointer arithmetic
authorRusty Russell <rusty@rustcorp.com.au>
Tue, 22 Mar 2011 02:14:03 +0000 (12:44 +1030)
committerRusty Russell <rusty@rustcorp.com.au>
Tue, 22 Mar 2011 02:14:03 +0000 (12:44 +1030)
ccan/alloc/alloc.c
ccan/alloc/bitops.c
ccan/alloc/bitops.h
ccan/alloc/test/run.c
ccan/alloc/tiny.c

index 4b3c03cea47c3ea1910460105b9939fcb545d00e..181f6302f458540d6549560954d41a76e204b2aa 100644 (file)
@@ -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);
        }
index b408a20f0e579d8ce83228f1fc60a79a6f7e844f..e1f25f974e7ec36bf938741f561e366b83824039 100644 (file)
@@ -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! */
index 11ec950eff9df92e7bcaed8c09d70bce417b83b0..c6509c3182a5509b72f0cb6544c019e33b2a9bce 100644 (file)
@@ -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 */
index a6d021ff9e5dc87b3d1f25cf821fc15215031208..d5b40c8c3708d13a1c138f902d596ba1d8f40691 100644 (file)
@@ -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)
index c27c601f5aa1fb59b448ff0dc000af322a5a8bd6..8ab3f7e4a9d758fc345ff60bc4bae85848c73d5f 100644 (file)
@@ -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;