Re: [Qemu-devel] [PATCH 04/21] qom: make Object a type

2012-05-23 Thread Andreas Färber
Am 16.05.2012 10:16, schrieb Andreas Färber:
> Am 02.05.2012 13:30, schrieb Paolo Bonzini:
>> 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 
> 
> Anthony, you had Reviewed-by an earlier version of this patch but then
> did it differently in your series. Should I apply this to qom-next or is
> there some issue with it? The issue of unintended NULL .parent that I
> raised is being addressed with a followup patch.

Anthony agreed to this version on IRC so I've applied this to qom-next:
http://repo.or.cz/w/qemu/afaerber.git/shortlog/refs/heads/qom-next

Andreas

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg



Re: [Qemu-devel] [PATCH 04/21] qom: make Object a type

2012-05-16 Thread Andreas Färber
Am 02.05.2012 13:30, schrieb Paolo Bonzini:
> 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 

Anthony, you had Reviewed-by an earlier version of this patch but then
did it differently in your series. Should I apply this to qom-next or is
there some issue with it? The issue of unintended NULL .parent that I
raised is being addressed with a followup patch.

Thanks,
Andreas

> ---
>  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 597a2f6..9c49d99 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 e66d3ab..88ec417 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]);
>  }
> @@ -467,19 +461,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;
> @@ -1216,3 +1197,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)


-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg



[Qemu-devel] [PATCH 04/21] qom: make Object a type

2012-05-02 Thread Paolo Bonzini
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 
---
 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 597a2f6..9c49d99 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 e66d3ab..88ec417 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]);
 }
@@ -467,19 +461,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;
@@ -1216,3 +1197,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.9.3