[libvirt] [libvirt-glib] Compilation warning and error

Hi Daniel, I'm trying libvirt-glib, however, I met some compilation warning and error, for details, please see attachment. Regards, Alex

On Thu, Jan 12, 2012 at 10:50:57PM -0500, Alex Jia wrote:
CC libvirt_gobject_1_0_la-libvirt-gobject-main.lo CC libvirt_gobject_1_0_la-libvirt-gobject-domain-snapshot.lo CC libvirt_gobject_1_0_la-libvirt-gobject-domain-device.lo libvirt-gobject-domain-device.c: In function 'gvir_domain_device_set_property': libvirt-gobject-domain-device.c:77: warning: implicit declaration of function 'g_clear_object' libvirt-gobject-domain-device.c:77: warning: nested extern declaration of 'g_clear_object'
This was added in glib 2.28
CC libvirt_gobject_1_0_la-libvirt-gobject-domain-disk.lo CC libvirt_gobject_1_0_la-libvirt-gobject-domain-interface.lo CC libvirt_gobject_1_0_la-libvirt-gobject-domain.lo libvirt-gobject-domain.c: In function 'gvir_domain_save_helper': libvirt-gobject-domain.c:777: warning: implicit declaration of function 'g_simple_async_result_take_error' libvirt-gobject-domain.c:777: warning: nested extern declaration of 'g_simple_async_result_take_error'
This was added in glib 2.28 too
CC libvirt_gobject_1_0_la-libvirt-gobject-interface.lo libvirt-gobject-interface.c:158: error: expected declaration specifiers or '...' before 'gvir_interface_handle' libvirt-gobject-interface.c:159: error: expected declaration specifiers or '...' before 'gvir_interface_handle_copy' libvirt-gobject-interface.c:159: error: expected declaration specifiers or '...' before 'gvir_interface_handle_free' libvirt-gobject-interface.c:158: error: parameter 1 has incomplete type libvirt-gobject-interface.c:161: warning: return type defaults to 'int' libvirt-gobject-interface.c:158: warning: no previous prototype for 'G_DEFINE_BOXED_TYPE'
And this was added in glib 2.26 But configure.ac only checks for glib 2.10, you probably have an older glib. Adding compatibility fallbacks for older glibs for these functions shouldn't be too hard, spice-gtk added such fallbacks recently. Christophe

Hi Christophe, Thanks for your comments, as you said, it should be my old glib version issue. Regards, Alex ----- Original Message ----- From: "Christophe Fergeau" <cfergeau@redhat.com> To: "Alex Jia" <ajia@redhat.com> Cc: "Daniel Berrange" <berrange@redhat.com>, "libvir" <libvir-list@redhat.com> Sent: Friday, January 13, 2012 4:58:08 PM Subject: Re: [libvirt] [libvirt-glib] Compilation warning and error On Thu, Jan 12, 2012 at 10:50:57PM -0500, Alex Jia wrote:
CC libvirt_gobject_1_0_la-libvirt-gobject-main.lo CC libvirt_gobject_1_0_la-libvirt-gobject-domain-snapshot.lo CC libvirt_gobject_1_0_la-libvirt-gobject-domain-device.lo libvirt-gobject-domain-device.c: In function 'gvir_domain_device_set_property': libvirt-gobject-domain-device.c:77: warning: implicit declaration of function 'g_clear_object' libvirt-gobject-domain-device.c:77: warning: nested extern declaration of 'g_clear_object'
This was added in glib 2.28
CC libvirt_gobject_1_0_la-libvirt-gobject-domain-disk.lo CC libvirt_gobject_1_0_la-libvirt-gobject-domain-interface.lo CC libvirt_gobject_1_0_la-libvirt-gobject-domain.lo libvirt-gobject-domain.c: In function 'gvir_domain_save_helper': libvirt-gobject-domain.c:777: warning: implicit declaration of function 'g_simple_async_result_take_error' libvirt-gobject-domain.c:777: warning: nested extern declaration of 'g_simple_async_result_take_error'
This was added in glib 2.28 too
CC libvirt_gobject_1_0_la-libvirt-gobject-interface.lo libvirt-gobject-interface.c:158: error: expected declaration specifiers or '...' before 'gvir_interface_handle' libvirt-gobject-interface.c:159: error: expected declaration specifiers or '...' before 'gvir_interface_handle_copy' libvirt-gobject-interface.c:159: error: expected declaration specifiers or '...' before 'gvir_interface_handle_free' libvirt-gobject-interface.c:158: error: parameter 1 has incomplete type libvirt-gobject-interface.c:161: warning: return type defaults to 'int' libvirt-gobject-interface.c:158: warning: no previous prototype for 'G_DEFINE_BOXED_TYPE'
And this was added in glib 2.26 But configure.ac only checks for glib 2.10, you probably have an older glib. Adding compatibility fallbacks for older glibs for these functions shouldn't be too hard, spice-gtk added such fallbacks recently. Christophe

On Fri, Jan 13, 2012 at 04:21:33AM -0500, Alex Jia wrote:
Hi Christophe, Thanks for your comments, as you said, it should be my old glib version issue.
Thanks for reporting this issue btw :) I think we should raise the glib requirement a bit (maybe 2.18) and then add fallbacks for the functions you mentioned Christophe

On Fri, Jan 13, 2012 at 10:27:30AM +0100, Christophe Fergeau wrote:
On Fri, Jan 13, 2012 at 04:21:33AM -0500, Alex Jia wrote:
Hi Christophe, Thanks for your comments, as you said, it should be my old glib version issue.
Thanks for reporting this issue btw :) I think we should raise the glib requirement a bit (maybe 2.18) and then add fallbacks for the functions you mentioned
My only desire is to retain build compat with RHEL-6 at this point, which has glib 2.22. So increasing the dep to 2.18 is fine with me Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

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

On Wed, Jan 18, 2012 at 12:14:46PM +0100, Christophe Fergeau wrote:
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
ACK
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
Can you also make the same change to libvirt-glib.spec.in for the RPM Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
participants (3)
-
Alex Jia
-
Christophe Fergeau
-
Daniel P. Berrange