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. 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. -Kevin