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 <ehabk...@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
signature.asc
Description: OpenPGP digital signature