Fix assumption that pointers fits in a 'long'
authorBruce Cran <bruce@cran.org.uk>
Mon, 20 Feb 2012 08:34:24 +0000 (09:34 +0100)
committerJens Axboe <axboe@kernel.dk>
Mon, 20 Feb 2012 08:34:24 +0000 (09:34 +0100)
Windows uses LLP64 model so [u]intptr_t is more correct.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
backend.c
hash.h
memalign.c
rbtree.h
smalloc.c

index 6e0e4424d6f6ce31d32ff6cf5d2ca77ba09111c2..eaa6ea77752e9d82feaf968c1aed5c6fdc20778c 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -30,6 +30,7 @@
 #include <locale.h>
 #include <assert.h>
 #include <time.h>
+#include <inttypes.h>
 #include <sys/stat.h>
 #include <sys/wait.h>
 #include <sys/ipc.h>
@@ -67,7 +68,7 @@ int temp_stall_ts;
 unsigned long done_secs = 0;
 
 #define PAGE_ALIGN(buf)        \
-       (char *) (((unsigned long) (buf) + page_mask) & ~page_mask)
+       (char *) (((uintptr_t) (buf) + page_mask) & ~page_mask)
 
 #define JOB_START_TIMEOUT      (5 * 1000)
 
@@ -1179,7 +1180,7 @@ err:
                write_iolog_close(td);
 
        td_set_runstate(td, TD_EXITED);
-       return (void *) (unsigned long) td->error;
+       return (void *) (uintptr_t) td->error;
 }
 
 
@@ -1210,7 +1211,7 @@ static int fork_main(int shmid, int offset)
        td = data + offset * sizeof(struct thread_data);
        ret = thread_main(td);
        shmdt(data);
-       return (int) (unsigned long) ret;
+       return (int) (uintptr_t) ret;
 }
 
 /*
diff --git a/hash.h b/hash.h
index 0c3cdda77be642842337f6fe949da7c24581e661..4b8c6bf0bcc49bd9b1f1b56c38c6e6b6243df22e 100644 (file)
--- a/hash.h
+++ b/hash.h
@@ -58,7 +58,7 @@ static inline unsigned long hash_long(unsigned long val, unsigned int bits)
        
 static inline unsigned long hash_ptr(void *ptr, unsigned int bits)
 {
-       return hash_long((unsigned long)ptr, bits);
+       return hash_long((uintptr_t)ptr, bits);
 }
 
 /*
index 87667b42c35c7bea3f5d4c5d3e3a7a60c8a94539..7a04ffd8c31aa38443034fa300942bb8adf2259e 100644 (file)
@@ -1,5 +1,6 @@
 #include <stdlib.h>
 #include <assert.h>
+#include <inttypes.h>
 
 #include "memalign.h"
 
@@ -8,7 +9,7 @@ struct align_footer {
 };
 
 #define PTR_ALIGN(ptr, mask)   \
-       (char *) (((unsigned long) ((ptr) + (mask)) & ~(mask)))
+       (char *) (((uintptr_t) ((ptr) + (mask)) & ~(mask)))
 
 void *fio_memalign(size_t alignment, size_t size)
 {
@@ -21,7 +22,7 @@ void *fio_memalign(size_t alignment, size_t size)
        if (ptr) {
                ret = PTR_ALIGN(ptr, alignment);
                f = ret + size;
-               f->offset = (unsigned long) ret - (unsigned long) ptr;
+               f->offset = (uintptr_t) ret - (uintptr_t) ptr;
        }
 
        return ret;
index 20306ff1929060d726ce5f76dce9eba51f7e6b54..7563725e51a90e37cff54e81c546ed30b151b28f 100644 (file)
--- a/rbtree.h
+++ b/rbtree.h
@@ -95,10 +95,11 @@ static inline struct page * rb_insert_page_cache(struct inode * inode,
 #define        _LINUX_RBTREE_H
 
 #include <stdlib.h>
+#include <inttypes.h>
 
 struct rb_node
 {
-       unsigned long  rb_parent_color;
+       intptr_t rb_parent_color;
 #define        RB_RED          0
 #define        RB_BLACK        1
        struct rb_node *rb_right;
@@ -121,7 +122,7 @@ struct rb_root
 
 static inline void rb_set_parent(struct rb_node *rb, struct rb_node *p)
 {
-       rb->rb_parent_color = (rb->rb_parent_color & 3) | (unsigned long)p;
+       rb->rb_parent_color = (rb->rb_parent_color & 3) | (uintptr_t)p;
 }
 static inline void rb_set_color(struct rb_node *rb, int color)
 {
@@ -144,7 +145,7 @@ extern struct rb_node *rb_first(struct rb_root *);
 static inline void rb_link_node(struct rb_node * node, struct rb_node * parent,
                                struct rb_node ** rb_link)
 {
-       node->rb_parent_color = (unsigned long )parent;
+       node->rb_parent_color = (uintptr_t)parent;
        node->rb_left = node->rb_right = NULL;
 
        *rb_link = node;
index 0c7c6df7bdd17992a5fa3c8acb6b53a769621009..5ba20047b37676ec8659dffc53dd6459061a5e4d 100644 (file)
--- a/smalloc.c
+++ b/smalloc.c
@@ -8,6 +8,7 @@
 #include <assert.h>
 #include <string.h>
 #include <unistd.h>
+#include <inttypes.h>
 #include <sys/types.h>
 #include <limits.h>
 #include <fcntl.h>
@@ -253,9 +254,9 @@ void scleanup(void)
 #ifdef SMALLOC_REDZONE
 static void *postred_ptr(struct block_hdr *hdr)
 {
-       unsigned long ptr;
+       uintptr_t ptr;
 
-       ptr = (unsigned long) hdr + hdr->size - sizeof(unsigned int);
+       ptr = (uintptr_t) hdr + hdr->size - sizeof(unsigned int);
        ptr = (ptr + int_mask) & ~int_mask;
 
        return (void *) ptr;