Skip to contentSkip to conversation

QEMU Object Model

RFC PATCH In review Luiz Capitulino 4 participants 13 messages Aug 6, 2009 Kbuild

lore
Share & tools
lore
#0 lore raw

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() and
GET_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.

#1 lore raw

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
new file mode 100644
index 0000000..b70e669
@@ -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
#2 lore raw

[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_t enum.

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
#3 lore raw

[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_t enum.

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.

#4 lore raw

Re: [Qemu-devel] [PATCH 1/3] Introduce qobject header file

In reply to Luiz Capitulino
Quoted 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_t enum.

---
 qobject.h |   33 +++++++++++++++++++++++++++++++++
 1 files changed, 33 insertions(+), 0 deletions(-)
 create mode 100644 qobject.h
qobject.h new file +9 -0
new file mode 100644
index 0000000..b70e669
@@ -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]
#5 lore raw

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
index 2ce539f..9e3faec 100644
@@ -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
index b70e669..d3378b1 100644
@@ -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
new file mode 100644
index 0000000..1856a12
@@ -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
#6 lore raw

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
index 9e3faec..c4cbbaf 100644
@@ -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
new file mode 100644
index 0000000..918637d
@@ -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
index d3378b1..20b9a99 100644
@@ -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
#7 lore raw

[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
#8 lore raw

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_t exclusively?

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.

#9 lore raw

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
#10 lore raw

[Qemu-devel] Re: [PATCH 3/3] Introduce QNumber data type

In reply to Avi Kivity
Quoted 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_t exclusively?

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.

#11 lore raw

[Qemu-devel] Re: [PATCH 3/3] Introduce QNumber data type

In reply to Avi Kivity
Quoted 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_t exclusively?

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...

#12 lore raw
In reply to Luiz Capitulino
Quoted 7 lines · Luiz Capitulino

#if TARGET_LONG_BITS == 64
#define GET_TLONG(qnum) qnumber_get_int64(qnum);
#else
#define GET_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