qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Andreas Färber" <afaerber@suse.de>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: aliguori@us.ibm.com, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 04/25] qom: make Object a type
Date: Tue, 03 Apr 2012 14:30:23 +0200	[thread overview]
Message-ID: <4F7AED5F.6000200@suse.de> (raw)
In-Reply-To: <1333451753-3550-5-git-send-email-pbonzini@redhat.com>

Am 03.04.2012 13:15, 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.

While the patch itself looks good, we should be aware that this changes
semantics: Before this patch, lack of .parent is identical to .parent =
TYPE_OBJECT; with this patch that would become another base class.
Should be mentioned in the commit message and all TypeInfos need to be
reviewed. I don't think accidentally growing base classes is a good
idea. Maybe whitelist valid base classes in type_register_static() and
abort otherwise? Then at least we'd catch it by just running the
executables.

> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  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 ccaea7d..22f646d 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 6ff1c19..585619d 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));

Is this really safe? Before we would only copy the contents of derived
classes. Missing some explanations IMO.

> +    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;
> @@ -1233,3 +1214,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)

Thanks for moving these down.

Is there a reason not to make them static const just before
register_types()?

Andreas

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

  reply	other threads:[~2012-04-03 12:30 UTC|newest]

Thread overview: 57+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-03 11:15 [Qemu-devel] [PATCH 00/25] qdev properties final installment: push, push! Paolo Bonzini
2012-04-03 11:15 ` [Qemu-devel] [PATCH 01/25] qom: add object_class_get_parent Paolo Bonzini
2012-04-03 20:50   ` Anthony Liguori
2012-04-03 11:15 ` [Qemu-devel] [PATCH 02/25] qom: add object_child_foreach Paolo Bonzini
2012-04-03 20:51   ` Anthony Liguori
2012-04-03 11:15 ` [Qemu-devel] [PATCH 03/25] qom: add class_base_init Paolo Bonzini
2012-04-03 20:51   ` Anthony Liguori
2012-04-03 11:15 ` [Qemu-devel] [PATCH 04/25] qom: make Object a type Paolo Bonzini
2012-04-03 12:30   ` Andreas Färber [this message]
2012-04-03 13:06     ` Paolo Bonzini
2012-04-03 20:52   ` Anthony Liguori
2012-04-03 11:15 ` [Qemu-devel] [PATCH 05/25] qom: push type up to Object Paolo Bonzini
2012-04-03 12:33   ` Andreas Färber
2012-04-03 20:55   ` Anthony Liguori
2012-04-03 11:15 ` [Qemu-devel] [PATCH 06/25] qdev: fix -device foo,? Paolo Bonzini
2012-04-03 20:59   ` Anthony Liguori
2012-04-03 11:15 ` [Qemu-devel] [PATCH 07/25] qdev: use object_property_print in info qtree Paolo Bonzini
2012-04-03 12:28   ` Jan Kiszka
2012-04-03 13:05     ` Paolo Bonzini
2012-05-11 14:10       ` Andreas Färber
2012-05-16  7:40         ` Paolo Bonzini
2012-05-16  7:43           ` Paolo Bonzini
2012-04-03 21:06   ` Anthony Liguori
2012-05-10 20:58     ` Jan Kiszka
2012-05-11 11:28       ` Paolo Bonzini
2012-05-11 11:38         ` Andreas Färber
2012-04-03 11:15 ` [Qemu-devel] [PATCH 08/25] qdev: remove qdev_prop_set_defaults Paolo Bonzini
2012-04-03 21:09   ` Anthony Liguori
2012-04-03 21:43     ` Paolo Bonzini
2012-04-03 11:15 ` [Qemu-devel] [PATCH 09/25] qdev: move bus properties to a separate global Paolo Bonzini
2012-04-03 11:15 ` [Qemu-devel] [PATCH 10/25] qdev: do not propagate properties to subclasses Paolo Bonzini
2012-04-03 11:15 ` [Qemu-devel] [PATCH 11/25] qdev: pick global properties from superclasses Paolo Bonzini
2012-04-03 11:15 ` [Qemu-devel] [PATCH 12/25] qdev: factor setting of global properties Paolo Bonzini
2012-04-03 11:15 ` [Qemu-devel] [PATCH 13/25] qdev: replace bus properties with superclass properties Paolo Bonzini
2012-04-03 11:15 ` [Qemu-devel] [PATCH 14/25] qapi: add Visitor interfaces for uint*_t and int*_t Paolo Bonzini
2012-04-03 11:15 ` [Qemu-devel] [PATCH 15/25] qdev: use int32_t container for devfn property Paolo Bonzini
2012-04-03 11:15 ` [Qemu-devel] [PATCH 16/25] qdev: switch property accessors to fixed-width visitor interfaces Paolo Bonzini
2012-04-03 11:15 ` [Qemu-devel] [PATCH 17/25] qdev: remove PropertyInfo range checking Paolo Bonzini
2012-04-03 11:15 ` [Qemu-devel] [PATCH 18/25] qdev: remove qdev_prop_exists Paolo Bonzini
2012-04-03 11:15 ` [Qemu-devel] [PATCH 19/25] qom: push state up to Object Paolo Bonzini
2012-04-03 11:15 ` [Qemu-devel] [PATCH 20/25] qdev: generalize properties to Objects Paolo Bonzini
2012-04-03 11:15 ` [Qemu-devel] [PATCH 21/25] qdev: move bulk of qdev-properties.c to qom/object.c Paolo Bonzini
2012-04-03 11:15 ` [Qemu-devel] [PATCH 22/25] qom: push static properties to Object Paolo Bonzini
2012-04-03 11:15 ` [Qemu-devel] [PATCH 23/25] qom: add realized property Paolo Bonzini
2012-04-03 12:11   ` Andreas Färber
2012-04-03 13:03     ` Paolo Bonzini
2012-04-05 12:04       ` Andreas Färber
2012-04-05 12:36         ` Paolo Bonzini
2012-04-05 13:31           ` Andreas Färber
2012-04-05 14:16             ` Paolo Bonzini
2012-04-05 15:13               ` Anthony Liguori
2012-05-09 20:01   ` Igor Mammedov
2012-05-10  7:05     ` Paolo Bonzini
2012-05-10 10:01       ` Andreas Färber
2012-05-10 12:19         ` Anthony Liguori
2012-04-03 11:15 ` [Qemu-devel] [PATCH 24/25] qdev: implement qdev_init on top of realize Paolo Bonzini
2012-04-03 11:15 ` [Qemu-devel] [PATCH 25/25] qdev: split part of device_finalize to device_unrealize Paolo Bonzini

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=4F7AED5F.6000200@suse.de \
    --to=afaerber@suse.de \
    --cc=aliguori@us.ibm.com \
    --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).