QEMU Object Model
cover QEMU Object Model
Hi guys,
Before I ago all over the command handlers again, I thought it would be
a good idea to submit _early_ implemention of the two most basic types for review: QNumber and QString.
I'm a bit concerned about QNumber, because it has to allow us to drop
the current long type handling in the monitor and work right on any arch.
The way I'm thinking in doing this is to change GET_TLONG() andGET_TPHYSADDR() to receive a QNumber as parameter and work with it to return the appropriate value.
For Example:
#if TARGET_LONG_BITS == 64
#define GET_TLONG(qnum) qnumber_get_int64(qnum);
#else
#define GET_TLONG(qnum) qnumber_get_int32(qnum);
#endif
Remeber that the monitor will always work with int64_t for the
'l' argument type.
Thanks.
PATCH 1/3 Introduce qobject header file
This file contains basic definitions for the QEMU Object Model, all object implementions must include this file and add its type code in qtype_t enum.
--- qobject.h | 33 +++++++++++++++++++++++++++++++++ 1 files changed, 33 insertions(+), 0 deletions(-) create mode 100644 qobject.h
qobject.h new file +33 -0
@@ -0,0 +1,33 @@ +/* +* QEMU Object Model. +* +* Copyright (C) 2009 Red Hat Inc. +* +* Authors: +* Luiz Capitulino <[email protected]> +* +* Based on ideas by Avi Kivity <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2. See +* the COPYING file in the top-level directory. +*/ +#ifndef QOBJECT_H +#define QOBJECT_H + +typedef enum { +QTYPE_NONE , +}qtype_t ; + +struct QObject ; + +typedef struct QType { +qtype_t code; +struct QObject *(*clone)(const struct QObject *); +void (*destroy)(struct QObject *); +}QType ; + +typedef struct QObject { +QType *type; +}QObject ; + +#endif /* QOBJECT_H */
Signature · 1 line
1.6.4.rc3.12.gdf73a
[Qemu-devel] Re: [PATCH 1/3] Introduce qobject header file
Quoted 6 lines · Luiz Capitulino
This file contains basic definitions for the QEMU Object Model, all object implementions must include this file and add its type code in
qtype_tenum.
qobject.h line 24
Quoted 9 lines
qobject.h new file +9
-0+ +typedef enum { +QTYPE_NONE , +}qtype_t ; + +struct QObject ; + +typedef struct QType { + qtype_t code;
Is this really needed? You can check if an object is a particular type by checking its ->type agains whatever you're interested in. Of course you should refrain from doing so unless there's no choice.
Signature · 1 line
error compiling committee.c: too many arguments to function
[Qemu-devel] Re: [PATCH 1/3] Introduce qobject header file
Quoted 6 lines · On Thu, 06 Aug 2009 17:02:48 +0300 Avi Kivity <[email protected]> wrote:
Quoted 5 lines · Luiz Capitulino
This file contains basic definitions for the QEMU Object Model, all object implementions must include this file and add its type code in
qtype_tenum.
Quoted 14 lines
qobject.h line 24
Quoted 10 lines
qobject.h new file +9
-0+ +typedef enum { +QTYPE_NONE , +}qtype_t ; + +struct QObject ; + +typedef struct QType { + qtype_t code;Is this really needed? You can check if an object is a particular type by checking its ->type agains whatever you're interested in. Of course you should refrain from doing so unless there's no choice.
Each QType definition is private to each type's module, I would have
to make them public then.
Re: [Qemu-devel] [PATCH 1/3] Introduce qobject header file
In reply to Luiz CapitulinoQuoted 25 lines · Luiz Capitulino
This file contains basic definitions for the QEMU Object Model, all object implementions must include this file and add its type code in
qtype_tenum.Signed-off-by Luiz Capitulino <[email protected]>--- qobject.h | 33 +++++++++++++++++++++++++++++++++ 1 files changed, 33 insertions(+), 0 deletions(-) create mode 100644 qobject.hqobject.h new file +9
-0@@ -0,0 +1,33 @@ +/* +* QEMU Object Model. +* +* Copyright (C) 2009 Red Hat Inc. +* +* Authors: +* Luiz Capitulino <[email protected]> +* +* Based on ideas by Avi Kivity <[email protected]>
qobject.h line 19
Quoted 10 lines
qobject.h new file +10
-0+* +* This work is licensed under the terms of the GNU GPL, version 2. See +* the COPYING file in the top-level directory. +*/ +#ifndef QOBJECT_H +#define QOBJECT_H + +typedef enum { +QTYPE_NONE , +}qtype_t ;
Please do not use _t suffix.
Quoted 15 lines
qobject.h new file +14
-0+ +struct QObject ; + +typedef struct QType { +qtype_t code; +struct QObject *(*clone)(const struct QObject *); +void (*destroy)(struct QObject *); +}QType ; + +typedef struct QObject { +QType *type; +}QObject ; + +#endif /* QOBJECT_H */
Signature · 1 line
mailto:[email protected]
PATCH 2/3 Introduce QString data type
In reply to Luiz Capitulino--- Makefile | 2 +- qobject.h | 1 + qstring.c | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ qstring.h | 17 +++++++++++ 4 files changed, 108 insertions(+), 1 deletions(-) create mode 100644 qstring.c create mode 100644 qstring.h
Makefile +1 -1
@@ -104,7 +104,7 @@ obj-y += buffered_file.o migration.o migration-tcp.o net.o qemu-sockets.o obj-y += qemu-char.o aio.o net-checksum.o savevm.o obj-y += msmouse.o ps2.o obj-y += qdev.o qdev-properties.o ssi.o -obj-y += qdict.o +obj-y += qdict.o qstring.o obj-$(CONFIG_BRLAPI) += baum.o
qobject.h +1 -0
@@ -16,6 +16,7 @@typedef enum {QTYPE_NONE , +QTYPE_QSTRING , }qtype_t ;struct QObject ;
qstring.c new file +89 -0
89 lines not on this page · raw message
qstring.h new file +17 -0
@@ -0,0 +1,17 @@ +#ifndef QSTRING_H +#define QSTRING_H + +#include <stddef.h> +#include "qobject.h" + +typedef struct QString { +QObject base; +char *string; +}QString ; + +QString *qstring_from_str (const char *str); +char *qstring_to_str (const QString *qstring); +size_t qstring_size (const QString *qstring); +void qstring_destroy (QString *qstring); + +#endif /* QSTRING_H */
Signature · 1 line
1.6.4.rc3.12.gdf73a
PATCH 3/3 Introduce QNumber data type
In reply to Luiz Capitulino--- Makefile | 2 +- qnumber.c | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ qnumber.h | 20 +++++++++++ qobject.h | 1 + 4 files changed, 130 insertions(+), 1 deletions(-) create mode 100644 qnumber.c create mode 100644 qnumber.h
Makefile +1 -1
@@ -104,7 +104,7 @@ obj-y += buffered_file.o migration.o migration-tcp.o net.o qemu-sockets.o obj-y += qemu-char.o aio.o net-checksum.o savevm.o obj-y += msmouse.o ps2.o obj-y += qdev.o qdev-properties.o ssi.o -obj-y += qdict.o qstring.o +obj-y += qdict.o qstring.o qnumber.o obj-$(CONFIG_BRLAPI) += baum.o
qnumber.c new file +108 -0
108 lines not on this page · raw message
qnumber.h new file +20 -0
@@ -0,0 +1,20 @@ +#ifndef QNUMBER_H +#define QNUMBER_H + +#include "qobject.h" +#include <stdint.h> + +typedef struct QNumber { +QObject base; +union { +int n_int; +int64_t n_int64; + } number; +}QNumber ; + +QNumber *qnumber_from_int (int value); +QNumber *qnumber_from_int64 (int64_t value); +void qnumber_destroy (QNumber *qnum); +int qnumber_to_int (const QNumber *qnum); + +#endif /* QNUMBER_H */
qobject.h +1 -0
@@ -17,6 +17,7 @@typedef enum {QTYPE_NONE ,QTYPE_QSTRING , +QTYPE_QNUMBER , }qtype_t ;struct QObject ;
Signature · 1 line
1.6.4.rc3.12.gdf73a
[Qemu-devel] Re: [PATCH 3/3] Introduce QNumber data type
qnumber.h line 13
Quoted 9 lines · Luiz Capitulino
qnumber.h new file +8
-0+ +typedef struct QNumber { +QObject base; +union { +int n_int; +int64_t n_int64; + } number; +}QNumber ;
Why not have an int64_t exclusively?
Also, we need floating point support. So probably need to split this into QInt and QFloat.
Signature · 1 line
error compiling committee.c: too many arguments to function
Re: [Qemu-devel] Re: [PATCH 3/3] Introduce QNumber data type
Quoted 13 lines · Luiz Capitulino
qnumber.h line 13
Quoted 9 lines
qnumber.h new file +8
-0+ +typedef struct QNumber { +QObject base; +union { +int n_int; +int64_t n_int64; + } number; +}QNumber ;Why not have an
int64_texclusively?
Quoted 2 lines
Also, we need floating point support. So probably need to split this into QInt and QFloat.
Aw you sure all this won't clash with some Qt class if some fold tries to mix both?
Now, I use the BeAPI so I don't really care, but still.
And I still wonder why not just use a real OO language instead of faking.
François.
Re: [Qemu-devel] Re: [PATCH 3/3] Introduce QNumber data type
Quoted 7 lines · François Revol
Quoted 3 lines
Also, we need floating point support. So probably need to split this into QInt and QFloat.
Aw you sure all this won't clash with some Qt class if some fold tries to mix both?
We can address that when it happens.
Quoted 3 lines
And I still wonder why not just use a real OO language instead of faking.
I'm all for it.
Signature · 1 line
error compiling committee.c: too many arguments to function
[Qemu-devel] Re: [PATCH 3/3] Introduce QNumber data type
In reply to Avi KivityQuoted 13 lines · On Thu, 06 Aug 2009 17:04:50 +0300 Avi Kivity <[email protected]> wrote:
qnumber.h line 13
Quoted 9 lines · Luiz Capitulino
qnumber.h new file +8
-0+ +typedef struct QNumber { +QObject base; +union { +int n_int; +int64_t n_int64; + } number; +}QNumber ;Why not have an
int64_texclusively?
Quoted 2 lines
Also, we need floating point support. So probably need to split this into QInt and QFloat.
Right, we can have QInt with int64_t.
But the monitor doesn't use floats, so QFloat doesn't seem
needed, at least for now.
[Qemu-devel] Re: [PATCH 3/3] Introduce QNumber data type
In reply to Avi KivityQuoted 12 lines · On Thu, 06 Aug 2009 17:04:50 +0300 Avi Kivity <[email protected]> wrote:
qnumber.h line 13
Quoted 9 lines · Luiz Capitulino
qnumber.h new file +8
-0+ +typedef struct QNumber { +QObject base; +union { +int n_int; +int64_t n_int64; + } number; +}QNumber ;Why not have an
int64_texclusively?
Something I was wondering: why does get_expr() use int64_t
instead of uint64_t?
As far as I can understand it uses strtoull() and strtoul() to
convert from the user's string and command handlers use 64-bits values only for addresses and (signed) 32-bits for anything else.
We are doing some int64_t to uint64_t conversions today...
Quoted 7 lines · Luiz Capitulino
#if
TARGET_LONG_BITS== 64
#defineGET_TLONG(qnum)qnumber_get_int64(qnum);
#else
#defineGET_TLONG(qnum)qnumber_get_int32(qnum);
#endif
#define GET_TLONG(qnum) ((target_ulong_t)qnumber_get_uint64(qnum))
That doesn't warn on overflow though.
Signature · 1 line
error compiling committee.c: too many arguments to function