qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 03/12] qom: Make object_class_property_add_uint*_ptr() get of


From: Eric Blake
Subject: Re: [PATCH 03/12] qom: Make object_class_property_add_uint*_ptr() get offset
Date: Fri, 9 Oct 2020 12:24:19 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.11.0

On 10/9/20 11:01 AM, Eduardo Habkost wrote:
> The existing object_class_property_add_uint*_ptr() functions are
> not very useful, because they need a pointer to the property
> value, which can't really be provided before the object is
> created.
> 
> Replace the pointer parameter in those functions with a
> `ptrdiff_t offset` parameter.
> 
> Include a uint8 class property in check-qom-proplist unit tests,
> to ensure the feature is working.
> 
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> ---

>  static void *pointer_property_get_ptr(Object *obj, PointerProperty *prop)
>  {
> -    return prop->ptr;
> +    if (prop->is_offset) {
> +        return (void *)obj + prop->offset;

Addition on void* is a gcc extension.  Does clang support it as well, or
should you be casting to char* instead?

> +    } else {
> +        return prop->ptr;
> +    }
>  }
>  

> +++ b/tests/check-qom-proplist.c
> @@ -61,6 +61,7 @@ struct DummyObject {
>      bool bv;
>      DummyAnimal av;
>      char *sv;
> +    uint8_t u8v;
>  };
>  
>  struct DummyObjectClass {
> @@ -141,6 +142,9 @@ static void dummy_class_init(ObjectClass *cls, void *data)
>                                     &dummy_animal_map,
>                                     dummy_get_av,
>                                     dummy_set_av);
> +    object_class_property_add_uint8_ptr(cls, "u8v",
> +                                        offsetof(DummyObject, u8v),
> +                                        OBJ_PROP_FLAG_READWRITE);

I like how it turns out.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]