diff mbox series

[v3,1/3] util: remove redundant include of glib.h and add osdep.h

Message ID 20180608131604.16826-2-berrange@redhat.com
State New
Headers show
Series glib: update the min required version | expand

Commit Message

Daniel P. Berrangé June 8, 2018, 1:16 p.m. UTC
Code must only ever include glib.h indirectly via the glib-compat.h
header file, because we will need some macros set before glib.h is
pulled in. Adding extra includes of glib.h will (soon) cause compile
failures such as:

In file included from /home/berrange/src/virt/qemu/include/qemu/osdep.h:107,
                 from /home/berrange/src/virt/qemu/include/qemu/iova-tree.h:26,
                 from util/iova-tree.c:13:
/home/berrange/src/virt/qemu/include/glib-compat.h:22: error: "GLIB_VERSION_MIN_REQUIRED" redefined [-Werror]
 #define GLIB_VERSION_MIN_REQUIRED GLIB_VERSION_2_40

In file included from /usr/include/glib-2.0/glib/gtypes.h:34,
                 from /usr/include/glib-2.0/glib/galloca.h:32,
                 from /usr/include/glib-2.0/glib.h:30,
                 from util/iova-tree.c:12:
/usr/include/glib-2.0/glib/gversionmacros.h:237: note: this is the location of the previous definition
 # define GLIB_VERSION_MIN_REQUIRED      (GLIB_VERSION_CUR_STABLE)

Furthermore, the osdep.h include should always be done directly from the
.c file rather than indirectly via any .h file.

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 include/qemu/iova-tree.h | 1 -
 util/iova-tree.c         | 2 +-
 2 files changed, 1 insertion(+), 2 deletions(-)

Comments

Eric Blake June 8, 2018, 2:48 p.m. UTC | #1
On 06/08/2018 08:16 AM, Daniel P. Berrangé wrote:
> Code must only ever include glib.h indirectly via the glib-compat.h
> header file, because we will need some macros set before glib.h is
> pulled in. Adding extra includes of glib.h will (soon) cause compile
> failures such as:
> 
> In file included from /home/berrange/src/virt/qemu/include/qemu/osdep.h:107,
>                   from /home/berrange/src/virt/qemu/include/qemu/iova-tree.h:26,
>                   from util/iova-tree.c:13:
> /home/berrange/src/virt/qemu/include/glib-compat.h:22: error: "GLIB_VERSION_MIN_REQUIRED" redefined [-Werror]
>   #define GLIB_VERSION_MIN_REQUIRED GLIB_VERSION_2_40
> 
> In file included from /usr/include/glib-2.0/glib/gtypes.h:34,
>                   from /usr/include/glib-2.0/glib/galloca.h:32,
>                   from /usr/include/glib-2.0/glib.h:30,
>                   from util/iova-tree.c:12:
> /usr/include/glib-2.0/glib/gversionmacros.h:237: note: this is the location of the previous definition
>   # define GLIB_VERSION_MIN_REQUIRED      (GLIB_VERSION_CUR_STABLE)
> 
> Furthermore, the osdep.h include should always be done directly from the
> .c file rather than indirectly via any .h file.
> 
> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---

Reviewed-by: Eric Blake <eblake@redhat.com>
Thomas Huth June 8, 2018, 5:26 p.m. UTC | #2
On 08.06.2018 15:16, Daniel P. Berrangé wrote:
> Code must only ever include glib.h indirectly via the glib-compat.h
> header file, because we will need some macros set before glib.h is
> pulled in. Adding extra includes of glib.h will (soon) cause compile
> failures such as:
> 
> In file included from /home/berrange/src/virt/qemu/include/qemu/osdep.h:107,
>                  from /home/berrange/src/virt/qemu/include/qemu/iova-tree.h:26,
>                  from util/iova-tree.c:13:
> /home/berrange/src/virt/qemu/include/glib-compat.h:22: error: "GLIB_VERSION_MIN_REQUIRED" redefined [-Werror]
>  #define GLIB_VERSION_MIN_REQUIRED GLIB_VERSION_2_40
> 
> In file included from /usr/include/glib-2.0/glib/gtypes.h:34,
>                  from /usr/include/glib-2.0/glib/galloca.h:32,
>                  from /usr/include/glib-2.0/glib.h:30,
>                  from util/iova-tree.c:12:
> /usr/include/glib-2.0/glib/gversionmacros.h:237: note: this is the location of the previous definition
>  # define GLIB_VERSION_MIN_REQUIRED      (GLIB_VERSION_CUR_STABLE)
> 
> Furthermore, the osdep.h include should always be done directly from the
> .c file rather than indirectly via any .h file.
> 
> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  include/qemu/iova-tree.h | 1 -
>  util/iova-tree.c         | 2 +-
>  2 files changed, 1 insertion(+), 2 deletions(-)

Reviewed-by: Thomas Huth <thuth@redhat.com>
Peter Xu June 11, 2018, 2:43 a.m. UTC | #3
On Fri, Jun 08, 2018 at 02:16:02PM +0100, Daniel P. Berrangé wrote:
> Code must only ever include glib.h indirectly via the glib-compat.h
> header file, because we will need some macros set before glib.h is
> pulled in. Adding extra includes of glib.h will (soon) cause compile
> failures such as:
> 
> In file included from /home/berrange/src/virt/qemu/include/qemu/osdep.h:107,
>                  from /home/berrange/src/virt/qemu/include/qemu/iova-tree.h:26,
>                  from util/iova-tree.c:13:
> /home/berrange/src/virt/qemu/include/glib-compat.h:22: error: "GLIB_VERSION_MIN_REQUIRED" redefined [-Werror]
>  #define GLIB_VERSION_MIN_REQUIRED GLIB_VERSION_2_40
> 
> In file included from /usr/include/glib-2.0/glib/gtypes.h:34,
>                  from /usr/include/glib-2.0/glib/galloca.h:32,
>                  from /usr/include/glib-2.0/glib.h:30,
>                  from util/iova-tree.c:12:
> /usr/include/glib-2.0/glib/gversionmacros.h:237: note: this is the location of the previous definition
>  # define GLIB_VERSION_MIN_REQUIRED      (GLIB_VERSION_CUR_STABLE)
> 
> Furthermore, the osdep.h include should always be done directly from the
> .c file rather than indirectly via any .h file.
> 
> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>

Reviewed-by: Peter Xu <peterx@redhat.com>
diff mbox series

Patch

diff --git a/include/qemu/iova-tree.h b/include/qemu/iova-tree.h
index b061932097..b66cf93c4b 100644
--- a/include/qemu/iova-tree.h
+++ b/include/qemu/iova-tree.h
@@ -23,7 +23,6 @@ 
  * for the thread safety issue.
  */
 
-#include "qemu/osdep.h"
 #include "exec/memory.h"
 #include "exec/hwaddr.h"
 
diff --git a/util/iova-tree.c b/util/iova-tree.c
index 2d9cebfc89..7990692cbd 100644
--- a/util/iova-tree.c
+++ b/util/iova-tree.c
@@ -9,7 +9,7 @@ 
  * This work is licensed under the terms of the GNU GPL, version 2 or later.
  */
 
-#include <glib.h>
+#include "qemu/osdep.h"
 #include "qemu/iova-tree.h"
 
 struct IOVATree {