[Spice-devel] [spice v2 1/2] display-channel: reuse function to set video codecs
Frediano Ziglio
fziglio at redhat.com
Mon Dec 5 11:49:50 UTC 2016
> From: Victor Toso <me at victortoso.com>
>
> Including g_clear_pointer() in glib-compat.h and using it to avoid
> warnings in odd situations.
>
> Signed-off-by: Victor Toso <victortoso at redhat.com>
Acked
> ---
> server/display-channel.c | 8 +++-----
> server/glib-compat.h | 19 +++++++++++++++++++
> 2 files changed, 22 insertions(+), 5 deletions(-)
>
> diff --git a/server/display-channel.c b/server/display-channel.c
> index 52f0a3d..061a99d 100644
> --- a/server/display-channel.c
> +++ b/server/display-channel.c
> @@ -21,6 +21,7 @@
> #include <common/sw_canvas.h>
>
> #include "display-channel-private.h"
> +#include "glib-compat.h"
>
> G_DEFINE_TYPE(DisplayChannel, display_channel, TYPE_COMMON_GRAPHICS_CHANNEL)
>
> @@ -62,10 +63,7 @@ display_channel_set_property(GObject *object,
> self->priv->n_surfaces = g_value_get_uint(value);
> break;
> case PROP_VIDEO_CODECS:
> - if (self->priv->video_codecs) {
> - g_array_unref(self->priv->video_codecs);
> - }
> - self->priv->video_codecs =
> g_array_ref(g_value_get_boxed(value));
> + display_channel_set_video_codecs(self,
> g_value_get_boxed(value));
> break;
> default:
> G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
> @@ -211,7 +209,7 @@ void display_channel_set_video_codecs(DisplayChannel
> *display, GArray *video_cod
> {
> spice_return_if_fail(display);
>
> - g_array_unref(display->priv->video_codecs);
> + g_clear_pointer(&display->priv->video_codecs, g_array_unref);
> display->priv->video_codecs = g_array_ref(video_codecs);
> }
>
> diff --git a/server/glib-compat.h b/server/glib-compat.h
> index 8a27afe..50a0783 100644
> --- a/server/glib-compat.h
> +++ b/server/glib-compat.h
> @@ -20,6 +20,25 @@
>
> #include <glib.h>
>
> +#if !GLIB_CHECK_VERSION(2,34,0)
> +#define g_clear_pointer(pp, destroy) \
> + G_STMT_START {
> \
> + G_STATIC_ASSERT (sizeof *(pp) == sizeof (gpointer));
> \
> + /* Only one access, please */
> \
> + gpointer *_pp = (gpointer *) (pp);
> \
> + gpointer _p;
> \
> + /* This assignment is needed to avoid a gcc warning */
> \
> + GDestroyNotify _destroy = (GDestroyNotify) (destroy);
> \
> +
> \
> + _p = *_pp;
> \
> + if (_p)
> \
> + {
> \
> + *_pp = NULL;
> \
> + _destroy (_p);
> \
> + }
> \
> + } G_STMT_END
> +#endif
> +
> #if !GLIB_CHECK_VERSION(2,32,0)
> static inline void
> g_queue_free_full(GQueue *queue, GDestroyNotify free_func)
Frediano
More information about the Spice-devel
mailing list