Skip to contentSkip to conversation

hw/qxl.c: Fix compilation failures on 32 bit hosts

PATCH In review Peter Maydell 3 participants 5 messages Mar 16, 2012 – Mar 19, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/qxl.c: Fix compilation failures on 32 bit hosts

Fix compilation failures on 32 bit hosts (cast from pointer to integer of different size; %ld expects 'long int' not uint64_t).

---
 hw/qxl.c |   16 ++++++++--------
 1 files changed, 8 insertions(+), 8 deletions(-)
hw/qxl.c +8 -8
index e17b0e3..47dc383 100644
@@ -149,7 +149,7 @@ void qxl_spice_update_area(PCIQXLDevice *qxl, uint32_t surface_id,
     } else {
         assert(cookie != NULL);
         spice_qxl_update_area_async(&qxl->ssd.qxl, surface_id, area,
-                                    clear_dirty_region, (uint64_t)cookie);
+                                    clear_dirty_region, (uintptr_t)cookie);
     }
 }
 
@@ -171,7 +171,7 @@ static void qxl_spice_destroy_surface_wait(PCIQXLDevice *qxl, uint32_t id,
         cookie = qxl_cookie_new(QXL_COOKIE_TYPE_IO,
                                 QXL_IO_DESTROY_SURFACE_ASYNC);
         cookie->u.surface_id = id;
-        spice_qxl_destroy_surface_async(&qxl->ssd.qxl, id, (uint64_t)cookie);
+        spice_qxl_destroy_surface_async(&qxl->ssd.qxl, id, (uintptr_t)cookie);
     } else {
         qxl->ssd.worker->destroy_surface_wait(qxl->ssd.worker, id);
         qxl_spice_destroy_surface_wait_complete(qxl, id);
@@ -181,8 +181,8 @@ static void qxl_spice_destroy_surface_wait(PCIQXLDevice *qxl, uint32_t id,
 static void qxl_spice_flush_surfaces_async(PCIQXLDevice *qxl)
 {
     spice_qxl_flush_surfaces_async(&qxl->ssd.qxl,
-        (uint64_t)qxl_cookie_new(QXL_COOKIE_TYPE_IO,
-                                 QXL_IO_FLUSH_SURFACES_ASYNC));
+        (uintptr_t)qxl_cookie_new(QXL_COOKIE_TYPE_IO,
+                                  QXL_IO_FLUSH_SURFACES_ASYNC));
 }
 
 void qxl_spice_loadvm_commands(PCIQXLDevice *qxl, struct QXLCommandExt *ext,
@@ -213,8 +213,8 @@ static void qxl_spice_destroy_surfaces(PCIQXLDevice *qxl, qxl_async_io async)
 {
     if (async) {
         spice_qxl_destroy_surfaces_async(&qxl->ssd.qxl,
-                (uint64_t)qxl_cookie_new(QXL_COOKIE_TYPE_IO,
-                                         QXL_IO_DESTROY_ALL_SURFACES_ASYNC));
+                (uintptr_t)qxl_cookie_new(QXL_COOKIE_TYPE_IO,
+                                          QXL_IO_DESTROY_ALL_SURFACES_ASYNC));
     } else {
         qxl->ssd.worker->destroy_surfaces(qxl->ssd.worker);
         qxl_spice_destroy_surfaces_complete(qxl);
@@ -743,7 +743,7 @@ static void interface_async_complete_io(PCIQXLDevice *qxl, QXLCookie *cookie)
     }
     if (cookie && current_async != cookie->io) {
         fprintf(stderr,
-                "qxl: %s: error: current_async = %d != %ld = cookie->io\n",
+                "qxl: %s: error: current_async = %d != %" PRId64 " = cookie->io\n",
                 __func__, current_async, cookie->io);
     }
     switch (current_async) {
@@ -812,7 +812,7 @@ static void interface_update_area_complete(QXLInstance *sin,
 static void interface_async_complete(QXLInstance *sin, uint64_t cookie_token)
 {
     PCIQXLDevice *qxl = container_of(sin, PCIQXLDevice, ssd.qxl);
-    QXLCookie *cookie = (QXLCookie *)cookie_token;
+    QXLCookie *cookie = (QXLCookie *)(uintptr_t)cookie_token;
 
     switch (cookie->type) {
     case QXL_COOKIE_TYPE_IO:
Signature · 1 line
1.7.9
Reviewed-by on v1 1/1
#1 lore raw

Am 16.03.2012 14:50, schrieb Peter Maydell:

Quoted 54 lines

Fix compilation failures on 32 bit hosts (cast from pointer to integer of different size; %ld expects 'long int' not uint64_t).

---
  hw/qxl.c |   16 ++++++++--------
  1 files changed, 8 insertions(+), 8 deletions(-)
hw/qxl.c +6 -6
index e17b0e3..47dc383 100644
@@ -149,7 +149,7 @@ void qxl_spice_update_area(PCIQXLDevice *qxl, uint32_t surface_id,
      } else {
          assert(cookie != NULL);
          spice_qxl_update_area_async(&qxl->ssd.qxl, surface_id, area,
-                                    clear_dirty_region, (uint64_t)cookie);
+                                    clear_dirty_region, (uintptr_t)cookie);
      }
  }
 
@@ -171,7 +171,7 @@ static void qxl_spice_destroy_surface_wait(PCIQXLDevice *qxl, uint32_t id,
          cookie = qxl_cookie_new(QXL_COOKIE_TYPE_IO,
                                  QXL_IO_DESTROY_SURFACE_ASYNC);
          cookie->u.surface_id = id;
-        spice_qxl_destroy_surface_async(&qxl->ssd.qxl, id, (uint64_t)cookie);
+        spice_qxl_destroy_surface_async(&qxl->ssd.qxl, id, (uintptr_t)cookie);
      } else {
          qxl->ssd.worker->destroy_surface_wait(qxl->ssd.worker, id);
          qxl_spice_destroy_surface_wait_complete(qxl, id);
@@ -181,8 +181,8 @@ static void qxl_spice_destroy_surface_wait(PCIQXLDevice *qxl, uint32_t id,
  static void qxl_spice_flush_surfaces_async(PCIQXLDevice *qxl)
  {
      spice_qxl_flush_surfaces_async(&qxl->ssd.qxl,
-        (uint64_t)qxl_cookie_new(QXL_COOKIE_TYPE_IO,
-                                 QXL_IO_FLUSH_SURFACES_ASYNC));
+        (uintptr_t)qxl_cookie_new(QXL_COOKIE_TYPE_IO,
+                                  QXL_IO_FLUSH_SURFACES_ASYNC));
  }
 
  void qxl_spice_loadvm_commands(PCIQXLDevice *qxl, struct QXLCommandExt *ext,
@@ -213,8 +213,8 @@ static void qxl_spice_destroy_surfaces(PCIQXLDevice *qxl, qxl_async_io async)
  {
      if (async) {
          spice_qxl_destroy_surfaces_async(&qxl->ssd.qxl,
-                (uint64_t)qxl_cookie_new(QXL_COOKIE_TYPE_IO,
-                                         QXL_IO_DESTROY_ALL_SURFACES_ASYNC));
+                (uintptr_t)qxl_cookie_new(QXL_COOKIE_TYPE_IO,
+                                          QXL_IO_DESTROY_ALL_SURFACES_ASYNC));
      } else {
          qxl->ssd.worker->destroy_surfaces(qxl->ssd.worker);
          qxl_spice_destroy_surfaces_complete(qxl);

hw/qxl.c static void interface_async_complete_io(PCIQXLDevice *qxl, QXLCookie *cookie) · line 748

Quoted 7 lines
hw/qxl.c +1 -1
@@ -743,7 +743,7 @@ static void interface_async_complete_io(PCIQXLDevice *qxl, QXLCookie *cookie)
      }
      if (cookie&&  current_async != cookie->io) {
          fprintf(stderr,
-                "qxl: %s: error: current_async = %d != %ld = cookie->io\n",
+                "qxl: %s: error: current_async = %d != %" PRId64 " = cookie->io\n",
                  __func__, current_async, cookie->io);
 

current_async is uint32_t, so maybe you can also replace %d by %" PRIu32 ". Is io unsigned (I don't have the headers, but think it is)? Then PRIu64 would be better.

With these modifications you may add

Cheers,
Stefan

Quoted 12 lines
hw/qxl.c +0 -0
      }
      switch (current_async) {
hw/qxl.c +1 -1
@@ -812,7 +812,7 @@ static void interface_update_area_complete(QXLInstance *sin,
  static void interface_async_complete(QXLInstance *sin, uint64_t cookie_token)
  {
      PCIQXLDevice *qxl = container_of(sin, PCIQXLDevice, ssd.qxl);
-    QXLCookie *cookie = (QXLCookie *)cookie_token;
+    QXLCookie *cookie = (QXLCookie *)(uintptr_t)cookie_token;
 
      switch (cookie->type) {
      case QXL_COOKIE_TYPE_IO:
#2 lore raw
Quoted 9 lines · Stefan Weil
Quoted 7 lines

         fprintf(stderr,
-                "qxl: %s: error: current_async = %d != %ld = cookie->io\n",
+                "qxl: %s: error: current_async = %d != %" PRId64 " = cookie->io\n",
                 __func__, current_async, cookie->io);

Quoted 3 lines

current_async is uint32_t,  so maybe you can also replace %d by %" PRIu32 ". Is io unsigned (I don't have the headers, but think it is)? Then PRIu64 would be better.

Yes, cookie->io is uint64_t, but I just want to fix compile warnings, not make functional changes (it might be a semantically signed value that we happen to be carrying in an unsigned type, for instance).

I agree that we could use PRId32 in theory, but on the other hand it doesn't cause any compiler warnings and we also use %d for it elsewhere in the function. I'd rather leave that kind of cleanup for somebody who wants to deal with it more systematically.

-- PMM

#4 lore raw
Quoted 5 lines · Gerd Hoffmann
Quoted 2 lines · Peter Maydell

Fix compilation failures on 32 bit hosts (cast from pointer to integer of different size; %ld expects 'long int' not uint64_t).

Oops, scratch that, should have been "added to spice patch queue".

cheers,
Gerd