[Spice-commits] server/char-device.c server/cursor-channel.c server/dcc-encoders.c server/dcc-send.c server/dcc.c server/display-channel.c server/display-channel.h server/image-cache.c server/inputs-channel.c server/main-channel-client.c server/pixmap-cache.c server/red-channel.c server/red-common.h server/red-record-qxl.c server/reds.c server/smartcard.c server/spicevmc.c server/stream.c server/tree.h

Frediano Ziglio fziglio at kemper.freedesktop.org
Tue May 24 17:02:00 UTC 2016


 server/char-device.c         |    2 +-
 server/cursor-channel.c      |    6 +++---
 server/dcc-encoders.c        |    2 +-
 server/dcc-send.c            |   14 +++++++-------
 server/dcc.c                 |    2 +-
 server/display-channel.c     |    4 ++--
 server/display-channel.h     |    2 +-
 server/image-cache.c         |    4 ++--
 server/inputs-channel.c      |    6 +++---
 server/main-channel-client.c |   22 +++++++++++-----------
 server/pixmap-cache.c        |    2 +-
 server/red-channel.c         |    4 ++--
 server/red-common.h          |    4 ++++
 server/red-record-qxl.c      |    2 +-
 server/reds.c                |    2 +-
 server/smartcard.c           |    6 +++---
 server/spicevmc.c            |    6 +++---
 server/stream.c              |    6 +++---
 server/tree.h                |    6 +++---
 19 files changed, 53 insertions(+), 49 deletions(-)

New commits:
commit 02adcf354eeec6a6a0400443d6d79d8f61ff0b8e
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Tue May 24 10:51:40 2016 +0100

    Introduce SPICE_UPCAST macro
    
    This was proposed by Christophe as improvement over some typesafe
    patches.
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Christophe Fergeau <cfergeau at redhat.com>

diff --git a/server/char-device.c b/server/char-device.c
index 4a6e4c8..cb35aa2 100644
--- a/server/char-device.c
+++ b/server/char-device.c
@@ -1002,7 +1002,7 @@ SpiceServer* red_char_device_get_server(RedCharDevice *dev)
 
 SpiceCharDeviceInterface *spice_char_device_get_interface(SpiceCharDeviceInstance *instance)
 {
-   return SPICE_CONTAINEROF(instance->base.sif, SpiceCharDeviceInterface, base);
+   return SPICE_UPCAST(SpiceCharDeviceInterface, instance->base.sif);
 }
 
 
diff --git a/server/cursor-channel.c b/server/cursor-channel.c
index 23a8cb8..2869b11 100644
--- a/server/cursor-channel.c
+++ b/server/cursor-channel.c
@@ -208,7 +208,7 @@ static void cursor_pipe_item_free(RedPipeItem *base)
 {
     spice_return_if_fail(base);
 
-    RedCursorPipeItem *pipe_item = SPICE_CONTAINEROF(base, RedCursorPipeItem, base);
+    RedCursorPipeItem *pipe_item = SPICE_UPCAST(RedCursorPipeItem, base);
 
     spice_assert(!red_pipe_item_is_linked(&pipe_item->base));
 
@@ -318,13 +318,13 @@ static void cursor_channel_send_item(RedChannelClient *rcc, RedPipeItem *pipe_it
 
     switch (pipe_item->type) {
     case RED_PIPE_ITEM_TYPE_CURSOR:
-        cursor_marshall(rcc, m, SPICE_CONTAINEROF(pipe_item, RedCursorPipeItem, base));
+        cursor_marshall(rcc, m, SPICE_UPCAST(RedCursorPipeItem, pipe_item));
         break;
     case RED_PIPE_ITEM_TYPE_INVAL_ONE:
         red_marshall_inval(rcc, m, SPICE_CONTAINEROF(pipe_item, RedCacheItem, u.pipe_data));
         break;
     case RED_PIPE_ITEM_TYPE_VERB:
-        red_marshall_verb(rcc, SPICE_CONTAINEROF(pipe_item, RedVerbItem, base));
+        red_marshall_verb(rcc, SPICE_UPCAST(RedVerbItem, pipe_item));
         break;
     case RED_PIPE_ITEM_TYPE_CURSOR_INIT:
         red_reset_cursor_cache(rcc);
diff --git a/server/dcc-encoders.c b/server/dcc-encoders.c
index 65f5a17..e20a645 100644
--- a/server/dcc-encoders.c
+++ b/server/dcc-encoders.c
@@ -624,7 +624,7 @@ static GlzSharedDictionary *find_glz_dictionary(RedClient *client, uint8_t dict_
 
     now = &glz_dictionary_list;
     while ((now = ring_next(&glz_dictionary_list, now))) {
-        GlzSharedDictionary *dict = SPICE_CONTAINEROF(now, GlzSharedDictionary, base);
+        GlzSharedDictionary *dict = SPICE_UPCAST(GlzSharedDictionary, now);
         if ((dict->client == client) && (dict->id == dict_id)) {
             ret = dict;
             break;
diff --git a/server/dcc-send.c b/server/dcc-send.c
index 193396a..2b8da3d 100644
--- a/server/dcc-send.c
+++ b/server/dcc-send.c
@@ -2326,7 +2326,7 @@ static void marshall_gl_draw(RedChannelClient *rcc,
                              SpiceMarshaller *m,
                              RedPipeItem *item)
 {
-    RedGlDrawItem *p = SPICE_CONTAINEROF(item, RedGlDrawItem, base);
+    RedGlDrawItem *p = SPICE_UPCAST(RedGlDrawItem, item);
 
     red_channel_client_init_send_data(rcc, SPICE_MSG_DISPLAY_GL_DRAW, NULL);
     spice_marshall_msg_display_gl_draw(m, &p->draw);
@@ -2383,29 +2383,29 @@ void dcc_send_item(RedChannelClient *rcc, RedPipeItem *pipe_item)
         marshall_inval_palette(rcc, m, SPICE_CONTAINEROF(pipe_item, RedCacheItem, u.pipe_data));
         break;
     case RED_PIPE_ITEM_TYPE_STREAM_CREATE: {
-        StreamCreateDestroyItem *item = SPICE_CONTAINEROF(pipe_item, StreamCreateDestroyItem, base);
+        StreamCreateDestroyItem *item = SPICE_UPCAST(StreamCreateDestroyItem, pipe_item);
         marshall_stream_start(rcc, m, item->agent);
         break;
     }
     case RED_PIPE_ITEM_TYPE_STREAM_CLIP:
-        marshall_stream_clip(rcc, m, SPICE_CONTAINEROF(pipe_item, RedStreamClipItem, base));
+        marshall_stream_clip(rcc, m, SPICE_UPCAST(RedStreamClipItem, pipe_item));
         break;
     case RED_PIPE_ITEM_TYPE_STREAM_DESTROY: {
-        StreamCreateDestroyItem *item = SPICE_CONTAINEROF(pipe_item, StreamCreateDestroyItem, base);
+        StreamCreateDestroyItem *item = SPICE_UPCAST(StreamCreateDestroyItem, pipe_item);
         marshall_stream_end(rcc, m, item->agent);
         break;
     }
     case RED_PIPE_ITEM_TYPE_UPGRADE:
-        marshall_upgrade(rcc, m, SPICE_CONTAINEROF(pipe_item, RedUpgradeItem, base));
+        marshall_upgrade(rcc, m, SPICE_UPCAST(RedUpgradeItem, pipe_item));
         break;
     case RED_PIPE_ITEM_TYPE_VERB:
-        red_marshall_verb(rcc, SPICE_CONTAINEROF(pipe_item, RedVerbItem, base));
+        red_marshall_verb(rcc, SPICE_UPCAST(RedVerbItem, pipe_item));
         break;
     case RED_PIPE_ITEM_TYPE_MIGRATE_DATA:
         display_channel_marshall_migrate_data(rcc, m);
         break;
     case RED_PIPE_ITEM_TYPE_IMAGE:
-        red_marshall_image(rcc, m, SPICE_CONTAINEROF(pipe_item, RedImageItem, base));
+        red_marshall_image(rcc, m, SPICE_UPCAST(RedImageItem, pipe_item));
         break;
     case RED_PIPE_ITEM_TYPE_PIXMAP_SYNC:
         display_channel_marshall_pixmap_sync(rcc, m);
diff --git a/server/dcc.c b/server/dcc.c
index 9013626..ef43a3c 100644
--- a/server/dcc.c
+++ b/server/dcc.c
@@ -87,7 +87,7 @@ int dcc_clear_surface_drawables_from_pipe(DisplayChannelClient *dcc, int surface
             dpi = SPICE_CONTAINEROF(item, RedDrawablePipeItem, dpi_pipe_item);
             drawable = dpi->drawable;
         } else if (item->type == RED_PIPE_ITEM_TYPE_UPGRADE) {
-            drawable = SPICE_CONTAINEROF(item, RedUpgradeItem, base)->drawable;
+            drawable = SPICE_UPCAST(RedUpgradeItem, item)->drawable;
         } else {
             continue;
         }
diff --git a/server/display-channel.c b/server/display-channel.c
index b970c9b..6460f57 100644
--- a/server/display-channel.c
+++ b/server/display-channel.c
@@ -369,7 +369,7 @@ static void drawable_remove_from_pipes(Drawable *drawable)
     RingItem *item, *next;
 
     RING_FOREACH_SAFE(item, next, &drawable->pipes) {
-        dpi = SPICE_CONTAINEROF(item, RedDrawablePipeItem, base);
+        dpi = SPICE_UPCAST(RedDrawablePipeItem, item);
         if (red_pipe_item_is_linked(&dpi->dpi_pipe_item)) {
             red_channel_client_pipe_remove_and_release(RED_CHANNEL_CLIENT(dpi->dcc),
                                                        &dpi->dpi_pipe_item);
@@ -480,7 +480,7 @@ static int current_add_equal(DisplayChannel *display, DrawItem *item, TreeItem *
             while (worker_ring_item) {
                 dcc = SPICE_CONTAINEROF(worker_ring_item, DisplayChannelClient,
                                         common.base.channel_link);
-                dpi = SPICE_CONTAINEROF(dpi_ring_item, RedDrawablePipeItem, base);
+                dpi = SPICE_UPCAST(RedDrawablePipeItem, dpi_ring_item);
                 while (worker_ring_item && (!dpi || dcc != dpi->dcc)) {
                     dcc_prepend_drawable(dcc, drawable);
                     worker_ring_item = ring_next(&RED_CHANNEL(display)->clients,
diff --git a/server/display-channel.h b/server/display-channel.h
index 4eb78c5..5aa13c1 100644
--- a/server/display-channel.h
+++ b/server/display-channel.h
@@ -84,7 +84,7 @@ struct Drawable {
 
 void drawable_unref (Drawable *drawable);
 
-#define LINK_TO_DPI(ptr) SPICE_CONTAINEROF((ptr), RedDrawablePipeItem, base)
+#define LINK_TO_DPI(ptr) SPICE_UPCAST(RedDrawablePipeItem, (ptr))
 #define DRAWABLE_FOREACH_DPI_SAFE(drawable, link, next, dpi)            \
     SAFE_FOREACH(link, next, drawable,  &(drawable)->pipes, dpi, LINK_TO_DPI(link))
 
diff --git a/server/image-cache.c b/server/image-cache.c
index 8fb090f..ab10880 100644
--- a/server/image-cache.c
+++ b/server/image-cache.c
@@ -74,7 +74,7 @@ static void image_cache_remove(ImageCache *cache, ImageCacheItem *item)
 
 static void image_cache_put(SpiceImageCache *spice_cache, uint64_t id, pixman_image_t *image)
 {
-    ImageCache *cache = SPICE_CONTAINEROF(spice_cache, ImageCache, base);
+    ImageCache *cache = SPICE_UPCAST(ImageCache, spice_cache);
     ImageCacheItem *item;
 
 #ifndef IMAGE_CACHE_AGE
@@ -104,7 +104,7 @@ static void image_cache_put(SpiceImageCache *spice_cache, uint64_t id, pixman_im
 
 static pixman_image_t *image_cache_get(SpiceImageCache *spice_cache, uint64_t id)
 {
-    ImageCache *cache = SPICE_CONTAINEROF(spice_cache, ImageCache,base);
+    ImageCache *cache = SPICE_UPCAST(ImageCache, spice_cache);
 
     ImageCacheItem *item = image_cache_find(cache, id);
     if (!item) {
diff --git a/server/inputs-channel.c b/server/inputs-channel.c
index 197823d..eb07a6f 100644
--- a/server/inputs-channel.c
+++ b/server/inputs-channel.c
@@ -149,7 +149,7 @@ void inputs_channel_set_tablet_logical_size(InputsChannel *inputs, int x_res, in
 {
     SpiceTabletInterface *sif;
 
-    sif = SPICE_CONTAINEROF(inputs->tablet->base.sif, SpiceTabletInterface, base);
+    sif = SPICE_UPCAST(SpiceTabletInterface, inputs->tablet->base.sif);
     sif->set_logical_size(inputs->tablet, x_res, y_res);
 }
 
@@ -265,7 +265,7 @@ static void inputs_channel_send_item(RedChannelClient *rcc, RedPipeItem *base)
 
             red_channel_client_init_send_data(rcc, SPICE_MSG_INPUTS_KEY_MODIFIERS, base);
             key_modifiers.modifiers =
-                SPICE_CONTAINEROF(base, RedKeyModifiersPipeItem, base)->modifiers;
+                SPICE_UPCAST(RedKeyModifiersPipeItem, base)->modifiers;
             spice_marshall_msg_inputs_key_modifiers(m, &key_modifiers);
             break;
         }
@@ -275,7 +275,7 @@ static void inputs_channel_send_item(RedChannelClient *rcc, RedPipeItem *base)
 
             red_channel_client_init_send_data(rcc, SPICE_MSG_INPUTS_INIT, base);
             inputs_init.keyboard_modifiers =
-                SPICE_CONTAINEROF(base, RedInputsInitPipeItem, base)->modifiers;
+                SPICE_UPCAST(RedInputsInitPipeItem, base)->modifiers;
             spice_marshall_msg_inputs_init(m, &inputs_init);
             break;
         }
diff --git a/server/main-channel-client.c b/server/main-channel-client.c
index 6a314b6..1e3c443 100644
--- a/server/main-channel-client.c
+++ b/server/main-channel-client.c
@@ -111,7 +111,7 @@ static int main_channel_client_push_ping(MainChannelClient *mcc, int size);
 
 static void main_notify_item_free(RedPipeItem *base)
 {
-    RedNotifyPipeItem *data = SPICE_CONTAINEROF(base, RedNotifyPipeItem, base);
+    RedNotifyPipeItem *data = SPICE_UPCAST(RedNotifyPipeItem, base);
     free(data->msg);
     free(data);
 }
@@ -183,7 +183,7 @@ void main_channel_client_push_agent_tokens(MainChannelClient *mcc, uint32_t num_
 
 static void main_agent_data_item_free(RedPipeItem *base)
 {
-    RedAgentDataPipeItem *item = SPICE_CONTAINEROF(base, RedAgentDataPipeItem, base);
+    RedAgentDataPipeItem *item = SPICE_UPCAST(RedAgentDataPipeItem, base);
     item->free_data(item->data, item->opaque);
     free(item);
 }
@@ -829,12 +829,12 @@ void main_channel_client_send_item(RedChannelClient *rcc, RedPipeItem *base)
             break;
         case RED_PIPE_ITEM_TYPE_MAIN_PING:
             main_channel_marshall_ping(rcc, m,
-                SPICE_CONTAINEROF(base, RedPingPipeItem, base));
+                SPICE_UPCAST(RedPingPipeItem, base));
             break;
         case RED_PIPE_ITEM_TYPE_MAIN_MOUSE_MODE:
             {
                 RedMouseModePipeItem *item =
-                    SPICE_CONTAINEROF(base, RedMouseModePipeItem, base);
+                    SPICE_UPCAST(RedMouseModePipeItem, base);
                 main_channel_marshall_mouse_mode(rcc, m, item);
                 break;
             }
@@ -843,11 +843,11 @@ void main_channel_client_send_item(RedChannelClient *rcc, RedPipeItem *base)
             break;
         case RED_PIPE_ITEM_TYPE_MAIN_AGENT_TOKEN:
             main_channel_marshall_tokens(rcc, m,
-                SPICE_CONTAINEROF(base, RedTokensPipeItem, base));
+                SPICE_UPCAST(RedTokensPipeItem, base));
             break;
         case RED_PIPE_ITEM_TYPE_MAIN_AGENT_DATA:
             main_channel_marshall_agent_data(rcc, m,
-                SPICE_CONTAINEROF(base, RedAgentDataPipeItem, base));
+                SPICE_UPCAST(RedAgentDataPipeItem, base));
             break;
         case RED_PIPE_ITEM_TYPE_MAIN_MIGRATE_DATA:
             main_channel_marshall_migrate_data_item(rcc, m, base);
@@ -855,11 +855,11 @@ void main_channel_client_send_item(RedChannelClient *rcc, RedPipeItem *base)
         case RED_PIPE_ITEM_TYPE_MAIN_INIT:
             mcc->init_sent = TRUE;
             main_channel_marshall_init(rcc, m,
-                SPICE_CONTAINEROF(base, RedInitPipeItem, base));
+                SPICE_UPCAST(RedInitPipeItem, base));
             break;
         case RED_PIPE_ITEM_TYPE_MAIN_NOTIFY:
             main_channel_marshall_notify(rcc, m,
-                SPICE_CONTAINEROF(base, RedNotifyPipeItem, base));
+                SPICE_UPCAST(RedNotifyPipeItem, base));
             break;
         case RED_PIPE_ITEM_TYPE_MAIN_MIGRATE_BEGIN:
             main_channel_marshall_migrate_begin(m, rcc, base);
@@ -869,18 +869,18 @@ void main_channel_client_send_item(RedChannelClient *rcc, RedPipeItem *base)
             break;
         case RED_PIPE_ITEM_TYPE_MAIN_MULTI_MEDIA_TIME:
             main_channel_marshall_multi_media_time(rcc, m,
-                SPICE_CONTAINEROF(base, RedMultiMediaTimePipeItem, base));
+                SPICE_UPCAST(RedMultiMediaTimePipeItem, base));
             break;
         case RED_PIPE_ITEM_TYPE_MAIN_MIGRATE_SWITCH_HOST:
             main_channel_marshall_migrate_switch(m, rcc, base);
             break;
         case RED_PIPE_ITEM_TYPE_MAIN_NAME:
             red_channel_client_init_send_data(rcc, SPICE_MSG_MAIN_NAME, base);
-            spice_marshall_msg_main_name(m, &SPICE_CONTAINEROF(base, RedNamePipeItem, base)->msg);
+            spice_marshall_msg_main_name(m, &SPICE_UPCAST(RedNamePipeItem, base)->msg);
             break;
         case RED_PIPE_ITEM_TYPE_MAIN_UUID:
             red_channel_client_init_send_data(rcc, SPICE_MSG_MAIN_UUID, base);
-            spice_marshall_msg_main_uuid(m, &SPICE_CONTAINEROF(base, RedUuidPipeItem, base)->msg);
+            spice_marshall_msg_main_uuid(m, &SPICE_UPCAST(RedUuidPipeItem, base)->msg);
             break;
         case RED_PIPE_ITEM_TYPE_MAIN_AGENT_CONNECTED_TOKENS:
             main_channel_marshall_agent_connected(m, rcc, base);
diff --git a/server/pixmap-cache.c b/server/pixmap-cache.c
index 6b818d8..3ca3b87 100644
--- a/server/pixmap-cache.c
+++ b/server/pixmap-cache.c
@@ -114,7 +114,7 @@ PixmapCache *pixmap_cache_get(RedClient *client, uint8_t id, int64_t size)
 
     now = &pixmap_cache_list;
     while ((now = ring_next(&pixmap_cache_list, now))) {
-        PixmapCache *cache = SPICE_CONTAINEROF(now, PixmapCache, base);
+        PixmapCache *cache = SPICE_UPCAST(PixmapCache, now);
         if ((cache->client == client) && (cache->id == id)) {
             ret = cache;
             ret->refs++;
diff --git a/server/red-channel.c b/server/red-channel.c
index c00b655..2f17b28 100644
--- a/server/red-channel.c
+++ b/server/red-channel.c
@@ -517,7 +517,7 @@ static void red_channel_client_send_migrate(RedChannelClient *rcc)
 
 static void red_channel_client_send_empty_msg(RedChannelClient *rcc, RedPipeItem *base)
 {
-    RedEmptyMsgPipeItem *msg_pipe_item = SPICE_CONTAINEROF(base, RedEmptyMsgPipeItem, base);
+    RedEmptyMsgPipeItem *msg_pipe_item = SPICE_UPCAST(RedEmptyMsgPipeItem, base);
 
     red_channel_client_init_send_data(rcc, msg_pipe_item->msg, NULL);
     red_channel_client_begin_send_message(rcc);
@@ -2367,7 +2367,7 @@ int red_channel_client_wait_outgoing_item(RedChannelClient *rcc,
 
 static void marker_pipe_item_free(RedPipeItem *base)
 {
-    MarkerPipeItem *item = SPICE_CONTAINEROF(base, MarkerPipeItem, base);
+    MarkerPipeItem *item = SPICE_UPCAST(MarkerPipeItem, base);
 
     if (item->item_in_pipe) {
         *item->item_in_pipe = FALSE;
diff --git a/server/red-common.h b/server/red-common.h
index 50f29cc..7add3d0 100644
--- a/server/red-common.h
+++ b/server/red-common.h
@@ -33,10 +33,14 @@
 #include <common/ring.h>
 #include <common/spice_common.h>
 #include <common/draw.h>
+#include <common/verify.h>
 
 #include "spice.h"
 #include "utils.h"
 
+#define SPICE_UPCAST(type, ptr) \
+    (verify_expr(SPICE_OFFSETOF(type, base) == 0,SPICE_CONTAINEROF(ptr, type, base)))
+
 typedef struct SpiceCoreInterfaceInternal SpiceCoreInterfaceInternal;
 
 struct SpiceCoreInterfaceInternal {
diff --git a/server/red-record-qxl.c b/server/red-record-qxl.c
index 9c9dd62..aa2f3e5 100644
--- a/server/red-record-qxl.c
+++ b/server/red-record-qxl.c
@@ -70,7 +70,7 @@ static int record_zlib_more_space(ZlibEncoderUsrContext *usr, uint8_t **io_ptr)
 
 static int record_zlib_more_input(ZlibEncoderUsrContext *usr, uint8_t **input)
 {
-    RecordEncoderData *data = SPICE_CONTAINEROF(usr, RecordEncoderData, base);
+    RecordEncoderData *data = SPICE_UPCAST(RecordEncoderData, usr);
 
     if (data->buf == NULL) {
         fprintf(stderr, "%s: error: no more data\n", __FUNCTION__);
diff --git a/server/reds.c b/server/reds.c
index 90911b4..5c0f9b6 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -811,7 +811,7 @@ static RedVDIReadBuf *vdi_port_get_read_buf(RedCharDeviceVDIPort *dev)
 
 static void vdi_port_read_buf_free(RedPipeItem *base)
 {
-    RedVDIReadBuf *buf = SPICE_CONTAINEROF(base, RedVDIReadBuf, base);
+    RedVDIReadBuf *buf = SPICE_UPCAST(RedVDIReadBuf, base);
 
     g_warn_if_fail(buf->base.refcount == 0);
     ring_add(&buf->dev->priv->read_bufs, &buf->base.link);
diff --git a/server/smartcard.c b/server/smartcard.c
index f68ce48..7a34080 100644
--- a/server/smartcard.c
+++ b/server/smartcard.c
@@ -440,7 +440,7 @@ static void smartcard_channel_send_data(RedChannelClient *rcc, SpiceMarshaller *
 static void smartcard_channel_send_error(
     RedChannelClient *rcc, SpiceMarshaller *m, RedPipeItem *item)
 {
-    RedErrorItem* error_item = SPICE_CONTAINEROF(item, RedErrorItem, base);
+    RedErrorItem* error_item = SPICE_UPCAST(RedErrorItem, item);
 
     smartcard_channel_send_data(rcc, m, item, &error_item->vheader);
 }
@@ -448,7 +448,7 @@ static void smartcard_channel_send_error(
 static void smartcard_channel_send_msg(RedChannelClient *rcc,
                                        SpiceMarshaller *m, RedPipeItem *item)
 {
-    RedMsgItem* msg_item = SPICE_CONTAINEROF(item, RedMsgItem, base);
+    RedMsgItem* msg_item = SPICE_UPCAST(RedMsgItem, item);
 
     smartcard_channel_send_data(rcc, m, item, msg_item->vheader);
 }
@@ -539,7 +539,7 @@ static void smartcard_push_error(RedChannelClient *rcc, uint32_t reader_id, VSCE
 
 static void smartcard_free_vsc_msg_item(RedPipeItem *base)
 {
-    RedMsgItem *item = SPICE_CONTAINEROF(base, RedMsgItem, base);
+    RedMsgItem *item = SPICE_UPCAST(RedMsgItem, base);
     free(item->vheader);
     free(item);
 }
diff --git a/server/spicevmc.c b/server/spicevmc.c
index 54c4f42..b662d94 100644
--- a/server/spicevmc.c
+++ b/server/spicevmc.c
@@ -358,7 +358,7 @@ static void spicevmc_red_channel_send_data(RedChannelClient *rcc,
                                            SpiceMarshaller *m,
                                            RedPipeItem *item)
 {
-    RedVmcPipeItem *i = SPICE_CONTAINEROF(item, RedVmcPipeItem, base);
+    RedVmcPipeItem *i = SPICE_UPCAST(RedVmcPipeItem, item);
 
     red_channel_client_init_send_data(rcc, SPICE_MSG_SPICEVMC_DATA, item);
     spice_marshaller_add_ref(m, i->buf, i->buf_used);
@@ -382,7 +382,7 @@ static void spicevmc_red_channel_send_port_init(RedChannelClient *rcc,
                                                 SpiceMarshaller *m,
                                                 RedPipeItem *item)
 {
-    RedPortInitPipeItem *i = SPICE_CONTAINEROF(item, RedPortInitPipeItem, base);
+    RedPortInitPipeItem *i = SPICE_UPCAST(RedPortInitPipeItem, item);
     SpiceMsgPortInit init;
 
     red_channel_client_init_send_data(rcc, SPICE_MSG_PORT_INIT, item);
@@ -396,7 +396,7 @@ static void spicevmc_red_channel_send_port_event(RedChannelClient *rcc,
                                                  SpiceMarshaller *m,
                                                  RedPipeItem *item)
 {
-    RedPortEventPipeItem *i = SPICE_CONTAINEROF(item, RedPortEventPipeItem, base);
+    RedPortEventPipeItem *i = SPICE_UPCAST(RedPortEventPipeItem, item);
     SpiceMsgPortEvent event;
 
     red_channel_client_init_send_data(rcc, SPICE_MSG_PORT_EVENT, item);
diff --git a/server/stream.c b/server/stream.c
index f59abeb..9a648c7 100644
--- a/server/stream.c
+++ b/server/stream.c
@@ -65,7 +65,7 @@ static void stream_agent_stats_print(StreamAgent *agent)
 
 static void stream_create_destroy_item_release(RedPipeItem *base)
 {
-    StreamCreateDestroyItem *item = SPICE_CONTAINEROF(base, StreamCreateDestroyItem, base);
+    StreamCreateDestroyItem *item = SPICE_UPCAST(StreamCreateDestroyItem, base);
     DisplayChannel *display = (DisplayChannel*)item->agent->dcc->common.base.channel;
     stream_agent_unref(display, item->agent);
     free(item);
@@ -164,7 +164,7 @@ void stream_agent_unref(DisplayChannel *display, StreamAgent *agent)
 static void red_stream_clip_item_free(RedPipeItem *base)
 {
     g_return_if_fail(base != NULL);
-    RedStreamClipItem *item = SPICE_CONTAINEROF(base, RedStreamClipItem, base);
+    RedStreamClipItem *item = SPICE_UPCAST(RedStreamClipItem, base);
     DisplayChannel *display = DCC_TO_DC(item->stream_agent->dcc);
 
     g_return_if_fail(item->base.refcount == 0);
@@ -788,7 +788,7 @@ void stream_agent_stop(StreamAgent *agent)
 
 static void red_upgrade_item_free(RedPipeItem *base)
 {
-    RedUpgradeItem *item = SPICE_CONTAINEROF(base, RedUpgradeItem, base);
+    RedUpgradeItem *item = SPICE_UPCAST(RedUpgradeItem, base);
 
     g_return_if_fail(item != NULL);
     g_return_if_fail(item->base.refcount == 0);
diff --git a/server/tree.h b/server/tree.h
index e8da58d..648725c 100644
--- a/server/tree.h
+++ b/server/tree.h
@@ -54,7 +54,7 @@ struct Shadow {
 };
 
 #define IS_SHADOW(item) ((item)->type == TREE_ITEM_TYPE_SHADOW)
-#define SHADOW(item) SPICE_CONTAINEROF(item, Shadow, base)
+#define SHADOW(item) SPICE_UPCAST(Shadow, item)
 
 struct Container {
     TreeItem base;
@@ -62,7 +62,7 @@ struct Container {
 };
 
 #define IS_CONTAINER(item) ((item)->type == TREE_ITEM_TYPE_CONTAINER)
-#define CONTAINER(item) SPICE_CONTAINEROF(item, Container, base)
+#define CONTAINER(item) SPICE_UPCAST(Container, item)
 
 struct DrawItem {
     TreeItem base;
@@ -72,7 +72,7 @@ struct DrawItem {
 };
 
 #define IS_DRAW_ITEM(item) ((item)->type == TREE_ITEM_TYPE_DRAWABLE)
-#define DRAW_ITEM(item) SPICE_CONTAINEROF(item, DrawItem, base)
+#define DRAW_ITEM(item) SPICE_UPCAST(DrawItem, item)
 
 static inline int is_opaque_item(TreeItem *item)
 {


More information about the Spice-commits mailing list