Introduce the TypeInfo::registerable() callback to allow
runtime decision on whether register a QOM type or not.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
include/qom/object.h | 1 +
qom/object.c | 4 ++++
qom/trace-events | 1 +
3 files changed, 6 insertions(+)
diff --git a/include/qom/object.h b/include/qom/object.h
index 9192265db76..f046791f60c 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -476,6 +476,7 @@ struct TypeInfo
{
const char *name;
const char *parent;
+ bool (*registerable)(void);
size_t instance_size;
size_t instance_align;
diff --git a/qom/object.c b/qom/object.c
index 01618d06bd8..c62b7fd1695 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -168,6 +168,10 @@ static TypeImpl *type_register_internal(const TypeInfo *info)
fprintf(stderr, "Registering '%s' with illegal type name\n", info->name);
abort();
}
+ if (info->registerable && !info->registerable()) {
+ trace_object_register_skipped(info->name);
+ return NULL;
+ }
ti = type_new(info);
diff --git a/qom/trace-events b/qom/trace-events
index b2e9f4a7127..29af95d8507 100644
--- a/qom/trace-events
+++ b/qom/trace-events
@@ -3,3 +3,4 @@
# object.c
object_dynamic_cast_assert(const char *type, const char *target, const char *file, int line, const char *func) "%s->%s (%s:%d:%s)"
object_class_dynamic_cast_assert(const char *type, const char *target, const char *file, int line, const char *func) "%s->%s (%s:%d:%s)"
+object_register_skipped(const char *type) "Not registering '%s' type"
--
2.47.1
On 3/5/25 08:12, Philippe Mathieu-Daudé wrote: > Introduce theTypeInfo::registerable() callback to allow > runtime decision on whether register a QOM type or not. > > Signed-off-by: Philippe Mathieu-Daudé<philmd@linaro.org> > --- > include/qom/object.h | 1 + > qom/object.c | 4 ++++ > qom/trace-events | 1 + > 3 files changed, 6 insertions(+) Reviewed-by: Richard Henderson <richard.henderson@linaro.org> r~
On 3/5/25 08:12, Philippe Mathieu-Daudé wrote:
> Introduce the TypeInfo::registerable() callback to allow
> runtime decision on whether register a QOM type or not.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
> include/qom/object.h | 1 +
> qom/object.c | 4 ++++
> qom/trace-events | 1 +
> 3 files changed, 6 insertions(+)
>
> diff --git a/include/qom/object.h b/include/qom/object.h
> index 9192265db76..f046791f60c 100644
> --- a/include/qom/object.h
> +++ b/include/qom/object.h
> @@ -476,6 +476,7 @@ struct TypeInfo
> {
> const char *name;
> const char *parent;
> + bool (*registerable)(void);
>
> size_t instance_size;
> size_t instance_align;
> diff --git a/qom/object.c b/qom/object.c
> index 01618d06bd8..c62b7fd1695 100644
> --- a/qom/object.c
> +++ b/qom/object.c
> @@ -168,6 +168,10 @@ static TypeImpl *type_register_internal(const TypeInfo *info)
> fprintf(stderr, "Registering '%s' with illegal type name\n", info->name);
> abort();
> }
> + if (info->registerable && !info->registerable()) {
> + trace_object_register_skipped(info->name);
> + return NULL;
> + }
>
> ti = type_new(info);
>
> diff --git a/qom/trace-events b/qom/trace-events
> index b2e9f4a7127..29af95d8507 100644
> --- a/qom/trace-events
> +++ b/qom/trace-events
> @@ -3,3 +3,4 @@
> # object.c
> object_dynamic_cast_assert(const char *type, const char *target, const char *file, int line, const char *func) "%s->%s (%s:%d:%s)"
> object_class_dynamic_cast_assert(const char *type, const char *target, const char *file, int line, const char *func) "%s->%s (%s:%d:%s)"
> +object_register_skipped(const char *type) "Not registering '%s' type"
That's a good way to be able to select at runtime the objects enabled,
even though we'll have a binary with all qom objects code present.
Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
© 2016 - 2026 Red Hat, Inc.