Patchwork [RFC,v2,1/7] hw/irq: move struct IRQState to irq.h

login
register
mail settings
Submitter liguang
Date April 5, 2013, 4:28 a.m.
Message ID <1365136091-26148-2-git-send-email-lig.fnst@cn.fujitsu.com>
Download mbox | patch
Permalink /patch/234032/
State New
Headers show

Comments

liguang - April 5, 2013, 4:28 a.m.
define struct IRQState in irq.c bring in
a annoying result, if you want dereference of
IRQState's member like opaque outside of
irq.c, compiler will complain:
"error: dereferencing pointer to incomplete type"

Signed-off-by: liguang <lig.fnst@cn.fujitsu.com>
---
 hw/irq.c |    6 ------
 hw/irq.h |    6 ++++++
 2 files changed, 6 insertions(+), 6 deletions(-)
Peter Maydell - April 5, 2013, 8:34 a.m.
On 5 April 2013 05:28, liguang <lig.fnst@cn.fujitsu.com> wrote:
> define struct IRQState in irq.c bring in
> a annoying result, if you want dereference of
> IRQState's member like opaque outside of
> irq.c, compiler will complain:
> "error: dereferencing pointer to incomplete type"

No, this is deliberate -- it's an opaque type which should
only be used inside irq.c. If you think you need to dereference
it you're probably doing something wrong.

thanks
-- PMM
liguang - April 5, 2013, 8:39 a.m.
在 2013-04-05五的 09:34 +0100,Peter Maydell写道:
> On 5 April 2013 05:28, liguang <lig.fnst@cn.fujitsu.com> wrote:
> > define struct IRQState in irq.c bring in
> > a annoying result, if you want dereference of
> > IRQState's member like opaque outside of
> > irq.c, compiler will complain:
> > "error: dereferencing pointer to incomplete type"
> 
> No, this is deliberate -- it's an opaque type which should
> only be used inside irq.c. If you think you need to dereference
> it you're probably doing something wrong.
> 

 Yes, you're right, it's only a suggestion for
some hacking conditions.

Patch

diff --git a/hw/irq.c b/hw/irq.c
index 2078542..100890f 100644
--- a/hw/irq.c
+++ b/hw/irq.c
@@ -24,12 +24,6 @@ 
 #include "qemu-common.h"
 #include "hw/irq.h"
 
-struct IRQState {
-    qemu_irq_handler handler;
-    void *opaque;
-    int n;
-};
-
 void qemu_set_irq(qemu_irq irq, int level)
 {
     if (!irq)
diff --git a/hw/irq.h b/hw/irq.h
index 610e6b7..7ae152d 100644
--- a/hw/irq.h
+++ b/hw/irq.h
@@ -7,6 +7,12 @@  typedef struct IRQState *qemu_irq;
 
 typedef void (*qemu_irq_handler)(void *opaque, int n, int level);
 
+struct IRQState {
+    qemu_irq_handler handler;
+    void *opaque;
+    int n;
+};
+
 void qemu_set_irq(qemu_irq irq, int level);
 
 static inline void qemu_irq_raise(qemu_irq irq)