When removing target specific sections (#ifdef TARGET_X), we started exposing types for different targets in the same file.
Previously, we implemented a filter based on interfaces, but it proved to be too cumbersome, requiring duplication across architectures. To simplify it, we add a new callback, is_available, to TypeInfo, that will replace the existing filtering mechanism. Signed-off-by: Pierrick Bouvier <[email protected]> --- include/qom/object.h | 3 +++ qom/object.c | 4 ++++ rust/qom/src/qom.rs | 1 + 3 files changed, 8 insertions(+) diff --git a/include/qom/object.h b/include/qom/object.h index e24f0a2b2d0..7ecd0f210fb 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -469,6 +469,8 @@ struct Object * @class_data: Data to pass to the @class_init, * @class_base_init. This can be useful when building dynamic * classes. + * @is_available: callback invoked at registration time, to dynamically check if + * this type should be available or not. * @interfaces: The list of interfaces associated with this type. This * should point to a static array that's terminated with a zero filled * element. @@ -491,6 +493,7 @@ struct TypeInfo void (*class_base_init)(ObjectClass *klass, const void *data); const void *class_data; + bool (*is_available)(void); const InterfaceInfo *interfaces; }; diff --git a/qom/object.c b/qom/object.c index 85bbd7f9fe1..b1834a57cc9 100644 --- a/qom/object.c +++ b/qom/object.c @@ -163,6 +163,10 @@ static TypeImpl *type_register_internal(const TypeInfo *info) abort(); } + if (info->is_available && !info->is_available()) { + return NULL; + } + ti = type_new(info); type_table_add(ti); diff --git a/rust/qom/src/qom.rs b/rust/qom/src/qom.rs index cc00ddcfc98..bbb485e2cfd 100644 --- a/rust/qom/src/qom.rs +++ b/rust/qom/src/qom.rs @@ -691,6 +691,7 @@ pub trait ObjectImpl: ObjectType + IsA<Object> { class_init: Some(rust_class_init::<Self>), class_base_init: Self::CLASS_BASE_INIT, class_data: core::ptr::null(), + is_available: None, interfaces: core::ptr::null(), }; -- 2.43.0
