All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Mark Cave-Ayland <mark.caveayland@nutanix.com>
Cc: mst@redhat.com, imammedo@redhat.com, anisinha@redhat.com,
	philmd@mailo.com, aurelien@aurel32.net, peter.maydell@linaro.org,
	pbonzini@redhat.com, richard.henderson@linaro.org,
	qemu-devel@nongnu.org, qemu-arm@nongnu.org
Subject: Re: [PATCH v2 02/12] qom/object.c: add object_class_property_add_uint8_ptr()
Date: Tue, 7 Jul 2026 13:17:07 +0100	[thread overview]
Message-ID: <akzuQ-YiaSmToNsg@redhat.com> (raw)
In-Reply-To: <20260703135512.3213964-3-mark.caveayland@nutanix.com>

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 <mark.caveayland@nutanix.com>
> ---
>  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)

> +
> +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);


> +}
> +
> +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..

> +}
> +
>  ObjectProperty *
>  object_property_add_uint8_ptr(Object *obj, const char *name,
>                                const uint8_t *v,

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 :|



  reply	other threads:[~2026-07-07 12:17 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-03 13:53 [PATCH v2 00/12] hw/acpi: convert object props to class props Mark Cave-Ayland
2026-07-03 13:53 ` [PATCH v2 01/12] qom/object.c: rename object_class_property_uint*_ptr() to object_class_static_property_uint*_ptr() Mark Cave-Ayland
2026-07-07 12:05   ` Daniel P. Berrangé
2026-07-07 13:08     ` Mark Cave-Ayland
2026-07-07 13:19       ` Daniel P. Berrangé
2026-07-07 14:19       ` Peter Maydell
2026-07-08  9:24         ` Mark Cave-Ayland
2026-07-03 13:53 ` [PATCH v2 02/12] qom/object.c: add object_class_property_add_uint8_ptr() Mark Cave-Ayland
2026-07-07 12:17   ` Daniel P. Berrangé [this message]
2026-07-07 13:13     ` Mark Cave-Ayland
2026-07-07 13:20       ` Daniel P. Berrangé
2026-07-03 13:53 ` [PATCH v2 03/12] qom/object.c: add object_class_property_add_uint16_ptr() Mark Cave-Ayland
2026-07-03 13:53 ` [PATCH v2 04/12] qom/object.c: add object_class_property_add_uint32_ptr() Mark Cave-Ayland
2026-07-03 13:53 ` [PATCH v2 05/12] qom/object.c: add object_class_property_add_uint64_ptr() Mark Cave-Ayland
2026-07-03 13:53 ` [PATCH v2 06/12] hw/acpi/ich9.c: move initial property values into ich9_reset_properties() Mark Cave-Ayland
2026-07-06  7:06   ` Philippe Mathieu-Daudé
2026-07-03 13:53 ` [PATCH v2 07/12] hw/isa/lpc_ich9.c: convert ich9_lpc_initfn() object props to class props Mark Cave-Ayland
2026-07-03 13:53 ` [PATCH v2 08/12] hw/acpi/ich9.c: don't pass ICH9LPCPMRegs via opaque for ACPI_PM_PROP_GPE0_BLK prop Mark Cave-Ayland
2026-07-06  7:07   ` Philippe Mathieu-Daudé
2026-07-03 13:53 ` [PATCH v2 09/12] hw/acpi/ich9.c: convert object props in ICH9_LPC_DEVICE to class props Mark Cave-Ayland
2026-07-03 13:53 ` [PATCH v2 10/12] hw/acpi/pcihp.c: convert ACPI_PCIHP_IO_BASE_PROP and ACPI_PCIHP_IO_BASE_PROP " Mark Cave-Ayland
2026-07-03 13:53 ` [PATCH v2 11/12] hw/acpi/pcihp.c: convert ACPI_PCIHP_PROP_BSEL from object prop to class prop Mark Cave-Ayland
2026-07-03 13:53 ` [PATCH v2 12/12] hw/acpi/piix4.c: convert object props in PIIX4_PM to class props Mark Cave-Ayland

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=akzuQ-YiaSmToNsg@redhat.com \
    --to=berrange@redhat.com \
    --cc=anisinha@redhat.com \
    --cc=aurelien@aurel32.net \
    --cc=imammedo@redhat.com \
    --cc=mark.caveayland@nutanix.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=philmd@mailo.com \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.