Re: [PATCH v3 09/15] qom/object.c: add object_class_property_add_bool_ptr()

[email protected]
Newsgroups org.nongnu.qemu-arm,org.nongnu.qemu-devel
Message-ID <178716196332.2018258.9610593235879631054.b4-review@b4>
> This adds a class property that references a bool within the object instance
> and is intended to be used as a replacement for object_class_property_add_bool()
> where possible.
> 
> Signed-off-by: Mark Cave-Ayland <[email protected]>
> Message-ID: <[email protected]>
>
> diff --git a/include/qom/object.h b/include/qom/object.h
> index e0c88453b1e0..b469740782ac 100644
> --- a/include/qom/object.h
> +++ b/include/qom/object.h
> @@ -2017,6 +2017,24 @@ typedef enum {
>      OBJ_PROP_FLAG_READWRITE = (OBJ_PROP_FLAG_READ | OBJ_PROP_FLAG_WRITE),
>  } ObjectPropertyFlags;
>  
> +/**
> + * object_class_property_add_bool_ptr:
> + * @klass: the object class to add a property to
> + * @name: the name of the property
> + * @offset: the offset from the object instance where the bool value is
> + *   stored
> + * @flags: bitwise-or'd ObjectPropertyFlags
> + *
> + * Add an integer property in memory.  This function will add a

"Add an integer property" -> "Add a boolean property"

> + * property of type 'bool'.
> + *
> + * Returns: The newly added property on success, or %NULL on failure.
> + */
> +ObjectProperty *object_class_property_add_bool_ptr(ObjectClass *klass,
> +                                         const char *name,
> +                                         ptrdiff_t offset,
> +                                         ObjectPropertyFlags flags);
> +
>  /**
>   * object_property_add_uint8_ptr:
>   * @obj: the object to add a property to
> diff --git a/qom/object.c b/qom/object.c
> index fe032c96190c..b82f10376a44 100644
> --- a/qom/object.c
> +++ b/qom/object.c
> @@ -2749,6 +2749,49 @@ DEFINE_OBJECT_CLASS_PROPERTY_SCALAR_METHODS(uint32)
>  #undef DEFINE_OBJECT_CLASS_PROPERTY_SCALAR_METHODS
>  
>  
> +static void property_class_get_bool_ptr(Object *obj, Visitor *v,
> +                                        const char *name,
> +                                        void *opaque, Error **errp)
> +{
> +    bool value = *(bool *)object_class_prop_ptr(obj, (ptrdiff_t)opaque);
> +
> +    visit_type_bool(v, name, &value, errp); \

extra \

> +}
> +
> +static void property_class_set_bool_ptr(Object *obj, Visitor *v,
> +                                        const char *name,
> +                                        void *opaque, Error **errp)
> +{
> +    bool *field = (bool *)object_class_prop_ptr(obj, (ptrdiff_t)opaque);
> +    bool value;
> +
> +    if (!visit_type_bool(v, name, &value, errp)) {
> +        return;
> +    }
> +
> +    *field = value;
> +}
> +
> +ObjectProperty *
> +object_class_property_add_bool_ptr(ObjectClass *klass, const char *name,
> +                                   ptrdiff_t offset,
> +                                   ObjectPropertyFlags flags)
> +{
> +    ObjectPropertyAccessor *getter = NULL;
> +    ObjectPropertyAccessor *setter = NULL;
> +
> +    if ((flags & OBJ_PROP_FLAG_READ) == OBJ_PROP_FLAG_READ) {
> +        getter = property_class_get_bool_ptr;
> +    }
> +
> +    if ((flags & OBJ_PROP_FLAG_WRITE) == OBJ_PROP_FLAG_WRITE) {
> +        setter = property_class_set_bool_ptr;
> +    }
> +
> +    return object_class_property_add(klass, name, "bool",
> +                                     getter, setter, NULL, (void *)offset);
> +}
> +
>  ObjectProperty *
>  object_property_add_uint8_ptr(Object *obj, const char *name,
>                                const uint8_t *v,

Reviewed-by: Marc-André Lureau <[email protected]>

-- 
Marc-André Lureau <[email protected]>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.