It is similar to object_class_property_add_field_static(), but gets a copy of a Property struct so we don't need static variables.
Signed-off-by: Eduardo Habkost <ehabk...@redhat.com> --- This is a new patch added in v3 of this series, but v2 had a object_class_property_add_field() function too. This version of object_class_property_add_field() is slightly different from the one in v2, as it gets a copy of the Property struct (so it won't require static variables anymore). --- Cc: Paolo Bonzini <pbonz...@redhat.com> Cc: "Daniel P. Berrangé" <berra...@redhat.com> Cc: Eduardo Habkost <ehabk...@redhat.com> Cc: qemu-devel@nongnu.org --- include/qom/field-property.h | 23 +++++++++++++++++++++++ qom/field-property.c | 14 ++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/include/qom/field-property.h b/include/qom/field-property.h index 419e5eef75..a904f98609 100644 --- a/include/qom/field-property.h +++ b/include/qom/field-property.h @@ -83,6 +83,29 @@ struct PropertyInfo { ObjectPropertyRelease *release; }; +/** + * object_class_property_add_field: Add a field property to object class + * @oc: object class + * @name: property name + * @prop: property definition + * @allow_set: check function called when property is set + * + * Add a field property to an object class. A field property is + * a property that will change a field at a specific offset of the + * object instance struct. + * + * Note that data pointed by @prop (like strings or pointers to + * other structs) are not copied and must have static life time. + * + * @allow_set should not be NULL. If the property can always be + * set, `prop_allow_set_always` can be used. If the property can + * never be set, `prop_allow_set_never` can be used. + */ +ObjectProperty * +object_class_property_add_field(ObjectClass *oc, const char *name, + Property prop, + ObjectPropertyAllowSet allow_set); + void *object_field_prop_ptr(Object *obj, Property *prop); #endif diff --git a/qom/field-property.c b/qom/field-property.c index 1fd11f2ad3..cb729626ce 100644 --- a/qom/field-property.c +++ b/qom/field-property.c @@ -125,6 +125,20 @@ object_class_property_add_field_static(ObjectClass *oc, const char *name, return op; } +ObjectProperty * +object_class_property_add_field(ObjectClass *oc, const char *name, + Property prop, + ObjectPropertyAllowSet allow_set) +{ + /* + * QOM classes and class properties are never deallocated, so we don't + * have a corresponding release function that will free newprop. + */ + Property *newprop = g_new0(Property, 1); + *newprop = prop; + return object_class_property_add_field_static(oc, name, newprop, allow_set); +} + void object_class_add_field_properties(ObjectClass *oc, Property *props, ObjectPropertyAllowSet allow_set) { -- 2.28.0