qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] qom: Simplify pointer property getters/setters
@ 2020-10-09 19:15 Eduardo Habkost
  2020-10-09 19:15 ` [PATCH 1/3] acpi: Don't pass const pointers to object_property_add_uint*_ptr() Eduardo Habkost
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Eduardo Habkost @ 2020-10-09 19:15 UTC (permalink / raw)
  To: qemu-devel
  Cc: Daniel P. Berrangé, Eduardo Habkost, Igor Mammedov,
	Michael S. Tsirkin, Philippe Mathieu-Daudé,
	Markus Armbruster, Aleksandar Markovic, Marc-André Lureau,
	Paolo Bonzini, Aurelien Jarno

The existing pointer property getters/setters are awkward because
they are expected to work with const variables.  If we remove
that requirement, they can become a lot simpler and simply call
the visit_type_uint*() functions directly.

Git tree: https://github.com/ehabkost/qemu work/qom-ptr-prop-not-const
Based-on: 20201009160122.1662082-1-ehabkost@redhat.com

Eduardo Habkost (3):
  acpi: Don't pass const pointers to object_property_add_uint*_ptr()
  qom: Make object_property_add_uint*_ptr() get non-const pointers
  qom: Simplify and merge pointer property getters/setters

 include/qom/object.h |   8 +--
 hw/acpi/ich9.c       |   2 +-
 hw/acpi/piix4.c      |  10 ++--
 hw/isa/lpc_ich9.c    |   4 +-
 qom/object.c         | 122 +++++++++----------------------------------
 5 files changed, 38 insertions(+), 108 deletions(-)

-- 
2.26.2




^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/3] acpi: Don't pass const pointers to object_property_add_uint*_ptr()
  2020-10-09 19:15 [PATCH 0/3] qom: Simplify pointer property getters/setters Eduardo Habkost
@ 2020-10-09 19:15 ` Eduardo Habkost
  2020-10-09 19:15 ` [PATCH 2/3] qom: Make object_property_add_uint*_ptr() get non-const pointers Eduardo Habkost
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Eduardo Habkost @ 2020-10-09 19:15 UTC (permalink / raw)
  To: qemu-devel
  Cc: Daniel P. Berrangé, Eduardo Habkost, Igor Mammedov,
	Michael S. Tsirkin, Philippe Mathieu-Daudé,
	Markus Armbruster, Aleksandar Markovic, Marc-André Lureau,
	Paolo Bonzini, Aurelien Jarno

object_property_add_uint*_ptr() will be changed to get non-const
pointers.  Adapt the ACPI code to that.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 hw/acpi/ich9.c    |  2 +-
 hw/acpi/piix4.c   | 10 +++++-----
 hw/isa/lpc_ich9.c |  4 ++--
 3 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/hw/acpi/ich9.c b/hw/acpi/ich9.c
index 95cb0f935b..9bb8d1b155 100644
--- a/hw/acpi/ich9.c
+++ b/hw/acpi/ich9.c
@@ -371,7 +371,7 @@ static void ich9_pm_set_enable_tco(Object *obj, bool value, Error **errp)
 
 void ich9_pm_add_properties(Object *obj, ICH9LPCPMRegs *pm)
 {
-    static const uint32_t gpe0_len = ICH9_PMIO_GPE0_LEN;
+    static uint32_t gpe0_len = ICH9_PMIO_GPE0_LEN;
     pm->acpi_memory_hotplug.is_enabled = true;
     pm->cpu_hotplug_legacy = true;
     pm->disable_s3 = 0;
diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index 894d357f8c..1e8a15676d 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -439,11 +439,11 @@ static void piix4_pm_machine_ready(Notifier *n, void *opaque)
 
 static void piix4_pm_add_propeties(PIIX4PMState *s)
 {
-    static const uint8_t acpi_enable_cmd = ACPI_ENABLE;
-    static const uint8_t acpi_disable_cmd = ACPI_DISABLE;
-    static const uint32_t gpe0_blk = GPE_BASE;
-    static const uint32_t gpe0_blk_len = GPE_LEN;
-    static const uint16_t sci_int = 9;
+    static uint8_t acpi_enable_cmd = ACPI_ENABLE;
+    static uint8_t acpi_disable_cmd = ACPI_DISABLE;
+    static uint32_t gpe0_blk = GPE_BASE;
+    static uint32_t gpe0_blk_len = GPE_LEN;
+    static uint16_t sci_int = 9;
 
     object_property_add_uint8_ptr(OBJECT(s), ACPI_PM_PROP_ACPI_ENABLE_CMD,
                                   &acpi_enable_cmd, OBJ_PROP_FLAG_READ);
diff --git a/hw/isa/lpc_ich9.c b/hw/isa/lpc_ich9.c
index 04e5323140..b9dc01f654 100644
--- a/hw/isa/lpc_ich9.c
+++ b/hw/isa/lpc_ich9.c
@@ -638,8 +638,8 @@ static void ich9_lpc_initfn(Object *obj)
 {
     ICH9LPCState *lpc = ICH9_LPC_DEVICE(obj);
 
-    static const uint8_t acpi_enable_cmd = ICH9_APM_ACPI_ENABLE;
-    static const uint8_t acpi_disable_cmd = ICH9_APM_ACPI_DISABLE;
+    static uint8_t acpi_enable_cmd = ICH9_APM_ACPI_ENABLE;
+    static uint8_t acpi_disable_cmd = ICH9_APM_ACPI_DISABLE;
 
     object_property_add_uint8_ptr(obj, ACPI_PM_PROP_SCI_INT,
                                   &lpc->sci_gsi, OBJ_PROP_FLAG_READ);
-- 
2.26.2



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/3] qom: Make object_property_add_uint*_ptr() get non-const pointers
  2020-10-09 19:15 [PATCH 0/3] qom: Simplify pointer property getters/setters Eduardo Habkost
  2020-10-09 19:15 ` [PATCH 1/3] acpi: Don't pass const pointers to object_property_add_uint*_ptr() Eduardo Habkost
@ 2020-10-09 19:15 ` Eduardo Habkost
  2020-10-09 19:15 ` [PATCH 3/3] qom: Simplify and merge pointer property getters/setters Eduardo Habkost
  2020-10-21 13:09 ` [PATCH 0/3] qom: Simplify " Igor Mammedov
  3 siblings, 0 replies; 7+ messages in thread
From: Eduardo Habkost @ 2020-10-09 19:15 UTC (permalink / raw)
  To: qemu-devel
  Cc: Daniel P. Berrangé, Eduardo Habkost, Igor Mammedov,
	Michael S. Tsirkin, Philippe Mathieu-Daudé,
	Markus Armbruster, Aleksandar Markovic, Marc-André Lureau,
	Paolo Bonzini, Aurelien Jarno

Currently, the getter/setter functions are awkward because the
visit_type_uint*() functions provided by QAPI will always write a
value to the provided pointer.  Getting a non-const pointer will
allow us to simplify a lot of the getters/setters logic.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 include/qom/object.h | 8 ++++----
 qom/object.c         | 8 ++++----
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/include/qom/object.h b/include/qom/object.h
index a124cf897d..1441807be6 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -1744,7 +1744,7 @@ typedef enum {
  * Returns: The newly added property on success, or %NULL on failure.
  */
 ObjectProperty *object_property_add_uint8_ptr(Object *obj, const char *name,
-                                              const uint8_t *v,
+                                              uint8_t *v,
                                               ObjectPropertyFlags flags);
 
 ObjectProperty *object_class_property_add_uint8_ptr(ObjectClass *klass,
@@ -1765,7 +1765,7 @@ ObjectProperty *object_class_property_add_uint8_ptr(ObjectClass *klass,
  * Returns: The newly added property on success, or %NULL on failure.
  */
 ObjectProperty *object_property_add_uint16_ptr(Object *obj, const char *name,
-                                    const uint16_t *v,
+                                    uint16_t *v,
                                     ObjectPropertyFlags flags);
 
 ObjectProperty *object_class_property_add_uint16_ptr(ObjectClass *klass,
@@ -1786,7 +1786,7 @@ ObjectProperty *object_class_property_add_uint16_ptr(ObjectClass *klass,
  * Returns: The newly added property on success, or %NULL on failure.
  */
 ObjectProperty *object_property_add_uint32_ptr(Object *obj, const char *name,
-                                    const uint32_t *v,
+                                    uint32_t *v,
                                     ObjectPropertyFlags flags);
 
 ObjectProperty *object_class_property_add_uint32_ptr(ObjectClass *klass,
@@ -1807,7 +1807,7 @@ ObjectProperty *object_class_property_add_uint32_ptr(ObjectClass *klass,
  * Returns: The newly added property on success, or %NULL on failure.
  */
 ObjectProperty *object_property_add_uint64_ptr(Object *obj, const char *name,
-                                    const uint64_t *v,
+                                    uint64_t *v,
                                     ObjectPropertyFlags flags);
 
 ObjectProperty *object_class_property_add_uint64_ptr(ObjectClass *klass,
diff --git a/qom/object.c b/qom/object.c
index 73f27b8b7e..6b4dfc279a 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -2623,7 +2623,7 @@ object_class_property_add_uint_ptr(ObjectClass *oc, const char *name,
 
 ObjectProperty *
 object_property_add_uint8_ptr(Object *obj, const char *name,
-                              const uint8_t *v,
+                              uint8_t *v,
                               ObjectPropertyFlags flags)
 {
     return object_property_add_uint_ptr(obj, name, "uint8",
@@ -2646,7 +2646,7 @@ object_class_property_add_uint8_ptr(ObjectClass *klass, const char *name,
 
 ObjectProperty *
 object_property_add_uint16_ptr(Object *obj, const char *name,
-                               const uint16_t *v,
+                               uint16_t *v,
                                ObjectPropertyFlags flags)
 {
     return object_property_add_uint_ptr(obj, name, "uint16",
@@ -2669,7 +2669,7 @@ object_class_property_add_uint16_ptr(ObjectClass *klass, const char *name,
 
 ObjectProperty *
 object_property_add_uint32_ptr(Object *obj, const char *name,
-                               const uint32_t *v,
+                               uint32_t *v,
                                ObjectPropertyFlags flags)
 {
     return object_property_add_uint_ptr(obj, name, "uint32",
@@ -2692,7 +2692,7 @@ object_class_property_add_uint32_ptr(ObjectClass *klass, const char *name,
 
 ObjectProperty *
 object_property_add_uint64_ptr(Object *obj, const char *name,
-                               const uint64_t *v,
+                               uint64_t *v,
                                ObjectPropertyFlags flags)
 {
     return object_property_add_uint_ptr(obj, name, "uint64",
-- 
2.26.2



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/3] qom: Simplify and merge pointer property getters/setters
  2020-10-09 19:15 [PATCH 0/3] qom: Simplify pointer property getters/setters Eduardo Habkost
  2020-10-09 19:15 ` [PATCH 1/3] acpi: Don't pass const pointers to object_property_add_uint*_ptr() Eduardo Habkost
  2020-10-09 19:15 ` [PATCH 2/3] qom: Make object_property_add_uint*_ptr() get non-const pointers Eduardo Habkost
@ 2020-10-09 19:15 ` Eduardo Habkost
  2020-10-09 20:02   ` Eric Blake
  2020-10-21 13:09 ` [PATCH 0/3] qom: Simplify " Igor Mammedov
  3 siblings, 1 reply; 7+ messages in thread
From: Eduardo Habkost @ 2020-10-09 19:15 UTC (permalink / raw)
  To: qemu-devel
  Cc: Daniel P. Berrangé, Eduardo Habkost, Igor Mammedov,
	Michael S. Tsirkin, Philippe Mathieu-Daudé,
	Markus Armbruster, Aleksandar Markovic, Marc-André Lureau,
	Paolo Bonzini, Aurelien Jarno

Both the property getter and setter for pointer properties can
simply call the visitor functions directly, instead of making
extra copies and requiring additional logic.

Remove the extra copying logic, and merge the getter and setter
functions in object_visit_uint*_ptr() accessors.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 qom/object.c | 114 ++++++++++-----------------------------------------
 1 file changed, 22 insertions(+), 92 deletions(-)

diff --git a/qom/object.c b/qom/object.c
index 6b4dfc279a..3b343fd118 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -2496,119 +2496,57 @@ static void *pointer_property_get_ptr(Object *obj, PointerProperty *prop)
     }
 }
 
-static void property_get_uint8_ptr(Object *obj, Visitor *v, const char *name,
+static void property_visit_uint8_ptr(Object *obj, Visitor *v, const char *name,
                                    void *opaque, Error **errp)
 {
     PointerProperty *prop = opaque;
     uint8_t *field = pointer_property_get_ptr(obj, prop);
-    uint8_t value = *field;
-    visit_type_uint8(v, name, &value, errp);
+    visit_type_uint8(v, name, field, errp);
 }
 
-static void property_set_uint8_ptr(Object *obj, Visitor *v, const char *name,
-                                   void *opaque, Error **errp)
-{
-    PointerProperty *prop = opaque;
-    uint8_t *field = pointer_property_get_ptr(obj, prop);
-    uint8_t value;
-
-    if (!visit_type_uint8(v, name, &value, errp)) {
-        return;
-    }
-
-    *field = value;
-}
-
-static void property_get_uint16_ptr(Object *obj, Visitor *v, const char *name,
+static void property_visit_uint16_ptr(Object *obj, Visitor *v, const char *name,
                                     void *opaque, Error **errp)
 {
     PointerProperty *prop = opaque;
     uint16_t *field = pointer_property_get_ptr(obj, prop);
-    uint16_t value = *field;
-    visit_type_uint16(v, name, &value, errp);
-}
-
-static void property_set_uint16_ptr(Object *obj, Visitor *v, const char *name,
-                                    void *opaque, Error **errp)
-{
-    PointerProperty *prop = opaque;
-    uint16_t *field = pointer_property_get_ptr(obj, prop);
-    uint16_t value;
-
-    if (!visit_type_uint16(v, name, &value, errp)) {
-        return;
-    }
-
-    *field = value;
+    visit_type_uint16(v, name, field, errp);
 }
 
-static void property_get_uint32_ptr(Object *obj, Visitor *v, const char *name,
+static void property_visit_uint32_ptr(Object *obj, Visitor *v, const char *name,
                                     void *opaque, Error **errp)
 {
     PointerProperty *prop = opaque;
     uint32_t *field = pointer_property_get_ptr(obj, prop);
-    uint32_t value = *field;
-    visit_type_uint32(v, name, &value, errp);
+    visit_type_uint32(v, name, field, errp);
 }
 
-static void property_set_uint32_ptr(Object *obj, Visitor *v, const char *name,
-                                    void *opaque, Error **errp)
-{
-    PointerProperty *prop = opaque;
-    uint32_t *field = pointer_property_get_ptr(obj, prop);
-    uint32_t value;
-
-    if (!visit_type_uint32(v, name, &value, errp)) {
-        return;
-    }
-
-    *field = value;
-}
-
-static void property_get_uint64_ptr(Object *obj, Visitor *v, const char *name,
+static void property_visit_uint64_ptr(Object *obj, Visitor *v, const char *name,
                                     void *opaque, Error **errp)
 {
     PointerProperty *prop = opaque;
     uint64_t *field = pointer_property_get_ptr(obj, prop);
-    uint64_t value = *field;
-    visit_type_uint64(v, name, &value, errp);
-}
-
-static void property_set_uint64_ptr(Object *obj, Visitor *v, const char *name,
-                                    void *opaque, Error **errp)
-{
-    PointerProperty *prop = opaque;
-    uint64_t *field = pointer_property_get_ptr(obj, prop);
-    uint64_t value;
-
-    if (!visit_type_uint64(v, name, &value, errp)) {
-        return;
-    }
-
-    *field = value;
+    visit_type_uint64(v, name, field, errp);
 }
 
 static ObjectProperty *
 object_property_add_uint_ptr(Object *obj, const char *name,
                             const char *type,
-                            ObjectPropertyAccessor getter,
-                            ObjectPropertyAccessor setter,
+                            ObjectPropertyAccessor accessor,
                             ObjectPropertyFlags flags,
                             void *ptr)
 {
     PointerProperty *prop = g_new0(PointerProperty, 1);
     prop->ptr = ptr;
     return object_property_add(obj, name, type,
-                               (flags & OBJ_PROP_FLAG_READ) ? getter : NULL,
-                               (flags & OBJ_PROP_FLAG_WRITE) ? setter : NULL,
+                               (flags & OBJ_PROP_FLAG_READ) ? accessor : NULL,
+                               (flags & OBJ_PROP_FLAG_WRITE) ? accessor : NULL,
                                NULL, (void *)prop);
 }
 
 static ObjectProperty *
 object_class_property_add_uint_ptr(ObjectClass *oc, const char *name,
                                    const char *type,
-                                   ObjectPropertyAccessor getter,
-                                   ObjectPropertyAccessor setter,
+                                   ObjectPropertyAccessor accessor,
                                    ObjectPropertyFlags flags,
                                    ptrdiff_t offset)
 {
@@ -2616,8 +2554,8 @@ object_class_property_add_uint_ptr(ObjectClass *oc, const char *name,
     prop->is_offset = true;
     prop->offset = offset;
     return object_class_property_add(oc, name, type,
-                                     (flags & OBJ_PROP_FLAG_READ) ? getter : NULL,
-                                     (flags & OBJ_PROP_FLAG_WRITE) ? setter : NULL,
+                                     (flags & OBJ_PROP_FLAG_READ) ? accessor : NULL,
+                                     (flags & OBJ_PROP_FLAG_WRITE) ? accessor : NULL,
                                      NULL, (void *)prop);
 }
 
@@ -2627,8 +2565,7 @@ object_property_add_uint8_ptr(Object *obj, const char *name,
                               ObjectPropertyFlags flags)
 {
     return object_property_add_uint_ptr(obj, name, "uint8",
-                                        property_get_uint8_ptr,
-                                        property_set_uint8_ptr,
+                                        property_visit_uint8_ptr,
                                         flags,
                                         (void *)v);
 }
@@ -2639,8 +2576,7 @@ object_class_property_add_uint8_ptr(ObjectClass *klass, const char *name,
                                     ObjectPropertyFlags flags)
 {
     return object_class_property_add_uint_ptr(klass, name, "uint8",
-                                              property_get_uint8_ptr,
-                                              property_set_uint8_ptr,
+                                              property_visit_uint8_ptr,
                                               flags, offset);
 }
 
@@ -2650,8 +2586,7 @@ object_property_add_uint16_ptr(Object *obj, const char *name,
                                ObjectPropertyFlags flags)
 {
     return object_property_add_uint_ptr(obj, name, "uint16",
-                                        property_get_uint16_ptr,
-                                        property_set_uint16_ptr,
+                                        property_visit_uint16_ptr,
                                         flags,
                                         (void *)v);
 }
@@ -2662,8 +2597,7 @@ object_class_property_add_uint16_ptr(ObjectClass *klass, const char *name,
                                      ObjectPropertyFlags flags)
 {
     return object_class_property_add_uint_ptr(klass, name, "uint16",
-                                              property_get_uint16_ptr,
-                                              property_set_uint16_ptr,
+                                              property_visit_uint16_ptr,
                                               flags, offset);
 }
 
@@ -2673,8 +2607,7 @@ object_property_add_uint32_ptr(Object *obj, const char *name,
                                ObjectPropertyFlags flags)
 {
     return object_property_add_uint_ptr(obj, name, "uint32",
-                                        property_get_uint32_ptr,
-                                        property_set_uint32_ptr,
+                                        property_visit_uint32_ptr,
                                         flags,
                                         (void *)v);
 }
@@ -2685,8 +2618,7 @@ object_class_property_add_uint32_ptr(ObjectClass *klass, const char *name,
                                      ObjectPropertyFlags flags)
 {
     return object_class_property_add_uint_ptr(klass, name, "uint32",
-                                              property_get_uint32_ptr,
-                                              property_set_uint32_ptr,
+                                              property_visit_uint32_ptr,
                                               flags, offset);
 }
 
@@ -2696,8 +2628,7 @@ object_property_add_uint64_ptr(Object *obj, const char *name,
                                ObjectPropertyFlags flags)
 {
     return object_property_add_uint_ptr(obj, name, "uint64",
-                                        property_get_uint64_ptr,
-                                        property_set_uint64_ptr,
+                                        property_visit_uint64_ptr,
                                         flags,
                                         (void *)v);
 }
@@ -2708,8 +2639,7 @@ object_class_property_add_uint64_ptr(ObjectClass *klass, const char *name,
                                      ObjectPropertyFlags flags)
 {
     return object_class_property_add_uint_ptr(klass, name, "uint64",
-                                              property_get_uint64_ptr,
-                                              property_set_uint64_ptr,
+                                              property_visit_uint64_ptr,
                                               flags, offset);
 }
 
-- 
2.26.2



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 3/3] qom: Simplify and merge pointer property getters/setters
  2020-10-09 19:15 ` [PATCH 3/3] qom: Simplify and merge pointer property getters/setters Eduardo Habkost
@ 2020-10-09 20:02   ` Eric Blake
  2020-10-09 20:09     ` fixup! " Eduardo Habkost
  0 siblings, 1 reply; 7+ messages in thread
From: Eric Blake @ 2020-10-09 20:02 UTC (permalink / raw)
  To: Eduardo Habkost, qemu-devel
  Cc: Daniel P. Berrangé, Michael S. Tsirkin,
	Philippe Mathieu-Daudé, Markus Armbruster,
	Aleksandar Markovic, Paolo Bonzini, Marc-André Lureau,
	Igor Mammedov, Aurelien Jarno


[-- Attachment #1.1: Type: text/plain, Size: 1208 bytes --]

On 10/9/20 2:15 PM, Eduardo Habkost wrote:
> Both the property getter and setter for pointer properties can
> simply call the visitor functions directly, instead of making
> extra copies and requiring additional logic.
> 
> Remove the extra copying logic, and merge the getter and setter
> functions in object_visit_uint*_ptr() accessors.
> 
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> ---
>  qom/object.c | 114 ++++++++++-----------------------------------------
>  1 file changed, 22 insertions(+), 92 deletions(-)
> 
> diff --git a/qom/object.c b/qom/object.c
> index 6b4dfc279a..3b343fd118 100644
> --- a/qom/object.c
> +++ b/qom/object.c
> @@ -2496,119 +2496,57 @@ static void *pointer_property_get_ptr(Object *obj, PointerProperty *prop)
>      }
>  }
>  
> -static void property_get_uint8_ptr(Object *obj, Visitor *v, const char *name,
> +static void property_visit_uint8_ptr(Object *obj, Visitor *v, const char *name,
>                                     void *opaque, Error **errp)

Indentation is now off.  Several instances.

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


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* fixup! qom: Simplify and merge pointer property getters/setters
  2020-10-09 20:02   ` Eric Blake
@ 2020-10-09 20:09     ` Eduardo Habkost
  0 siblings, 0 replies; 7+ messages in thread
From: Eduardo Habkost @ 2020-10-09 20:09 UTC (permalink / raw)
  To: Eric Blake
  Cc: Daniel P. Berrangé, Michael S. Tsirkin, Markus Armbruster,
	Philippe Mathieu-Daudé, qemu-devel, Aleksandar Markovic,
	Paolo Bonzini, Marc-André Lureau, Igor Mammedov,
	Aurelien Jarno

On Fri, Oct 09, 2020 at 03:02:58PM -0500, Eric Blake wrote:
> On 10/9/20 2:15 PM, Eduardo Habkost wrote:
> > Both the property getter and setter for pointer properties can
> > simply call the visitor functions directly, instead of making
> > extra copies and requiring additional logic.
> > 
> > Remove the extra copying logic, and merge the getter and setter
> > functions in object_visit_uint*_ptr() accessors.
> > 
> > Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> > ---
> >  qom/object.c | 114 ++++++++++-----------------------------------------
> >  1 file changed, 22 insertions(+), 92 deletions(-)
> > 
> > diff --git a/qom/object.c b/qom/object.c
> > index 6b4dfc279a..3b343fd118 100644
> > --- a/qom/object.c
> > +++ b/qom/object.c
> > @@ -2496,119 +2496,57 @@ static void *pointer_property_get_ptr(Object *obj, PointerProperty *prop)
> >      }
> >  }
> >  
> > -static void property_get_uint8_ptr(Object *obj, Visitor *v, const char *name,
> > +static void property_visit_uint8_ptr(Object *obj, Visitor *v, const char *name,
> >                                     void *opaque, Error **errp)
> 
> Indentation is now off.  Several instances.

Oops.  Fixup applied locally.  Thanks!

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
diff --git a/qom/object.c b/qom/object.c
index 3b343fd118..9d3710dec5 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -2497,7 +2497,7 @@ static void *pointer_property_get_ptr(Object *obj, PointerProperty *prop)
 }
 
 static void property_visit_uint8_ptr(Object *obj, Visitor *v, const char *name,
-                                   void *opaque, Error **errp)
+                                     void *opaque, Error **errp)
 {
     PointerProperty *prop = opaque;
     uint8_t *field = pointer_property_get_ptr(obj, prop);
@@ -2505,7 +2505,7 @@ static void property_visit_uint8_ptr(Object *obj, Visitor *v, const char *name,
 }
 
 static void property_visit_uint16_ptr(Object *obj, Visitor *v, const char *name,
-                                    void *opaque, Error **errp)
+                                      void *opaque, Error **errp)
 {
     PointerProperty *prop = opaque;
     uint16_t *field = pointer_property_get_ptr(obj, prop);
@@ -2513,7 +2513,7 @@ static void property_visit_uint16_ptr(Object *obj, Visitor *v, const char *name,
 }
 
 static void property_visit_uint32_ptr(Object *obj, Visitor *v, const char *name,
-                                    void *opaque, Error **errp)
+                                      void *opaque, Error **errp)
 {
     PointerProperty *prop = opaque;
     uint32_t *field = pointer_property_get_ptr(obj, prop);
@@ -2521,7 +2521,7 @@ static void property_visit_uint32_ptr(Object *obj, Visitor *v, const char *name,
 }
 
 static void property_visit_uint64_ptr(Object *obj, Visitor *v, const char *name,
-                                    void *opaque, Error **errp)
+                                      void *opaque, Error **errp)
 {
     PointerProperty *prop = opaque;
     uint64_t *field = pointer_property_get_ptr(obj, prop);


-- 
Eduardo



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/3] qom: Simplify pointer property getters/setters
  2020-10-09 19:15 [PATCH 0/3] qom: Simplify pointer property getters/setters Eduardo Habkost
                   ` (2 preceding siblings ...)
  2020-10-09 19:15 ` [PATCH 3/3] qom: Simplify and merge pointer property getters/setters Eduardo Habkost
@ 2020-10-21 13:09 ` Igor Mammedov
  3 siblings, 0 replies; 7+ messages in thread
From: Igor Mammedov @ 2020-10-21 13:09 UTC (permalink / raw)
  To: Eduardo Habkost
  Cc: Daniel P. Berrangé, Michael S. Tsirkin, Markus Armbruster,
	qemu-devel, Philippe Mathieu-Daudé, Aleksandar Markovic,
	Marc-André Lureau, Paolo Bonzini, Aurelien Jarno

On Fri,  9 Oct 2020 15:15:17 -0400
Eduardo Habkost <ehabkost@redhat.com> wrote:

> The existing pointer property getters/setters are awkward because
> they are expected to work with const variables.  If we remove
> that requirement, they can become a lot simpler and simply call
> the visit_type_uint*() functions directly.

see my reply on 'qom: Make all -object types use only class properties' thread.
we should drop  pointer property getters/setter instead of extending it.

> 
> Git tree: https://github.com/ehabkost/qemu work/qom-ptr-prop-not-const
> Based-on: 20201009160122.1662082-1-ehabkost@redhat.com
> 
> Eduardo Habkost (3):
>   acpi: Don't pass const pointers to object_property_add_uint*_ptr()
>   qom: Make object_property_add_uint*_ptr() get non-const pointers
>   qom: Simplify and merge pointer property getters/setters
> 
>  include/qom/object.h |   8 +--
>  hw/acpi/ich9.c       |   2 +-
>  hw/acpi/piix4.c      |  10 ++--
>  hw/isa/lpc_ich9.c    |   4 +-
>  qom/object.c         | 122 +++++++++----------------------------------
>  5 files changed, 38 insertions(+), 108 deletions(-)
> 



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-10-21 13:11 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-10-09 19:15 [PATCH 0/3] qom: Simplify pointer property getters/setters Eduardo Habkost
2020-10-09 19:15 ` [PATCH 1/3] acpi: Don't pass const pointers to object_property_add_uint*_ptr() Eduardo Habkost
2020-10-09 19:15 ` [PATCH 2/3] qom: Make object_property_add_uint*_ptr() get non-const pointers Eduardo Habkost
2020-10-09 19:15 ` [PATCH 3/3] qom: Simplify and merge pointer property getters/setters Eduardo Habkost
2020-10-09 20:02   ` Eric Blake
2020-10-09 20:09     ` fixup! " Eduardo Habkost
2020-10-21 13:09 ` [PATCH 0/3] qom: Simplify " Igor Mammedov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).