From: "Andreas Färber" <afaerber@suse.de>
To: qemu-devel@nongnu.org
Cc: "Paolo Bonzini" <pbonzini@redhat.com>,
"Andreas Färber" <afaerber@suse.de>,
"Anthony Liguori" <anthony@codemonkey.ws>
Subject: [Qemu-devel] [PATCH 05/22] qom: Make Object a type
Date: Mon, 18 Jun 2012 15:58:57 +0200 [thread overview]
Message-ID: <1340027954-19045-6-git-send-email-afaerber@suse.de> (raw)
In-Reply-To: <1340027954-19045-1-git-send-email-afaerber@suse.de>
From: Paolo Bonzini <pbonzini@redhat.com>
Right now the base Object class has a special NULL type. Change this so
that we will be able to add class_init and class_base_init callbacks.
To do this, remove some special casing of ObjectClass that is not really
necessary.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
include/qemu/object.h | 2 +-
qom/object.c | 59 +++++++++++++++++++++++++------------------------
2 files changed, 31 insertions(+), 30 deletions(-)
diff --git a/include/qemu/object.h b/include/qemu/object.h
index 3c29c17..ff5444f 100644
--- a/include/qemu/object.h
+++ b/include/qemu/object.h
@@ -33,7 +33,7 @@ typedef struct TypeInfo TypeInfo;
typedef struct InterfaceClass InterfaceClass;
typedef struct InterfaceInfo InterfaceInfo;
-#define TYPE_OBJECT NULL
+#define TYPE_OBJECT "object"
/**
* SECTION:object.h
diff --git a/qom/object.c b/qom/object.c
index 36379a1..dac9de5 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -210,7 +210,7 @@ static void type_class_interface_init(TypeImpl *ti, InterfaceImpl *iface)
static void type_initialize(TypeImpl *ti)
{
- size_t class_size = sizeof(ObjectClass);
+ TypeImpl *parent;
int i;
if (ti->class) {
@@ -221,30 +221,24 @@ static void type_initialize(TypeImpl *ti)
ti->instance_size = type_object_get_size(ti);
ti->class = g_malloc0(ti->class_size);
- ti->class->type = ti;
-
- if (type_has_parent(ti)) {
- TypeImpl *parent = type_get_parent(ti);
+ parent = type_get_parent(ti);
+ if (parent) {
type_initialize(parent);
- class_size = parent->class_size;
g_assert(parent->class_size <= ti->class_size);
+ memcpy(ti->class, parent->class, parent->class_size);
+ }
- memcpy((void *)ti->class + sizeof(ObjectClass),
- (void *)parent->class + sizeof(ObjectClass),
- parent->class_size - sizeof(ObjectClass));
+ ti->class->type = ti;
- while (parent) {
- if (parent->class_base_init) {
- parent->class_base_init(ti->class, ti->class_data);
- }
- parent = type_get_parent(parent);
+ while (parent) {
+ if (parent->class_base_init) {
+ parent->class_base_init(ti->class, ti->class_data);
}
+ parent = type_get_parent(parent);
}
- memset((void *)ti->class + class_size, 0, ti->class_size - class_size);
-
for (i = 0; i < ti->num_interfaces; i++) {
type_class_interface_init(ti, &ti->interfaces[i]);
}
@@ -477,19 +471,6 @@ Object *object_dynamic_cast(Object *obj, const char *typename)
}
-static void register_types(void)
-{
- static TypeInfo interface_info = {
- .name = TYPE_INTERFACE,
- .instance_size = sizeof(Interface),
- .abstract = true,
- };
-
- type_interface = type_register_static(&interface_info);
-}
-
-type_init(register_types)
-
Object *object_dynamic_cast_assert(Object *obj, const char *typename)
{
Object *inst;
@@ -1243,3 +1224,23 @@ void object_property_add_str(Object *obj, const char *name,
property_release_str,
prop, errp);
}
+
+static void register_types(void)
+{
+ static TypeInfo interface_info = {
+ .name = TYPE_INTERFACE,
+ .instance_size = sizeof(Interface),
+ .abstract = true,
+ };
+
+ static TypeInfo object_info = {
+ .name = TYPE_OBJECT,
+ .instance_size = sizeof(Object),
+ .abstract = true,
+ };
+
+ type_interface = type_register_static(&interface_info);
+ type_register_static(&object_info);
+}
+
+type_init(register_types)
--
1.7.7
next prev parent reply other threads:[~2012-06-18 14:00 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-18 13:58 [Qemu-devel] [PULL] qom-next queue, second batch: QBus, API additions and cleanups Andreas Färber
2012-06-18 13:58 ` [Qemu-devel] [PATCH 01/22] qom: Add object_class_get_parent() Andreas Färber
2012-06-18 13:58 ` [Qemu-devel] [PATCH 02/22] qom: Introduce object_property_is_{child, link}() Andreas Färber
2012-06-18 13:58 ` [Qemu-devel] [PATCH 03/22] qom: Add object_child_foreach() Andreas Färber
2012-06-18 13:58 ` [Qemu-devel] [PATCH 04/22] qom: Add class_base_init Andreas Färber
2012-06-18 13:58 ` Andreas Färber [this message]
2012-06-18 13:58 ` [Qemu-devel] [PATCH 06/22] qom: Drop type_register_static_alias() macro Andreas Färber
2012-06-18 13:58 ` [Qemu-devel] [PATCH 07/22] qom: Assert that public types have a non-NULL parent field Andreas Färber
2012-06-18 13:59 ` [Qemu-devel] [PATCH 08/22] m48t59: Rename "type" property to "model" Andreas Färber
2012-06-18 13:59 ` [Qemu-devel] [PATCH 09/22] arm_l2x0: Rename "type" property to "cache-type" Andreas Färber
2012-06-18 13:59 ` [Qemu-devel] [PATCH 10/22] qdev: Push "type" property up to Object Andreas Färber
2012-06-18 13:59 ` [Qemu-devel] [PATCH 11/22] qdev: Move bus properties to a separate global Andreas Färber
2012-06-18 13:59 ` [Qemu-devel] [PATCH 12/22] qdev: Move bus properties to abstract superclasses Andreas Färber
2012-06-18 13:59 ` [Qemu-devel] [PATCH 13/22] qdev: Clean up global properties Andreas Färber
2012-06-18 13:59 ` [Qemu-devel] [PATCH 14/22] qdev: Remove qdev_prop_set_defaults Andreas Färber
2012-06-18 13:59 ` [Qemu-devel] [PATCH 15/22] qdev: Use wrapper for qdev_get_path Andreas Färber
2012-06-18 13:59 ` [Qemu-devel] [PATCH 16/22] qdev: Move SysBus initialization to sysbus.c Andreas Färber
2012-06-18 13:59 ` [Qemu-devel] [PATCH 17/22] qdev: Convert busses to QEMU Object Model Andreas Färber
2012-06-18 13:59 ` [Qemu-devel] [PATCH 18/22] qdev: Connect busses with their parent devices Andreas Färber
2012-06-18 13:59 ` [Qemu-devel] [PATCH 19/22] qbus: Make child devices links Andreas Färber
2012-06-18 13:59 ` [Qemu-devel] [PATCH 20/22] qbus: Initialize in standard way Andreas Färber
2012-06-18 13:59 ` [Qemu-devel] [PATCH 21/22] qdev: Remove qdev_prop_exists() Andreas Färber
2012-06-18 13:59 ` [Qemu-devel] [PATCH 22/22] qom: Push error reporting to object_property_find() Andreas Färber
2012-06-20 13:09 ` [Qemu-devel] [PULL] qom-next queue, second batch: QBus, API additions and cleanups Anthony Liguori
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1340027954-19045-6-git-send-email-afaerber@suse.de \
--to=afaerber@suse.de \
--cc=anthony@codemonkey.ws \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).