Signed-off-by: Philippe Mathieu-Daudé <f4...@amsat.org> --- include/qom/object.h | 3 +++ qom/object.c | 18 ++++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/include/qom/object.h b/include/qom/object.h index dc73d59660..5d6e8795d4 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -428,6 +428,8 @@ struct Object * TypeInfo: * @name: The name of the type. * @parent: The name of the parent type. + * @aliases: A list of alias names for the type. This should point to a static + * array that's terminated with a zero filled element. * @instance_size: The size of the object (derivative of #Object). If * @instance_size is 0, then the size of the object will be the size of the * parent object. @@ -468,6 +470,7 @@ struct TypeInfo { const char *name; const char *parent; + const char **aliases; size_t instance_size; void (*instance_init)(Object *obj); diff --git a/qom/object.c b/qom/object.c index c58c52d518..c532a8aa65 100644 --- a/qom/object.c +++ b/qom/object.c @@ -83,10 +83,15 @@ static GHashTable *type_table_get(void) static bool enumerating_types; -static void type_table_add(TypeImpl *ti) +static void type_table_add_with_key(TypeImpl *ti, const char *key_name) { assert(!enumerating_types); - g_hash_table_insert(type_table_get(), (void *)ti->name, ti); + g_hash_table_insert(type_table_get(), (void *)key_name, ti); +} + +static void type_table_add(TypeImpl *ti) +{ + type_table_add_with_key(ti, ti->name); } static TypeImpl *type_table_lookup(const char *name) @@ -137,6 +142,15 @@ static TypeImpl *type_register_internal(const TypeInfo *info) ti = type_new(info); type_table_add(ti); + + if (info->aliases) { + int i; + + for (i = 0; info->aliases[i]; i++) { + type_table_add_with_key(ti, info->aliases[i]); + } + } + return ti; } -- 2.15.1