diff mbox series

[20/36] qdev: Reuse object_property_add_static() when adding array elements

Message ID 20201029220246.472693-21-ehabkost@redhat.com (mailing list archive)
State New, archived
Headers show
Series Make qdev static property API usable by any QOM type | expand

Commit Message

Eduardo Habkost Oct. 29, 2020, 10:02 p.m. UTC
Reuse function instead of calling object_property_add() directly.
We need to hack ObjectProperty.release to make sure we will free
the array property.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: "Daniel P. Berrangé" <berrange@redhat.com>
Cc: Eduardo Habkost <ehabkost@redhat.com>
Cc: qemu-devel@nongnu.org
---
 hw/core/qdev-properties.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

Comments

Marc-André Lureau Oct. 30, 2020, 11:37 a.m. UTC | #1
On Fri, Oct 30, 2020 at 2:09 AM Eduardo Habkost <ehabkost@redhat.com> wrote:

> Reuse function instead of calling object_property_add() directly.
> We need to hack ObjectProperty.release to make sure we will free
> the array property.
>
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
>

that seems to be right, but could use more eyes... somebody may have an
idea of simplification.

Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>

---
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Cc: "Daniel P. Berrangé" <berrange@redhat.com>
> Cc: Eduardo Habkost <ehabkost@redhat.com>
> Cc: qemu-devel@nongnu.org
> ---
>  hw/core/qdev-properties.c | 13 ++++++-------
>  1 file changed, 6 insertions(+), 7 deletions(-)
>
> diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
> index 1f06dfb5d5..4fec9cb73b 100644
> --- a/hw/core/qdev-properties.c
> +++ b/hw/core/qdev-properties.c
> @@ -600,7 +600,6 @@ static ArrayElementProperty *array_element_new(Object
> *obj,
>  {
>      char *propname = g_strdup_printf("%s[%d]", arrayname, index);
>      ArrayElementProperty *arrayprop = g_new0(ArrayElementProperty, 1);
> -    arrayprop->release = array_len_prop->arrayinfo->release;
>      arrayprop->propname = propname;
>      arrayprop->prop.info = array_len_prop->arrayinfo;
>      arrayprop->prop.name = propname;
> @@ -632,12 +631,12 @@ static void object_property_add_array_element(Object
> *obj,
>                                                Property *array_len_prop,
>                                                ArrayElementProperty *prop)
>  {
> -    object_property_add(obj, prop->prop.name,
> -                        prop->prop.info->name,
> -                        static_prop_getter(prop->prop.info),
> -                        static_prop_setter(prop->prop.info),
> -                        array_element_release,
> -                        prop);
> +    ObjectProperty *op = object_property_add_static(obj, &prop->prop);
> +
> +    assert((void *)prop == (void *)&prop->prop);
> +    prop->release = op->release;
> +    /* array_element_release() will call the original release function */
> +    op->release = array_element_release;
>  }
>
>  static void set_prop_arraylen(Object *obj, Visitor *v, const char *name,
> --
> 2.28.0
>
>
>
diff mbox series

Patch

diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
index 1f06dfb5d5..4fec9cb73b 100644
--- a/hw/core/qdev-properties.c
+++ b/hw/core/qdev-properties.c
@@ -600,7 +600,6 @@  static ArrayElementProperty *array_element_new(Object *obj,
 {
     char *propname = g_strdup_printf("%s[%d]", arrayname, index);
     ArrayElementProperty *arrayprop = g_new0(ArrayElementProperty, 1);
-    arrayprop->release = array_len_prop->arrayinfo->release;
     arrayprop->propname = propname;
     arrayprop->prop.info = array_len_prop->arrayinfo;
     arrayprop->prop.name = propname;
@@ -632,12 +631,12 @@  static void object_property_add_array_element(Object *obj,
                                               Property *array_len_prop,
                                               ArrayElementProperty *prop)
 {
-    object_property_add(obj, prop->prop.name,
-                        prop->prop.info->name,
-                        static_prop_getter(prop->prop.info),
-                        static_prop_setter(prop->prop.info),
-                        array_element_release,
-                        prop);
+    ObjectProperty *op = object_property_add_static(obj, &prop->prop);
+
+    assert((void *)prop == (void *)&prop->prop);
+    prop->release = op->release;
+    /* array_element_release() will call the original release function */
+    op->release = array_element_release;
 }
 
 static void set_prop_arraylen(Object *obj, Visitor *v, const char *name,