[Spice-devel] [PATCH 1/6] mingw: use uintptr_t when converting a pointer to an int

Christophe Fergeau cfergeau at redhat.com
Wed Feb 29 10:01:54 PST 2012


win64 uses 32 bit long, so we cannot use a long to hold a 64 bit
pointer. Thankfully, there's a [u]intptr_t type available exactly
for these uses.
---
 client/canvas.cpp     |    2 +-
 client/cursor.cpp     |    2 +-
 common/draw.h         |    4 ++--
 common/pixman_utils.c |    6 +++---
 4 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/client/canvas.cpp b/client/canvas.cpp
index 139b663..0986d47 100644
--- a/client/canvas.cpp
+++ b/client/canvas.cpp
@@ -70,7 +70,7 @@ void Canvas::clear()
 
 void Canvas::begin_draw(SpiceMsgDisplayBase& base, int size, size_t min_size)
 {
-    _base = (unsigned long)&base;
+    _base = (uintptr_t)&base;
 }
 
 void Canvas::draw_fill(SpiceMsgDisplayDrawFill& fill, int size)
diff --git a/client/cursor.cpp b/client/cursor.cpp
index e9e3006..0584b88 100644
--- a/client/cursor.cpp
+++ b/client/cursor.cpp
@@ -64,7 +64,7 @@ CursorData::CursorData(SpiceCursor& cursor, int data_size)
     }
 
     if (data_size < expected_size) {
-        THROW("access violation 0x%lx %u", (unsigned long)cursor.data, expected_size);
+        THROW("access violation 0x%lx %u", (uintptr_t)cursor.data, expected_size);
     }
     _data = new uint8_t[expected_size];
     memcpy(_data, cursor.data, expected_size);
diff --git a/common/draw.h b/common/draw.h
index 793169f..8b1206d 100644
--- a/common/draw.h
+++ b/common/draw.h
@@ -39,8 +39,8 @@
 extern "C" {
 #endif
 
-#define SPICE_GET_ADDRESS(addr) ((void *)(unsigned long)(addr))
-#define SPICE_SET_ADDRESS(addr, val) ((addr) = (unsigned long)(val))
+#define SPICE_GET_ADDRESS(addr) ((void *)(uintptr_t)(addr))
+#define SPICE_SET_ADDRESS(addr, val) ((addr) = (uintptr_t)(val))
 
 typedef int32_t SPICE_FIXED28_4;
 
diff --git a/common/pixman_utils.c b/common/pixman_utils.c
index c04b01f..1136aa7 100644
--- a/common/pixman_utils.c
+++ b/common/pixman_utils.c
@@ -243,19 +243,19 @@ void spice_pixman_fill_rect(pixman_image_t *dest,
         byte_line += stride;
         w = byte_width;
 
-        while (w >= 1 && ((unsigned long)d & 1)) {
+        while (w >= 1 && ((uintptr_t)d & 1)) {
             *(uint8_t *)d = (value & 0xff);
             w--;
             d++;
         }
 
-        while (w >= 2 && ((unsigned long)d & 3)) {
+        while (w >= 2 && ((uintptr_t)d & 3)) {
             *(uint16_t *)d = value;
             w -= 2;
             d += 2;
         }
 
-        while (w >= 4 && ((unsigned long)d & 7)) {
+        while (w >= 4 && ((uintptr_t)d & 7)) {
             *(uint32_t *)d = value;
 
             w -= 4;
-- 
1.7.7.6



More information about the Spice-devel mailing list