This commit raises glib required version to 2.22 or newer, adds a few missing functions to libvirt-gobject-compat.h and includes it in the files using these functions. --- configure.ac | 2 +- libvirt-gobject/Makefile.am | 1 + libvirt-gobject/libvirt-gobject-compat.c | 104 +++++++++++++++++++++++ libvirt-gobject/libvirt-gobject-compat.h | 30 +++++++ libvirt-gobject/libvirt-gobject-domain-device.c | 1 + libvirt-gobject/libvirt-gobject-input-stream.c | 1 + libvirt-gobject/libvirt-gobject-interface.c | 1 + libvirt-gobject/libvirt-gobject-output-stream.c | 1 + 8 files changed, 140 insertions(+), 1 deletions(-) create mode 100644 libvirt-gobject/libvirt-gobject-compat.c diff --git a/configure.ac b/configure.ac index 79a6eff..9f550ae 100644 --- a/configure.ac +++ b/configure.ac @@ -10,7 +10,7 @@ AC_CANONICAL_HOST AM_SILENT_RULES([yes]) LIBVIRT_REQUIRED=0.9.8 -GLIB2_REQUIRED=2.10.0 +GLIB2_REQUIRED=2.22.0 GOBJECT2_REQUIRED=2.10.0 GIO_REQUIRED=2.10.0 GOBJECT_INTROSPECTION_REQUIRED=0.10.8 diff --git a/libvirt-gobject/Makefile.am b/libvirt-gobject/Makefile.am index c4405f0..8531369 100644 --- a/libvirt-gobject/Makefile.am +++ b/libvirt-gobject/Makefile.am @@ -53,6 +53,7 @@ libvirt_gobject_1_0_la_SOURCES = \ $(GOBJECT_SOURCE_FILES) \ libvirt-gobject-domain-device-private.h \ libvirt-gobject-compat.h \ + libvirt-gobject-compat.c \ libvirt-gobject-input-stream.h \ libvirt-gobject-input-stream.c \ libvirt-gobject-output-stream.h \ diff --git a/libvirt-gobject/libvirt-gobject-compat.c b/libvirt-gobject/libvirt-gobject-compat.c new file mode 100644 index 0000000..7f51ecc --- /dev/null +++ b/libvirt-gobject/libvirt-gobject-compat.c @@ -0,0 +1,104 @@ +/* -*- 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 "libvirt-gobject-compat.h" + +#if !GLIB_CHECK_VERSION(2,28,0) +/** + * g_simple_async_result_take_error: (skip) + * @simple: a #GSimpleAsyncResult + * @error: a #GError + * + * Sets the result from @error, and takes over the caller's ownership + * of @error, so the caller does not need to free it any more. + * + * Since: 2.28 + **/ +G_GNUC_INTERNAL void +g_simple_async_result_take_error (GSimpleAsyncResult *simple, + GError *error) +{ + /* this code is different from upstream */ + /* we can't avoid extra copy/free, since the simple struct is + opaque */ + g_simple_async_result_set_from_error (simple, error); + g_error_free (error); +} + +/** + * g_simple_async_result_new_take_error: (skip) + * @source_object: (allow-none): a #GObject, or %NULL + * @callback: (scope async): a #GAsyncReadyCallback + * @user_data: (closure): user data passed to @callback + * @error: a #GError + * + * Creates a #GSimpleAsyncResult from an error condition, and takes over the + * caller's ownership of @error, so the caller does not need to free it anymore. + * + * Returns: a #GSimpleAsyncResult + * + * Since: 2.28 + **/ +GSimpleAsyncResult * +g_simple_async_result_new_take_error (GObject *source_object, + GAsyncReadyCallback callback, + gpointer user_data, + GError *error) +{ + GSimpleAsyncResult *simple; + + g_return_val_if_fail (!source_object || G_IS_OBJECT (source_object), NULL); + + simple = g_simple_async_result_new (source_object, + callback, + user_data, NULL); + g_simple_async_result_take_error (simple, error); + + return simple; +} + +/** + * g_simple_async_report_take_gerror_in_idle: (skip) + * @object: (allow-none): a #GObject, or %NULL + * @callback: a #GAsyncReadyCallback. + * @user_data: user data passed to @callback. + * @error: the #GError to report + * + * Reports an error in an idle function. Similar to + * g_simple_async_report_gerror_in_idle(), but takes over the caller's + * ownership of @error, so the caller does not have to free it any more. + * + * Since: 2.28 + **/ +void +g_simple_async_report_take_gerror_in_idle (GObject *object, + GAsyncReadyCallback callback, + gpointer user_data, + GError *error) +{ + GSimpleAsyncResult *simple; + + g_return_if_fail (!object || G_IS_OBJECT (object)); + g_return_if_fail (error != NULL); + + simple = g_simple_async_result_new_take_error (object, + callback, + user_data, + error); + g_simple_async_result_complete_in_idle (simple); + g_object_unref (simple); +} +#endif diff --git a/libvirt-gobject/libvirt-gobject-compat.h b/libvirt-gobject/libvirt-gobject-compat.h index d410953..0c37537 100644 --- a/libvirt-gobject/libvirt-gobject-compat.h +++ b/libvirt-gobject/libvirt-gobject-compat.h @@ -24,6 +24,7 @@ #define __LIBVIRT_GOBJECT_COMPAT_H__ #include <glib-object.h> +#include <gio/gio.h> #if !GLIB_CHECK_VERSION(2,26,0) #define G_DEFINE_BOXED_TYPE(TypeName, type_name, copy_func, free_func) G_DEFINE_BOXED_TYPE_WITH_CODE (TypeName, type_name, copy_func, free_func, {}) @@ -69,4 +70,33 @@ type_name##_get_type (void) \ #endif /* __GNUC__ */ #endif /* glib 2.26 */ +#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 + +void +g_simple_async_result_take_error(GSimpleAsyncResult *simple, + GError *error); +GSimpleAsyncResult *g_simple_async_result_new_take_error (GObject *source_object, + GAsyncReadyCallback callback, + gpointer user_data, + GError *error); +void g_simple_async_report_take_gerror_in_idle (GObject *object, + GAsyncReadyCallback callback, + gpointer user_data, + GError *error); +#endif /* glib 2.28 */ + + #endif /* __LIBVIRT_GOBJECT_COMPAT_H__ */ diff --git a/libvirt-gobject/libvirt-gobject-domain-device.c b/libvirt-gobject/libvirt-gobject-domain-device.c index 4a46a1d..528b513 100644 --- a/libvirt-gobject/libvirt-gobject-domain-device.c +++ b/libvirt-gobject/libvirt-gobject-domain-device.c @@ -27,6 +27,7 @@ #include "libvirt-glib/libvirt-glib.h" #include "libvirt-gobject/libvirt-gobject.h" +#include "libvirt-gobject-compat.h" #include "libvirt-gobject/libvirt-gobject-domain-device-private.h" diff --git a/libvirt-gobject/libvirt-gobject-input-stream.c b/libvirt-gobject/libvirt-gobject-input-stream.c index 29d1c29..3e1ee20 100644 --- a/libvirt-gobject/libvirt-gobject-input-stream.c +++ b/libvirt-gobject/libvirt-gobject-input-stream.c @@ -29,6 +29,7 @@ #include "libvirt-glib/libvirt-glib.h" #include "libvirt-gobject/libvirt-gobject.h" #include "libvirt-gobject-input-stream.h" +#include "libvirt-gobject-compat.h" #define gvir_input_stream_get_type _gvir_input_stream_get_type G_DEFINE_TYPE(GVirInputStream, gvir_input_stream, G_TYPE_INPUT_STREAM); diff --git a/libvirt-gobject/libvirt-gobject-interface.c b/libvirt-gobject/libvirt-gobject-interface.c index 1fede51..095e22a 100644 --- a/libvirt-gobject/libvirt-gobject-interface.c +++ b/libvirt-gobject/libvirt-gobject-interface.c @@ -28,6 +28,7 @@ #include "libvirt-glib/libvirt-glib.h" #include "libvirt-gobject/libvirt-gobject.h" +#include "libvirt-gobject-compat.h" #define GVIR_INTERFACE_GET_PRIVATE(obj) \ (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_TYPE_INTERFACE, GVirInterfacePrivate)) diff --git a/libvirt-gobject/libvirt-gobject-output-stream.c b/libvirt-gobject/libvirt-gobject-output-stream.c index 88fff85..e1b6a6a 100644 --- a/libvirt-gobject/libvirt-gobject-output-stream.c +++ b/libvirt-gobject/libvirt-gobject-output-stream.c @@ -29,6 +29,7 @@ #include "libvirt-glib/libvirt-glib.h" #include "libvirt-gobject/libvirt-gobject.h" #include "libvirt-gobject-output-stream.h" +#include "libvirt-gobject-compat.h" #define gvir_output_stream_get_type _gvir_output_stream_get_type G_DEFINE_TYPE(GVirOutputStream, gvir_output_stream, G_TYPE_OUTPUT_STREAM); -- 1.7.7.5 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list