On Mon, Aug 24, 2026 at 02:39:11PM +0100, Mark Cave-Ayland wrote: > On 24/08/2026 13:53, Daniel P. Berrangé wrote: > > > On Fri, Aug 21, 2026 at 12:14:22PM +0100, Mark Cave-Ayland wrote: > > > 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]> > > > Reviewed-by: Marc-André Lureau <[email protected]> > > > --- > > > include/qom/object.h | 18 ++++++++++++++++++ > > > qom/object.c | 43 +++++++++++++++++++++++++++++++++++++++++++ > > > 2 files changed, 61 insertions(+) > > > > > > diff --git a/include/qom/object.h b/include/qom/object.h > > > index 8dead29284..de37016ba8 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 boolean property in memory. This function will add a > > > + * 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 f91764aaa7..635eeeac77 100644 > > > --- a/qom/object.c > > > +++ b/qom/object.c > > > @@ -2750,6 +2750,49 @@ DEFINE_OBJECT_CLASS_PROPERTY_SCALAR_METHODS(uint64) > > > #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); > > > +} > > > + > > > +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; > > > +} > > > > Am I missing the reason why we can't use > > > > DEFINE_OBJECT_CLASS_PROPERTY_SCALAR_METHODS(bool) > > > > ? If so, could that be mentioned in the commit message. > > It's because bool is actually a macro according to C99 which causes the > expansion to fail. > > I'll update the commit message accordingly for v5.
Ah yes, I see it gets messy as you end up expanding to visit_type__Bool which of course doesn't exist. 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 :|
