Re: [PATCH v2 07/10] qom: Add object_property_add_size_ptr()

Fabiano Rosas <[email protected]> Tue, 09 Jun 2026 20:18:38 -0300
Newsgroups org.nongnu.qemu-rust,org.nongnu.qemu-arm,org.nongnu.qemu-devel
Message-ID <[email protected]>
Peter Xu <[email protected]> writes:

> Add a helper to set qom property via a size pointer.
>
> Signed-off-by: Peter Xu <[email protected]>

Reviewed-by: Fabiano Rosas <[email protected]>

> ---
>  include/qom/object-property-ptr.h | 16 +++++++++++++
>  qom/object-property-ptr.c         | 40 +++++++++++++++++++++++++++++++
>  2 files changed, 56 insertions(+)
>
> diff --git a/include/qom/object-property-ptr.h b/include/qom/object-property-ptr.h
> index 9cd8600094..be467c64af 100644
> --- a/include/qom/object-property-ptr.h
> +++ b/include/qom/object-property-ptr.h
> @@ -115,4 +115,20 @@ ObjectProperty *object_class_property_add_uint64_ptr(ObjectClass *klass,
>                                            const uint64_t *v,
>                                            ObjectPropertyFlags flags);
>  
> +/**
> + * object_property_add_size_ptr:
> + * @obj: the object to add a property to
> + * @name: the name of the property
> + * @v: pointer to value
> + * @flags: bitwise-or'd ObjectPropertyFlags
> + *
> + * Add a property of type 'size' to the object.
> + *
> + * Returns: The newly added property on success, or %NULL on failure.
> + */
> +ObjectProperty *
> +object_property_add_size_ptr(Object *obj, const char *name,
> +                             const uint64_t *v,
> +                             ObjectPropertyFlags flags);
> +
>  #endif
> diff --git a/qom/object-property-ptr.c b/qom/object-property-ptr.c
> index 49f223da7b..21ceb2510d 100644
> --- a/qom/object-property-ptr.c
> +++ b/qom/object-property-ptr.c
> @@ -107,6 +107,26 @@ static void property_set_uint64_ptr(Object *obj, Visitor *v, const char *name,
>      *field = value;
>  }
>  
> +static void property_get_size_ptr(Object *obj, Visitor *v, const char *name,
> +                                  void *opaque, Error **errp)
> +{
> +    uint64_t value = *(uint64_t *)opaque;
> +    visit_type_size(v, name, &value, errp);
> +}
> +
> +static void property_set_size_ptr(Object *obj, Visitor *v, const char *name,
> +                                  void *opaque, Error **errp)
> +{
> +    uint64_t *field = opaque;
> +    uint64_t value;
> +
> +    if (!visit_type_size(v, name, &value, errp)) {
> +        return;
> +    }
> +
> +    *field = value;
> +}
> +
>  ObjectProperty *
>  object_property_add_bool_ptr(Object *obj, const char *name,
>                               const bool *v, ObjectPropertyFlags flags)
> @@ -285,3 +305,23 @@ object_class_property_add_uint64_ptr(ObjectClass *klass, const char *name,
>      return object_class_property_add(klass, name, "uint64",
>                                       getter, setter, NULL, (void *)v);
>  }
> +
> +ObjectProperty *
> +object_property_add_size_ptr(Object *obj, const char *name,
> +                             const uint64_t *v,
> +                             ObjectPropertyFlags flags)
> +{
> +    ObjectPropertyAccessor *getter = NULL;
> +    ObjectPropertyAccessor *setter = NULL;
> +
> +    if ((flags & OBJ_PROP_FLAG_READ) == OBJ_PROP_FLAG_READ) {
> +        getter = property_get_size_ptr;
> +    }
> +
> +    if ((flags & OBJ_PROP_FLAG_WRITE) == OBJ_PROP_FLAG_WRITE) {
> +        setter = property_set_size_ptr;
> +    }
> +
> +    return object_property_add(obj, name, "size",
> +                               getter, setter, NULL, (void *)v);
> +}