From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:44469) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rdmdn-0003JV-Or for qemu-devel@nongnu.org; Thu, 22 Dec 2011 12:41:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Rdmdm-0002AJ-Pg for qemu-devel@nongnu.org; Thu, 22 Dec 2011 12:41:15 -0500 Received: from mail-iy0-f173.google.com ([209.85.210.173]:62160) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rdmdm-0002AA-K3 for qemu-devel@nongnu.org; Thu, 22 Dec 2011 12:41:14 -0500 Received: by iagj37 with SMTP id j37so15683125iag.4 for ; Thu, 22 Dec 2011 09:41:13 -0800 (PST) Message-ID: <4EF36BB4.1070405@codemonkey.ws> Date: Thu, 22 Dec 2011 11:41:08 -0600 From: Anthony Liguori MIME-Version: 1.0 References: <1324399916-21315-1-git-send-email-aliguori@us.ibm.com> <1324399916-21315-2-git-send-email-aliguori@us.ibm.com> <4EF1E094.6080500@redhat.com> <4EF1EEA4.40209@us.ibm.com> <20111222172531.GA24638@morn.localdomain> In-Reply-To: <20111222172531.GA24638@morn.localdomain> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 01/27] qom: add the base Object class List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Kevin O'Connor Cc: Paolo Bonzini , Anthony Liguori , qemu-devel@nongnu.org, Markus Armbruster On 12/22/2011 11:25 AM, Kevin O'Connor wrote: > On Wed, Dec 21, 2011 at 08:35:16AM -0600, Anthony Liguori wrote: >> On 12/21/2011 07:35 AM, Paolo Bonzini wrote: >>> What's the need for "Type"? You can use simply the TypeImpl * and drop >>> type_get_instance. Outside object.h it can be an opaque pointer. >> >> It's a bit nicer for type_register to return a handle that can later >> be unregistered (although that's not currently implemented). >> >> You could have it return TypeImpl * of course. GObject uses a >> simpler GType but they don't have the notion of a symbolic type >> name. >> >> I used a symbolic type name to avoid the problem of dependencies. >> In order to create a type in gobject, you have to reference the >> parent's GType which usually means you have to call the _get_type() >> function which acts as a singleton which registers the type. >> >> Since you have to specify the parent via a function call, you can't >> define the type in a unit-level static structure which I viewed as a >> critical requirement. > > Why not declare types with something like the following: > > TypeInfo my_device_info = { > .name = "my-device", > .parentinfo =&device_info, > .instance_size = sizeof(MyDevice), > }; > > That is, instead of looking up the TypeImpl via a string, lookup the > TypeImpl via the address of the TypeInfo. (Or possibly store a > pointer to TypeImpl in TypeInfo during registration.) > > Module order shouldn't matter - all the info needed to register the > parent is there so it can be registered during first use. The only problem with this is that if a .so implements the type, it means that you have to have a way to figure out the dependency order as you load the modules. OTOH, with the current approach, you can dlopen() all of the modules and register the types, and then when the first object is instantiated, that's when the type resolution will happen. This way, modules can be very simple instead of having to encode dependency info in a special elf section. > Indeed, > pass a TypeInfo* to object_new() and one should be able to skip the > registration step - if the type hasn't been registered the code can > detect that and automatically register it. Yes, I did think of this, the problem is you want to be able to enumerate all of the registered types before any objects may be instantiated. For instance, if you did qemu -device ? Regards, Anthony Liguori > -Kevin >