[Spice-devel] [PATCH spice-server 1/3] Use SPICE_CONTAINEROF to avoid some possible alignment warnings on MIPS

Frediano Ziglio fziglio at redhat.com
Mon Jun 17 12:20:57 UTC 2019


ping the series

> 
> This patch came from some experiments using an emulated MIPS machine.
> On such architecture due to not supporting alignment access the
> compiler is more strict about conversion complaining with some
> pointer casts. Use different conversion to avoid these warnings.
> 
> Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
> ---
>  server/cache-item.tmpl.c |  3 ++-
>  server/dcc.c             |  4 ++--
>  server/image-cache.c     |  5 +++--
>  server/image-encoders.c  | 26 +++++++++++++-------------
>  server/mjpeg-encoder.c   | 12 ++++++------
>  server/pixmap-cache.c    |  2 +-
>  6 files changed, 27 insertions(+), 25 deletions(-)
> 
> diff --git a/server/cache-item.tmpl.c b/server/cache-item.tmpl.c
> index f119a9ee4..8e18f9b1b 100644
> --- a/server/cache-item.tmpl.c
> +++ b/server/cache-item.tmpl.c
> @@ -89,7 +89,8 @@ static int FUNC_NAME(add)(CHANNELCLIENT *channel_client,
> uint64_t id, size_t siz
>      channel_client->priv->VAR_NAME(available) -= size;
>      SPICE_VERIFY(SPICE_OFFSETOF(RedCacheItem, u.cache_data.lru_link) == 0);
>      while (channel_client->priv->VAR_NAME(available) < 0) {
> -        RedCacheItem *tail = (RedCacheItem
> *)ring_get_tail(&channel_client->priv->VAR_NAME(lru));
> +        RedCacheItem *tail =
> SPICE_CONTAINEROF(ring_get_tail(&channel_client->priv->VAR_NAME(lru)),
> +                                                             RedCacheItem,
> u.cache_data.lru_link);
>          if (!tail) {
>              channel_client->priv->VAR_NAME(available) += size;
>              g_free(item);
> diff --git a/server/dcc.c b/server/dcc.c
> index acc1ca38c..71d09b77f 100644
> --- a/server/dcc.c
> +++ b/server/dcc.c
> @@ -968,8 +968,8 @@ bool dcc_pixmap_cache_unlocked_add(DisplayChannelClient
> *dcc, uint64_t id,
>          NewCacheItem **now;
>  
>          SPICE_VERIFY(SPICE_OFFSETOF(NewCacheItem, lru_link) == 0);
> -        if (!(tail = (NewCacheItem *)ring_get_tail(&cache->lru)) ||
> -                                                   tail->sync[dcc->priv->id]
> == serial) {
> +        if (!(tail = SPICE_CONTAINEROF(ring_get_tail(&cache->lru),
> NewCacheItem, lru_link)) ||
> +
> tail->sync[dcc->priv->id]
> == serial) {
>              cache->available += size;
>              g_free(item);
>              return FALSE;
> diff --git a/server/image-cache.c b/server/image-cache.c
> index 2ca4d4b67..4881f4d92 100644
> --- a/server/image-cache.c
> +++ b/server/image-cache.c
> @@ -78,7 +78,8 @@ static void image_cache_put(SpiceImageCache *spice_cache,
> uint64_t id, pixman_im
>  #ifndef IMAGE_CACHE_AGE
>      if (cache->num_items == IMAGE_CACHE_MAX_ITEMS) {
>          SPICE_VERIFY(SPICE_OFFSETOF(ImageCacheItem, lru_link) == 0);
> -        ImageCacheItem *tail = (ImageCacheItem *)ring_get_tail(&cache->lru);
> +        ImageCacheItem *tail =
> +            SPICE_CONTAINEROF(ring_get_tail(&cache->lru), ImageCacheItem,
> lru_link);
>          spice_assert(tail);
>          image_cache_remove(cache, tail);
>      }
> @@ -133,7 +134,7 @@ void image_cache_reset(ImageCache *cache)
>      ImageCacheItem *item;
>  
>      SPICE_VERIFY(SPICE_OFFSETOF(ImageCacheItem, lru_link) == 0);
> -    while ((item = (ImageCacheItem *)ring_get_head(&cache->lru))) {
> +    while ((item = SPICE_CONTAINEROF(ring_get_head(&cache->lru),
> ImageCacheItem, lru_link))) {
>          image_cache_remove(cache, item);
>      }
>  #ifdef IMAGE_CACHE_AGE
> diff --git a/server/image-encoders.c b/server/image-encoders.c
> index 306c6dca6..d4d486c36 100644
> --- a/server/image-encoders.c
> +++ b/server/image-encoders.c
> @@ -89,7 +89,7 @@ static void image_encoders_release_glz(ImageEncoders *enc);
>  static SPICE_GNUC_NORETURN SPICE_GNUC_PRINTF(2, 3) void
>  quic_usr_error(QuicUsrContext *usr, const char *fmt, ...)
>  {
> -    EncoderData *usr_data = &(((QuicData *)usr)->data);
> +    EncoderData *usr_data = &(SPICE_CONTAINEROF(usr, QuicData, usr)->data);
>      va_list ap;
>      char message_buf[ENCODER_MESSAGE_SIZE];
>  
> @@ -104,7 +104,7 @@ quic_usr_error(QuicUsrContext *usr, const char *fmt, ...)
>  static SPICE_GNUC_NORETURN SPICE_GNUC_PRINTF(2, 3) void
>  lz_usr_error(LzUsrContext *usr, const char *fmt, ...)
>  {
> -    EncoderData *usr_data = &(((LzData *)usr)->data);
> +    EncoderData *usr_data = &(SPICE_CONTAINEROF(usr, LzData, usr)->data);
>      va_list ap;
>      char message_buf[ENCODER_MESSAGE_SIZE];
>  
> @@ -233,25 +233,25 @@ static int encoder_usr_more_space(EncoderData
> *enc_data, uint8_t **io_ptr)
>  
>  static int quic_usr_more_space(QuicUsrContext *usr, uint32_t **io_ptr, int
>  rows_completed)
>  {
> -    EncoderData *usr_data = &(((QuicData *)usr)->data);
> +    EncoderData *usr_data = &(SPICE_CONTAINEROF(usr, QuicData, usr)->data);
>      return encoder_usr_more_space(usr_data, (uint8_t **)io_ptr) /
>      sizeof(uint32_t);
>  }
>  
>  static int lz_usr_more_space(LzUsrContext *usr, uint8_t **io_ptr)
>  {
> -    EncoderData *usr_data = &(((LzData *)usr)->data);
> +    EncoderData *usr_data = &(SPICE_CONTAINEROF(usr, LzData, usr)->data);
>      return encoder_usr_more_space(usr_data, io_ptr);
>  }
>  
>  static int glz_usr_more_space(GlzEncoderUsrContext *usr, uint8_t **io_ptr)
>  {
> -    EncoderData *usr_data = &(((GlzData *)usr)->data);
> +    EncoderData *usr_data = &(SPICE_CONTAINEROF(usr, GlzData, usr)->data);
>      return encoder_usr_more_space(usr_data, io_ptr);
>  }
>  
>  static int jpeg_usr_more_space(JpegEncoderUsrContext *usr, uint8_t **io_ptr)
>  {
> -    EncoderData *usr_data = &(((JpegData *)usr)->data);
> +    EncoderData *usr_data = &(SPICE_CONTAINEROF(usr, JpegData, usr)->data);
>      return encoder_usr_more_space(usr_data, io_ptr);
>  }
>  
> @@ -265,7 +265,7 @@ static int lz4_usr_more_space(Lz4EncoderUsrContext *usr,
> uint8_t **io_ptr)
>  
>  static int zlib_usr_more_space(ZlibEncoderUsrContext *usr, uint8_t **io_ptr)
>  {
> -    EncoderData *usr_data = &(((ZlibData *)usr)->data);
> +    EncoderData *usr_data = &(SPICE_CONTAINEROF(usr, ZlibData, usr)->data);
>      return encoder_usr_more_space(usr_data, io_ptr);
>  }
>  
> @@ -301,25 +301,25 @@ static inline int encoder_usr_more_lines(EncoderData
> *enc_data, uint8_t **lines)
>  
>  static int quic_usr_more_lines(QuicUsrContext *usr, uint8_t **lines)
>  {
> -    EncoderData *usr_data = &(((QuicData *)usr)->data);
> +    EncoderData *usr_data = &(SPICE_CONTAINEROF(usr, QuicData, usr)->data);
>      return encoder_usr_more_lines(usr_data, lines);
>  }
>  
>  static int lz_usr_more_lines(LzUsrContext *usr, uint8_t **lines)
>  {
> -    EncoderData *usr_data = &(((LzData *)usr)->data);
> +    EncoderData *usr_data = &(SPICE_CONTAINEROF(usr, LzData, usr)->data);
>      return encoder_usr_more_lines(usr_data, lines);
>  }
>  
>  static int glz_usr_more_lines(GlzEncoderUsrContext *usr, uint8_t **lines)
>  {
> -    EncoderData *usr_data = &(((GlzData *)usr)->data);
> +    EncoderData *usr_data = &(SPICE_CONTAINEROF(usr, GlzData, usr)->data);
>      return encoder_usr_more_lines(usr_data, lines);
>  }
>  
>  static int jpeg_usr_more_lines(JpegEncoderUsrContext *usr, uint8_t **lines)
>  {
> -    EncoderData *usr_data = &(((JpegData *)usr)->data);
> +    EncoderData *usr_data = &(SPICE_CONTAINEROF(usr, JpegData, usr)->data);
>      return encoder_usr_more_lines(usr_data, lines);
>  }
>  
> @@ -333,7 +333,7 @@ static int lz4_usr_more_lines(Lz4EncoderUsrContext *usr,
> uint8_t **lines)
>  
>  static int zlib_usr_more_input(ZlibEncoderUsrContext *usr, uint8_t** input)
>  {
> -    EncoderData *usr_data = &(((ZlibData *)usr)->data);
> +    EncoderData *usr_data = &(SPICE_CONTAINEROF(usr, ZlibData, usr)->data);
>      int buf_size;
>  
>      if (!usr_data->u.compressed_data.next) {
> @@ -386,7 +386,7 @@ static void image_encoders_init_lz(ImageEncoders *enc)
>  
>  static void glz_usr_free_image(GlzEncoderUsrContext *usr, GlzUsrImageContext
>  *image)
>  {
> -    GlzData *lz_data = (GlzData *)usr;
> +    GlzData *lz_data = SPICE_CONTAINEROF(usr, GlzData, usr);
>      GlzDrawableInstanceItem *glz_drawable_instance =
>      (GlzDrawableInstanceItem *)image;
>      ImageEncoders *drawable_enc =
>      glz_drawable_instance->glz_drawable->encoders;
>      ImageEncoders *this_enc = SPICE_CONTAINEROF(lz_data, ImageEncoders,
>      glz_data);
> diff --git a/server/mjpeg-encoder.c b/server/mjpeg-encoder.c
> index 4a02e7c8b..e629adae4 100644
> --- a/server/mjpeg-encoder.c
> +++ b/server/mjpeg-encoder.c
> @@ -206,7 +206,7 @@ static MJpegVideoBuffer* create_mjpeg_video_buffer(void)
>  
>  static void mjpeg_encoder_destroy(VideoEncoder *video_encoder)
>  {
> -    MJpegEncoder *encoder = (MJpegEncoder*)video_encoder;
> +    MJpegEncoder *encoder = SPICE_CONTAINEROF(video_encoder, MJpegEncoder,
> base);
>      g_free(encoder->cinfo.dest);
>      jpeg_destroy_compress(&encoder->cinfo);
>      g_free(encoder->row);
> @@ -931,7 +931,7 @@ static int mjpeg_encoder_encode_frame(VideoEncoder
> *video_encoder,
>                                        gpointer bitmap_opaque,
>                                        VideoBuffer **outbuf)
>  {
> -    MJpegEncoder *encoder = (MJpegEncoder*)video_encoder;
> +    MJpegEncoder *encoder = SPICE_CONTAINEROF(video_encoder, MJpegEncoder,
> base);
>      MJpegVideoBuffer *buffer = create_mjpeg_video_buffer();
>      if (!buffer) {
>          return VIDEO_ENCODER_FRAME_UNSUPPORTED;
> @@ -1191,7 +1191,7 @@ static void
> mjpeg_encoder_client_stream_report(VideoEncoder *video_encoder,
>                                                 int32_t end_frame_delay,
>                                                 uint32_t audio_delay)
>  {
> -    MJpegEncoder *encoder = (MJpegEncoder*)video_encoder;
> +    MJpegEncoder *encoder = SPICE_CONTAINEROF(video_encoder, MJpegEncoder,
> base);
>      MJpegEncoderRateControl *rate_control = &encoder->rate_control;
>      MJpegEncoderClientState *client_state = &rate_control->client_state;
>      uint64_t avg_enc_size = 0;
> @@ -1289,7 +1289,7 @@ static void
> mjpeg_encoder_client_stream_report(VideoEncoder *video_encoder,
>  
>  static void mjpeg_encoder_notify_server_frame_drop(VideoEncoder
>  *video_encoder)
>  {
> -    MJpegEncoder *encoder = (MJpegEncoder*)video_encoder;
> +    MJpegEncoder *encoder = SPICE_CONTAINEROF(video_encoder, MJpegEncoder,
> base);
>      encoder->rate_control.server_state.num_frames_dropped++;
>      mjpeg_encoder_process_server_drops(encoder);
>  }
> @@ -1328,14 +1328,14 @@ static void
> mjpeg_encoder_process_server_drops(MJpegEncoder *encoder)
>  
>  static uint64_t mjpeg_encoder_get_bit_rate(VideoEncoder *video_encoder)
>  {
> -    MJpegEncoder *encoder = (MJpegEncoder*)video_encoder;
> +    MJpegEncoder *encoder = SPICE_CONTAINEROF(video_encoder, MJpegEncoder,
> base);
>      return encoder->rate_control.byte_rate * 8;
>  }
>  
>  static void mjpeg_encoder_get_stats(VideoEncoder *video_encoder,
>                                      VideoEncoderStats *stats)
>  {
> -    MJpegEncoder *encoder = (MJpegEncoder*)video_encoder;
> +    MJpegEncoder *encoder = SPICE_CONTAINEROF(video_encoder, MJpegEncoder,
> base);
>      spice_assert(encoder != NULL && stats != NULL);
>      stats->starting_bit_rate = encoder->starting_bit_rate;
>      stats->cur_bit_rate = mjpeg_encoder_get_bit_rate(video_encoder);
> diff --git a/server/pixmap-cache.c b/server/pixmap-cache.c
> index 489fe0bf6..49659ea41 100644
> --- a/server/pixmap-cache.c
> +++ b/server/pixmap-cache.c
> @@ -45,7 +45,7 @@ void pixmap_cache_clear(PixmapCache *cache)
>      }
>  
>      SPICE_VERIFY(SPICE_OFFSETOF(NewCacheItem, lru_link) == 0);
> -    while ((item = (NewCacheItem *)ring_get_head(&cache->lru))) {
> +    while ((item = SPICE_CONTAINEROF(ring_get_head(&cache->lru),
> NewCacheItem, lru_link))) {
>          ring_remove(&item->lru_link);
>          g_free(item);
>      }


More information about the Spice-devel mailing list