[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [virt-tools-list] [virt-viewer 2/2] Fix compilation with older glib versions



ack

----- Mensaje original -----
> Recent commits introduced use of g_clear_object and
> g_byte_array_new_take which are only present respectively in glib
> 2.28 and 2.32
> ---
>  src/Makefile.am        |  1 +
>  src/virt-glib-compat.c | 32 ++++++++++++++++++++++++++++++++
>  src/virt-glib-compat.h | 20 ++++++++++++++++++++
>  3 files changed, 53 insertions(+)
>  create mode 100644 src/virt-glib-compat.c
> 
> diff --git a/src/Makefile.am b/src/Makefile.am
> index d14ab01..27420cb 100644
> --- a/src/Makefile.am
> +++ b/src/Makefile.am
> @@ -35,6 +35,7 @@ $(BUILT_SOURCES): %: %.etemplate $(ENUMS_FILES)
>  COMMON_SOURCES =					\
>  	$(BUILT_SOURCES)				\
>  	virt-glib-compat.h				\
> +	virt-glib-compat.c				\
>  	virt-gtk-compat.h				\
>  	virt-viewer-util.h virt-viewer-util.c		\
>  	virt-viewer-auth.h virt-viewer-auth.c		\
> diff --git a/src/virt-glib-compat.c b/src/virt-glib-compat.c
> new file mode 100644
> index 0000000..54cce62
> --- /dev/null
> +++ b/src/virt-glib-compat.c
> @@ -0,0 +1,32 @@
> +/* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
> +/*
> +   This library is free software; you can redistribute it and/or
> +   modify it under the terms of the GNU Lesser General Public
> +   License as published by the Free Software Foundation; either
> +   version 2.1 of the License, or (at your option) any later
> version.
> +
> +   This library is distributed in the hope that it will be useful,
> +   but WITHOUT ANY WARRANTY; without even the implied warranty of
> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> +   Lesser General Public License for more details.
> +
> +   You should have received a copy of the GNU Lesser General Public
> +   License along with this library; if not, see
> <http://www.gnu.org/licenses/>.
> +*/
> +#include "virt-glib-compat.h"
> +
> +#if !GLIB_CHECK_VERSION(2,32,0)
> +GByteArray *g_byte_array_new_take (guint8 *data, gsize len)
> +{
> +  GByteArray *array;
> +
> +  array = g_byte_array_new ();
> +  g_assert (array->data == NULL);
> +  g_assert (array->len == 0);
> +
> +  array->data = data;
> +  array->len = len;
> +
> +  return array;
> +}
> +#endif
> diff --git a/src/virt-glib-compat.h b/src/virt-glib-compat.h
> index 23345a0..37b6f61 100644
> --- a/src/virt-glib-compat.h
> +++ b/src/virt-glib-compat.h
> @@ -51,6 +51,26 @@ G_BEGIN_DECLS
>    } G_STMT_END
>  #endif
>  
> +#if !GLIB_CHECK_VERSION(2,28,0)
> +#define g_clear_object(object_ptr) \
> +  G_STMT_START {
>                                                             \
> +    /* Only one access, please */
>                                            \
> +    gpointer *_p = (gpointer) (object_ptr);
>                                  \
> +    gpointer _o;
>                                                             \
> +
>                                                                             \
> +    do
>                                                                       \
> +      _o = g_atomic_pointer_get (_p);
>                                        \
> +    while G_UNLIKELY (!g_atomic_pointer_compare_and_exchange (_p,
> _o, NULL));\
> +
>                                                                             \
> +    if (_o)
>                                                                  \
> +      g_object_unref (_o);
>                                                   \
> +  } G_STMT_END
> +#endif
> +
> +#if !GLIB_CHECK_VERSION(2,32,0)
> +GByteArray *g_byte_array_new_take (guint8 *data, gsize len);
> +#endif
> +
>  G_END_DECLS
>  
>  #endif // _VIRT_GLIB_COMPAT_H
> --
> 1.8.1.4
> 
> _______________________________________________
> virt-tools-list mailing list
> virt-tools-list redhat com
> https://www.redhat.com/mailman/listinfo/virt-tools-list
> 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]