On Tue, Jul 07, 2026 at 02:13:24PM +0100, Mark Cave-Ayland wrote: > On 07/07/2026 13:17, Daniel P. Berrangé wrote: > > > On Fri, Jul 03, 2026 at 02:53:04PM +0100, Mark Cave-Ayland wrote: > > > This adds a class property that references a uint8_t within the object > > > instance > > > and is intended to be a replacement for object_property_add_uint8_ptr(). > > > > > > Signed-off-by: Mark Cave-Ayland <[email protected]> > > > --- > > > include/qom/object.h | 5 +++++ > > > qom/object.c | 52 ++++++++++++++++++++++++++++++++++++++++++++ > > > 2 files changed, 57 insertions(+) > > > > > > diff --git a/include/qom/object.h b/include/qom/object.h > > > index 89c23d45ab..a55f9d0e97 100644 > > > --- a/include/qom/object.h > > > +++ b/include/qom/object.h > > > @@ -1956,6 +1956,11 @@ ObjectProperty > > > *object_property_add_uint8_ptr(Object *obj, const char *name, > > > const uint8_t *v, > > > ObjectPropertyFlags > > > flags); > > > +ObjectProperty *object_class_property_add_uint8_ptr(ObjectClass *klass, > > > + const char *name, > > > + ptrdiff_t v, > > > + ObjectPropertyFlags > > > flags); > > > + > > > ObjectProperty *object_class_static_property_add_uint8_ptr(ObjectClass > > > *klass, > > > const char *name, > > > const uint8_t *v, > > > diff --git a/qom/object.c b/qom/object.c > > > index d10bf848c0..263c313cd2 100644 > > > --- a/qom/object.c > > > +++ b/qom/object.c > > > @@ -2741,6 +2741,38 @@ static void property_set_uint64_ptr(Object *obj, > > > Visitor *v, const char *name, > > > *field = value; > > > } > > > +static void *object_class_prop_ptr(Object *obj, ptrdiff_t offset) > > > +{ > > > + void *ptr = obj; > > > + ptr += offset; > > > + > > > + return ptr; > > > +} > > > > Perhaps just > > > > #define FIELD(obj, offset) ((void *)obj+(ptrdiff_t)offset) > > That could work. > > > > + > > > +static void property_class_get_uint8_ptr(Object *obj, Visitor *v, > > > + const char *name, > > > + void *opaque, Error **errp) > > > +{ > > > + uint8_t value = *(uint8_t *)object_class_prop_ptr(obj, > > > + (ptrdiff_t)opaque); > > > > Do we need this intermediate instead of now > > > > > + visit_type_uint8(v, name, &value, errp); > > > > visit_type_uint8(v, name, FIELD(obj, opaque), errp); > > Yes, I think that would be possible. I shall give it a test and report back. > > > > +} > > > + > > > +static void property_class_set_uint8_ptr(Object *obj, Visitor *v, > > > + const char *name, > > > + void *opaque, Error **errp) > > > +{ > > > + uint8_t *field = (uint8_t *)object_class_prop_ptr(obj, > > > + (ptrdiff_t)opaque); > > > + uint8_t value; > > > + > > > + if (!visit_type_uint8(v, name, &value, errp)) { > > > + return; > > > + } > > > + > > > + *field = value; > > > > Instead of all this is it sufficient to do: > > > > visit_type_uint8(v, name, FIELD(obj, opaque), errp); > > > > > > Also, since we'll be using this pattern for int8, int16, int32, > > and many more, perhaps we could define a macro that can expand > > to the getter/setter impl for any scalar type. so we can do > > > > DEFINE_SCALAR_PROP_CALLBACKS(uint8); > > DEFINE_SCALAR_PROP_CALLBACKS(uint16); > > DEFINE_SCALAR_PROP_CALLBACKS(uint32); > > DEFINE_SCALAR_PROP_CALLBACKS(uint64); > > DEFINE_SCALAR_PROP_CALLBACKS(bool); > > ..etc.. > > That is something else that is possible: I've purposely avoided doing this > since it's not a pattern already in use within object.c. Do you think this > is worth doing as a separate exercise first?
Yeah, if we can convert existing scalar setters/getters that would be nice. Otherwise we're piling up a huge amount of repetitive code for dealing with every property type :-( > > > > +} > > > + > > > ObjectProperty * > > > object_property_add_uint8_ptr(Object *obj, const char *name, > > > const uint8_t *v, > > > ATB, > > Mark. > With regards, Daniel -- |: https://berrange.com ~~ https://hachyderm.io/@berrange :| |: https://libvirt.org ~~ https://entangle-photo.org :| |: https://pixelfed.art/berrange ~~ https://fstop138.berrange.com :|
