qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Anthony Liguori <anthony@codemonkey.ws>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: peter.maydell@linaro.org, aliguori@us.ibm.com,
	qemu-devel@nongnu.org,
	"Peter A. G. Crosthwaite" <peter.crosthwaite@petalogix.com>,
	paul@codesourcery.com, edgar.iglesias@gmail.com,
	"Andreas Färber" <afaerber@suse.de>,
	john.williams@petalogix.com, avi@redhat.com
Subject: Re: [Qemu-devel] [RFC v0 5/8] object: make interfaces concrete
Date: Wed, 13 Jun 2012 08:30:44 -0500	[thread overview]
Message-ID: <4FD89604.7050606@codemonkey.ws> (raw)
In-Reply-To: <4FD88F4B.20603@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 1249 bytes --]

On 06/13/2012 08:02 AM, Paolo Bonzini wrote:
> Il 13/06/2012 14:59, Andreas Färber ha scritto:
>> Ouch! One can argue that's still not recursive, but what matters more
>> this borks Anthony's in-place object_initialize() concept.
>>
>> Two solutions come to mind:
>> * allocate the interfaces as part of object_new() beyond instance_size
>
> That won't work if you initialize in place, because you cannot allocate
> the room for the interface.  It is possible to put Interface objects
> explicitly in the class, and pass an offset when registering the type so
> that they can be initialized in place.
>
> But I still think we're fighting windmills...

There's no problem in my mind with allocating interfaces on the heap.  in-place 
initialization is a readability thing, it's not a memory management thing.  It's 
so you can see that:

struct PIIX3 {
   ...

   RTCState rtc;
   APICState *apic;
};

'rtc' is a child and 'apic' is a link.

Anyway, I don't like the idea of making interfaces concrete.  That means that a 
user could directly instantiate an interface which doesn't make a lot of sense.

Here's a different solution.  This has not been even compile tested but I think 
the concept is sound.

Regards,

Anthony Liguori

>
> Paolo
>
>


[-- Attachment #2: 0001-qom-allow-interfaces-to-be-created-while-abstract-du.patch --]
[-- Type: text/x-patch, Size: 2861 bytes --]

>From c7e0661bd261ac4919dca0e3a5dd78d3871c3292 Mon Sep 17 00:00:00 2001
From: Anthony Liguori <aliguori@us.ibm.com>
Date: Wed, 13 Jun 2012 08:29:30 -0500
Subject: [PATCH] qom: allow interfaces to be created while abstract during
 object initialization

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
 qom/object.c |   23 ++++++++++++++++++-----
 1 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/qom/object.c b/qom/object.c
index 6f839ad..1a436d8 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -73,6 +73,8 @@ typedef struct Interface
 
 static Type type_interface;
 
+static Object *object_new_with_type_full(Type type, bool concrete_only);
+
 static GHashTable *type_table_get(void)
 {
     static GHashTable *type_table;
@@ -250,7 +252,7 @@ static void object_interface_init(Object *obj, InterfaceImpl *iface)
     TypeImpl *ti = iface->type;
     Interface *iface_obj;
 
-    iface_obj = INTERFACE(object_new(ti->name));
+    iface_obj = INTERFACE(object_new_with_type_full(ti, false));
     iface_obj->obj = obj;
 
     obj->interfaces = g_slist_prepend(obj->interfaces, iface_obj);
@@ -273,7 +275,8 @@ static void object_init_with_type(Object *obj, TypeImpl *ti)
     }
 }
 
-void object_initialize_with_type(void *data, TypeImpl *type)
+static void object_initialize_with_type_full(void *data, TypeImpl *type,
+                                             bool concrete_only)
 {
     Object *obj = data;
 
@@ -281,7 +284,7 @@ void object_initialize_with_type(void *data, TypeImpl *type)
     type_initialize(type);
 
     g_assert(type->instance_size >= sizeof(Object));
-    g_assert(type->abstract == false);
+    g_assert(!concrete_only || type->abstract == false);
 
     memset(obj, 0, type->instance_size);
     obj->class = type->class;
@@ -289,6 +292,11 @@ void object_initialize_with_type(void *data, TypeImpl *type)
     object_init_with_type(obj, type);
 }
 
+void object_initialize_with_type(void *data, TypeImpl *type)
+{
+    object_initialize_with_type_full(data, type, false);
+}
+
 void object_initialize(void *data, const char *typename)
 {
     TypeImpl *type = type_get_by_name(typename);
@@ -362,7 +370,7 @@ void object_finalize(void *data)
     g_assert(obj->ref == 0);
 }
 
-Object *object_new_with_type(Type type)
+static Object *object_new_with_type_full(Type type, bool concrete_only)
 {
     Object *obj;
 
@@ -370,12 +378,17 @@ Object *object_new_with_type(Type type)
     type_initialize(type);
 
     obj = g_malloc(type->instance_size);
-    object_initialize_with_type(obj, type);
+    object_initialize_with_type_full(obj, type, concrete_only);
     object_ref(obj);
 
     return obj;
 }
 
+Object *object_new_with_type(Type type)
+{
+    return object_new_with_type_full(type, true);
+}
+
 Object *object_new(const char *typename)
 {
     TypeImpl *ti = type_get_by_name(typename);
-- 
1.7.5.4


  reply	other threads:[~2012-06-13 13:31 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-13  9:38 [Qemu-devel] [RFC v0 0/8] QOMify AXI stream for Xilinx AXI ethernet/DMA Peter A. G. Crosthwaite
2012-06-13  9:38 ` [Qemu-devel] [RFC v0 1/8] qom: revamp interfaces Peter A. G. Crosthwaite
2012-06-13  9:38 ` [Qemu-devel] [RFC v0 2/8] xilinx: remove PROP_PTR properties Peter A. G. Crosthwaite
2012-06-13  9:38 ` [Qemu-devel] [RFC v0 3/8] xilinx_axidma: Added missing TypeInfo Peter A. G. Crosthwaite
2012-06-13 10:05   ` Paolo Bonzini
2012-06-13  9:38 ` [Qemu-devel] [RFC v0 4/8] object: create default canonical paths for orphans Peter A. G. Crosthwaite
2012-06-13 10:08   ` Paolo Bonzini
2012-06-13  9:38 ` [Qemu-devel] [RFC v0 5/8] object: make interfaces concrete Peter A. G. Crosthwaite
2012-06-13 10:03   ` Paolo Bonzini
2012-06-13 10:28     ` Andreas Färber
2012-06-13 10:42       ` Paolo Bonzini
2012-06-13 12:59         ` Andreas Färber
2012-06-13 13:02           ` Paolo Bonzini
2012-06-13 13:30             ` Anthony Liguori [this message]
2012-06-13 13:33               ` Paolo Bonzini
2012-06-13 13:36                 ` Anthony Liguori
2012-06-13 13:38                   ` Paolo Bonzini
2012-06-13 13:50                     ` Anthony Liguori
2012-06-13 20:22                       ` Edgar E. Iglesias
2012-06-13  9:38 ` [Qemu-devel] [RFC v0 6/8] xilinx dont cast to interface types with links Peter A. G. Crosthwaite
2012-06-13 10:41   ` Paolo Bonzini
2012-06-13 10:55     ` Avi Kivity
2012-06-13 10:59       ` Paolo Bonzini
2012-06-13 11:02         ` Avi Kivity
2012-06-13 11:05           ` Paolo Bonzini
2012-06-13 11:08             ` Avi Kivity
2012-06-13 13:55     ` Anthony Liguori
2012-06-13  9:38 ` [Qemu-devel] [RFC v0 7/8] petalogix_ml605_mmu: fixed qdev create for dma Peter A. G. Crosthwaite
2012-06-13  9:38 ` [Qemu-devel] [RFC v0 8/8] axidma: renamed interconnect to axi-stream Peter A. G. Crosthwaite

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=4FD89604.7050606@codemonkey.ws \
    --to=anthony@codemonkey.ws \
    --cc=afaerber@suse.de \
    --cc=aliguori@us.ibm.com \
    --cc=avi@redhat.com \
    --cc=edgar.iglesias@gmail.com \
    --cc=john.williams@petalogix.com \
    --cc=paul@codesourcery.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.crosthwaite@petalogix.com \
    --cc=peter.maydell@linaro.org \
    --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).