Re: [PATCH v2 08/10] qom: Add object_property_add_*_ptr_def()
Fabiano Rosas <[email protected]> Tue, 09 Jun 2026 20:21:18 -0300
| Newsgroups | org.nongnu.qemu-rust,org.nongnu.qemu-arm,org.nongnu.qemu-devel |
|---|---|
| Message-ID | <[email protected]> |
Peter Xu <[email protected]> writes: > Add sister functions for existing pointer versions, to make it even easier > to use by: > > - always make properties to be rw-able > - allowing to specify default values > - no retcode needed (assert on failure, always) > > Signed-off-by: Peter Xu <[email protected]> > --- > include/qom/object-property-ptr.h | 28 +++++++++++++ > qom/object-property-ptr.c | 67 +++++++++++++++++++++++++++++++ > 2 files changed, 95 insertions(+) > > diff --git a/include/qom/object-property-ptr.h b/include/qom/object-property-ptr.h > index be467c64af..ecd6f7819b 100644 > --- a/include/qom/object-property-ptr.h > +++ b/include/qom/object-property-ptr.h > @@ -131,4 +131,32 @@ object_property_add_size_ptr(Object *obj, const char *name, > const uint64_t *v, > ObjectPropertyFlags flags); > > +/* > + * Below are sister helpers of above, except that: > + * > + * (1) nothing is returned > + * (2) always make the property to be both readable and writeable > + * (3) allow setting default value > + * > + * Please refer to the sister functions for the documentation. > + */ > +void > +object_property_add_bool_ptr_def(Object *obj, const char *name, > + const bool *v, bool def); > +void > +object_property_add_uint8_ptr_def(Object *obj, const char *name, > + const uint8_t *v, uint8_t def); > +void > +object_property_add_uint16_ptr_def(Object *obj, const char *name, > + const uint16_t *v, uint16_t def); > +void > +object_property_add_uint32_ptr_def(Object *obj, const char *name, > + const uint32_t *v, uint32_t def); > +void > +object_property_add_uint64_ptr_def(Object *obj, const char *name, > + const uint64_t *v, uint64_t def); > +void > +object_property_add_size_ptr_def(Object *obj, const char *name, > + const uint64_t *v, uint64_t def); > + > #endif > diff --git a/qom/object-property-ptr.c b/qom/object-property-ptr.c > index 21ceb2510d..ae9081d2d8 100644 > --- a/qom/object-property-ptr.c > +++ b/qom/object-property-ptr.c > @@ -325,3 +325,70 @@ object_property_add_size_ptr(Object *obj, const char *name, > return object_property_add(obj, name, "size", > getter, setter, NULL, (void *)v); > } > + > +void > +object_property_add_bool_ptr_def(Object *obj, const char *name, > + const bool *v, bool def) > +{ > + ObjectProperty *prop; > + > + prop = object_property_add_bool_ptr(obj, name, v, > + OBJ_PROP_FLAG_READWRITE); > + object_property_set_default_bool(prop, def); > +} > + > + > +void > +object_property_add_uint8_ptr_def(Object *obj, const char *name, > + const uint8_t *v, uint8_t def) > +{ > + ObjectProperty *prop; > + > + prop = object_property_add_uint8_ptr(obj, name, v, > + OBJ_PROP_FLAG_READWRITE); > + object_property_set_default_uint(prop, def); > +} > + > +void > +object_property_add_uint16_ptr_def(Object *obj, const char *name, > + const uint16_t *v, uint16_t def) > +{ > + ObjectProperty *prop; > + > + prop = object_property_add_uint16_ptr(obj, name, v, > + OBJ_PROP_FLAG_READWRITE); > + object_property_set_default_uint(prop, def); > +} > + > +void > +object_property_add_uint32_ptr_def(Object *obj, const char *name, > + const uint32_t *v, uint32_t def) > +{ > + ObjectProperty *prop; > + > + prop = object_property_add_uint32_ptr(obj, name, v, > + OBJ_PROP_FLAG_READWRITE); > + object_property_set_default_uint(prop, def); > +} > + > +void > +object_property_add_uint64_ptr_def(Object *obj, const char *name, > + const uint64_t *v, uint64_t def) > +{ > + ObjectProperty *prop; > + > + prop = object_property_add_uint64_ptr(obj, name, v, > + OBJ_PROP_FLAG_READWRITE); > + object_property_set_default_uint(prop, def); > +} > + > +void > +object_property_add_size_ptr_def(Object *obj, const char *name, > + const uint64_t *v, uint64_t def) > +{ > + ObjectProperty *prop; > + > + prop = object_property_add_size_ptr(obj, name, v, > + OBJ_PROP_FLAG_READWRITE); > + object_property_set_default_uint(prop, def); > +} Reviewed-by: Fabiano Rosas <[email protected]>