Re: [PATCH v2 08/10] qom: Add object_property_add_*_ptr_def()

Mark Cave-Ayland <[email protected]> Thu, 11 Jun 2026 15:03:39 +0100
Newsgroups org.nongnu.qemu-rust,org.nongnu.qemu-arm,org.nongnu.qemu-devel
Message-ID <[email protected]>
On 09/06/2026 18:25, Peter Xu wrote:

> 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);
> +}

Would these ever be required outside of the migration logic? I'm 
wondering if it might make sense to use macros within the migration code 
instead. This would at least prevent them from leaking elsewhere into 
QEMU until we figure out a long-term strategy.


ATB,

Mark.