On 12/03/21 10:31, Claudio Fontana wrote:
Hello Paolo and all,

while debugging a class init ordering issue, I noticed that

_all_ class init functions for all types registered in the QEMU QOM are called 
in select_machine().
Expected?

In particular it happens here:

static MachineClass *select_machine(void)
{
     GSList *machines = object_class_get_list(TYPE_MACHINE, false);


object_class_get_list() ->
   object_class_foreach() ->
     g_hash_table_foreach() ->
       object_class_foreach_tramp ->
         type_initialize(type);

Is this really desired? It looks suspect to me.

It is not a problem because class_init should be idempotent. Changing QEMU to not do this would not be impossible, but most likely not worth the effort. To do this, I think one would have to reimplement all of object_class_dynamic_cast to operate on TypeInfos (so for example walk all interfaces in the type info instead of using class->interfaces).

If not here, where should be the right place, for example, for CPU class inits 
to be called?

The first time they're used, upon a call to one of object_new, object_initialize, object_class_get_list or object_class_foreach.

At the very least I would put a comment there around the beginning of 
select_machine() saying:

/* all types, all classes in QOM are initialized here, as a result of the 
object_class_get_list call */

No, it's just a side effect that is not (or should not) be visible.

Paolo


Reply via email to