Stop including qemu-common.h in memory.h
PATCH 1/1 Stop including qemu-common.h in memory.h
Including qemu-common.h from other header files is generally a bad idea, because it means it's very easy to end up with a circular dependency. For instance, if we wanted to include memory.h from qom/cpu.h we'd end up with this loop:
memory.h -> qemu-common.h -> cpu.h -> cpu-qom.h -> qom/cpu.h -> memory.h
Remove the include from memory.h. This requires us to fix up a few other files which were inadvertently getting declarations indirectly through memory.h.
The biggest change is splitting the fprintf_function typedef out into its own header so other headers can get at it without having to include qemu-common.h.
---
I originally wrote this because I thought I was going to need to include memory.h in qom/cpu.h. In fact I managed to avoid that in the end, but this still seems like useful cleanup.
include/exec/cpu-common.h | 2 ++ include/exec/memory.h | 1 - include/hw/arm/arm.h | 1 + include/qemu-common.h | 4 +--- include/qemu/fprintf-fn.h | 16 ++++++++++++++++ target-s390x/mmu_helper.c | 2 +- 6 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 include/qemu/fprintf-fn.h
include/exec/cpu-common.h +2 -0
@@ -13,6 +13,8 @@#include "qemu/bswap.h" #include "qemu/queue.h" +#include "qemu/fprintf-fn.h" +#include "qemu/typedefs.h" /** * CPUListState:
include/exec/memory.h +0 -1
@@ -23,7 +23,6 @@#include <stdint.h> #include <stdbool.h> -#include "qemu-common.h" #include "exec/cpu-common.h" #ifndef CONFIG_USER_ONLY #include "exec/hwaddr.h"
include/hw/arm/arm.h +1 -0
@@ -14,6 +14,7 @@#include "exec/memory.h" #include "hw/irq.h" #include "qemu/notify.h" +#include "cpu.h" /* armv7m.c */ qemu_irq *armv7m_init(MemoryRegion *system_memory, int mem_size, int num_irq,
include/qemu-common.h +1 -3
@@ -15,6 +15,7 @@#include "qemu/compiler.h" #include "config-host.h" #include "qemu/typedefs.h" +#include "qemu/fprintf-fn.h" #if defined(__arm__) || defined(__sparc__) || defined(__mips__) || defined(__hppa__) || defined(__ia64__)#define WORDS_ALIGNED
@@ -85,9 +86,6 @@# error Unknown pointer size#endif -typedef int (*fprintf_function)(FILE *f, const char *fmt, ...) -GCC_FMT_ATTR (2 ,3 ); -#ifdef _WIN32#define fsync _commit#if !defined(lseek)
include/qemu/fprintf-fn.h new file +16 -0
@@ -0,0 +1,16 @@ +/* +* Typedef for fprintf-alike function pointers. +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#ifndef FPRINTF_FN_H + +#include "qemu/compiler.h" +#include <stdio.h> + +typedef int (*fprintf_function)(FILE *f, const char *fmt, ...) +GCC_FMT_ATTR (2 ,3 ); + +#endif
target-s390x/mmu_helper.c +1 -1
@@ -17,8 +17,8 @@#include "qemu/error-report.h" #include "exec/address-spaces.h" -#include "sysemu/kvm.h" #include "cpu.h" +#include "sysemu/kvm.h" /* #define DEBUG_S390 */ /* #define DEBUG_S390_PTE */
Signature · 1 line
1.9.1
Quoted 6 lines · Peter Maydell
Including
qemu-common.hfrom other header files is generally a bad idea, because it means it's very easy to end up with a circular dependency. For instance, if we wanted to includememory.hfromqom/cpu.hwe'd end up with this loop:
memory.h->qemu-common.h->cpu.h->cpu-qom.h->qom/cpu.h->memory.h
Quoted 7 lines
Remove the include from
memory.h. This requires us to fix up a few other files which were inadvertently getting declarations indirectly throughmemory.h.The biggest change is splitting the
fprintf_functiontypedef out into its own header so other headers can get at it without having to includeqemu-common.h.
Why not simply put it in qemu/typedefs.h?
Quoted 5 lines
Signed-off-by Peter Maydell <[email protected]>---
I originally wrote this because I thought I was going to need to includememory.hinqom/cpu.h. In fact I managed to avoid that in the end, but this still seems like useful cleanup.
Yup.
Quoted 12 lines · Markus Armbruster
Quoted 10 lines · Peter Maydell
Including
qemu-common.hfrom other header files is generally a bad idea, because it means it's very easy to end up with a circular dependency. For instance, if we wanted to includememory.hfromqom/cpu.hwe'd end up with this loop:
memory.h->qemu-common.h->cpu.h->cpu-qom.h->qom/cpu.h->memory.hRemove the include from
memory.h. This requires us to fix up a few other files which were inadvertently getting declarations indirectly throughmemory.h.
Quoted 5 lines
Quoted 3 lines
The biggest change is splitting the
fprintf_functiontypedef out into its own header so other headers can get at it without having to includeqemu-common.h.Why not simply put it in
qemu/typedefs.h?
I thought about that, but that header claims it is specifically for opaque typedefs, and also I didn't really want to add the stdio.h and compiler.h includes to it.
-- PMM
Quoted 117 lines · Peter Maydell
Including
qemu-common.hfrom other header files is generally a bad idea, because it means it's very easy to end up with a circular dependency. For instance, if we wanted to includememory.hfromqom/cpu.hwe'd end up with this loop:
memory.h->qemu-common.h->cpu.h->cpu-qom.h->qom/cpu.h->memory.hRemove the include from
memory.h. This requires us to fix up a few other files which were inadvertently getting declarations indirectly throughmemory.h.The biggest change is splitting the
fprintf_functiontypedef out into its own header so other headers can get at it without having to includeqemu-common.h.Signed-off-by Peter Maydell <[email protected]>---
I originally wrote this because I thought I was going to need to includememory.hinqom/cpu.h. In fact I managed to avoid that in the end, but this still seems like useful cleanup.include/exec/cpu-common.h | 2 ++ include/exec/memory.h | 1 - include/hw/arm/arm.h | 1 + include/qemu-common.h | 4 +--- include/qemu/fprintf-fn.h | 16 ++++++++++++++++ target-s390x/mmu_helper.c | 2 +- 6 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 include/qemu/fprintf-fn.hinclude/exec/cpu-common.h +2
-0@@ -13,6 +13,8 @@#include "qemu/bswap.h" #include "qemu/queue.h" +#include "qemu/fprintf-fn.h" +#include "qemu/typedefs.h" /** * CPUListState: include/exec/memory.h +0
-1@@ -23,7 +23,6 @@#include <stdint.h> #include <stdbool.h> -#include "qemu-common.h" #include "exec/cpu-common.h" #ifndef CONFIG_USER_ONLY #include "exec/hwaddr.h" include/hw/arm/arm.h +1
-0@@ -14,6 +14,7 @@#include "exec/memory.h" #include "hw/irq.h" #include "qemu/notify.h" +#include "cpu.h" /* armv7m.c */ qemu_irq *armv7m_init(MemoryRegion *system_memory, int mem_size, int num_irq,include/qemu-common.h +1
-3@@ -15,6 +15,7 @@#include "qemu/compiler.h" #include "config-host.h" #include "qemu/typedefs.h" +#include "qemu/fprintf-fn.h" #if defined(__arm__) || defined(__sparc__) || defined(__mips__) || defined(__hppa__) || defined(__ia64__)#define WORDS_ALIGNED @@ -85,9 +86,6 @@# error Unknown pointer size#endif -typedef int (*fprintf_function)(FILE *f, const char *fmt, ...) -GCC_FMT_ATTR (2 ,3 ); -#ifdef _WIN32#define fsync _commit#if !defined(lseek)include/qemu/fprintf-fn.h new file +16
-0@@ -0,0 +1,16 @@ +/* +* Typedef for fprintf-alike function pointers. +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#ifndef FPRINTF_FN_H + +#include "qemu/compiler.h" +#include <stdio.h> + +typedef int (*fprintf_function)(FILE *f, const char *fmt, ...) +GCC_FMT_ATTR (2 ,3 ); + +#endif target-s390x/mmu_helper.c +0
-0
target-s390x/mmu_helper.c line 24
Quoted 9 lines
target-s390x/mmu_helper.c +1
-1@@ -17,8 +17,8 @@#include "qemu/error-report.h" #include "exec/address-spaces.h" -#include "sysemu/kvm.h" #include "cpu.h" +#include "sysemu/kvm.h" /* #define DEBUG_S390 */ /* #define DEBUG_S390_PTE */
Applied for 2.4, thanks.
Paolo