Instead of defining a class_init per class, just use a common constructor and set class_data to corresponding TargetInfo structure.
Suggested-by: Richard Henderson <[email protected]> Signed-off-by: Pierrick Bouvier <[email protected]> --- include/qemu/target-info-init.h | 14 ++------------ include/qemu/target-info-qom.h | 1 + target-info-qom.c | 6 ++++++ 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/include/qemu/target-info-init.h b/include/qemu/target-info-init.h index 176fd975a16..3945f2998e0 100644 --- a/include/qemu/target-info-init.h +++ b/include/qemu/target-info-init.h @@ -37,8 +37,6 @@ const TargetInfo *target_info(void) \ #include "qemu/target-info-qom.h" #include "qom/object.h" -#define TYPE_TARGET_INFO_TARGET TYPE_TARGET_INFO"-"TARGET_NAME - typedef struct TargetInfoQomTarget { TargetInfoQom parent; } TargetInfoQomTarget; @@ -47,24 +45,16 @@ typedef struct TargetInfoQomTargetClass { TargetInfoQomClass parent_class; } TargetInfoQomTargetClass; -OBJECT_DECLARE_TYPE(TargetInfoQomTarget, TargetInfoQomTargetClass, TARGET_INFO_TARGET) - #define target_info_init(ti_var) \ -static void target_info_qom_class_init(ObjectClass *oc, const void * data) \ -{ \ - TargetInfoQomTargetClass *klass = TARGET_INFO_TARGET_CLASS(oc); \ - klass->parent_class.target_info = &ti_var; \ -} \ - \ static const TypeInfo target_info_qom_target_type_info = { \ - .name = TYPE_TARGET_INFO_TARGET, \ + .name = TYPE_TARGET_INFO"-"TARGET_NAME, \ .parent = TYPE_TARGET_INFO, \ .instance_size = sizeof(TargetInfoQomTarget), \ .class_size = sizeof(TargetInfoQomTargetClass), \ .class_init = target_info_qom_class_init, \ + .class_data = &ti_var, \ .abstract = false, \ }; \ - \ DEFINE_TARGET_INFO_TYPE(target_info_qom_target_type_info) #endif /* CONFIG_USER_ONLY */ diff --git a/include/qemu/target-info-qom.h b/include/qemu/target-info-qom.h index 91be415ed33..a37c3e101e0 100644 --- a/include/qemu/target-info-qom.h +++ b/include/qemu/target-info-qom.h @@ -25,6 +25,7 @@ typedef struct TargetInfoQomClass { OBJECT_DECLARE_TYPE(TargetInfoQom, TargetInfoQomClass, TARGET_INFO) +void target_info_qom_class_init(ObjectClass *oc, const void * data); void target_info_qom_set_target(void); #endif /* QEMU_TARGET_INFO_QOM_H */ diff --git a/target-info-qom.c b/target-info-qom.c index cc470b3b4d6..5b0498ca654 100644 --- a/target-info-qom.c +++ b/target-info-qom.c @@ -37,6 +37,12 @@ static const TypeInfo target_info_parent_type = { DEFINE_TARGET_INFO_TYPE(target_info_parent_type) +void target_info_qom_class_init(ObjectClass *oc, const void * data) +{ + TargetInfoQomClass *klass = TARGET_INFO_CLASS(oc); + klass->target_info = data; +} + static const TargetInfo *target_info_ptr; const TargetInfo *target_info(void) -- 2.43.0
