diff mbox series

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

Message ID 20201029220246.472693-21-ehabkost@redhat.com
State New
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

>

>

>


-- 
Marc-André Lureau
<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Oct 30, 2020 at 2:09 AM Eduardo Habkost &lt;<a href="mailto:ehabkost@redhat.com">ehabkost@redhat.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Reuse function instead of calling object_property_add() directly.<br>
We need to hack ObjectProperty.release to make sure we will free<br>
the array property.<br>
<br>
Signed-off-by: Eduardo Habkost &lt;<a href="mailto:ehabkost@redhat.com" target="_blank">ehabkost@redhat.com</a>&gt;<br></blockquote><div><br></div><div>that seems to be right, but could use more eyes... somebody may have an idea of simplification.</div><div><br></div><div>Reviewed-by: Marc-André Lureau &lt;<a href="mailto:marcandre.lureau@redhat.com">marcandre.lureau@redhat.com</a>&gt;</div><div><br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">

---<br>
Cc: Paolo Bonzini &lt;<a href="mailto:pbonzini@redhat.com" target="_blank">pbonzini@redhat.com</a>&gt;<br>
Cc: &quot;Daniel P. Berrangé&quot; &lt;<a href="mailto:berrange@redhat.com" target="_blank">berrange@redhat.com</a>&gt;<br>
Cc: Eduardo Habkost &lt;<a href="mailto:ehabkost@redhat.com" target="_blank">ehabkost@redhat.com</a>&gt;<br>
Cc: <a href="mailto:qemu-devel@nongnu.org" target="_blank">qemu-devel@nongnu.org</a><br>
---<br>
 hw/core/qdev-properties.c | 13 ++++++-------<br>
 1 file changed, 6 insertions(+), 7 deletions(-)<br>
<br>
diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c<br>
index 1f06dfb5d5..4fec9cb73b 100644<br>
--- a/hw/core/qdev-properties.c<br>
+++ b/hw/core/qdev-properties.c<br>
@@ -600,7 +600,6 @@ static ArrayElementProperty *array_element_new(Object *obj,<br>
 {<br>
     char *propname = g_strdup_printf(&quot;%s[%d]&quot;, arrayname, index);<br>
     ArrayElementProperty *arrayprop = g_new0(ArrayElementProperty, 1);<br>
-    arrayprop-&gt;release = array_len_prop-&gt;arrayinfo-&gt;release;<br>
     arrayprop-&gt;propname = propname;<br>
     arrayprop-&gt;<a href="http://prop.info" rel="noreferrer" target="_blank">prop.info</a> = array_len_prop-&gt;arrayinfo;<br>
     arrayprop-&gt;<a href="http://prop.name" rel="noreferrer" target="_blank">prop.name</a> = propname;<br>
@@ -632,12 +631,12 @@ static void object_property_add_array_element(Object *obj,<br>
                                               Property *array_len_prop,<br>
                                               ArrayElementProperty *prop)<br>
 {<br>
-    object_property_add(obj, prop-&gt;<a href="http://prop.name" rel="noreferrer" target="_blank">prop.name</a>,<br>
-                        prop-&gt;prop.info-&gt;name,<br>
-                        static_prop_getter(prop-&gt;<a href="http://prop.info" rel="noreferrer" target="_blank">prop.info</a>),<br>
-                        static_prop_setter(prop-&gt;<a href="http://prop.info" rel="noreferrer" target="_blank">prop.info</a>),<br>
-                        array_element_release,<br>
-                        prop);<br>
+    ObjectProperty *op = object_property_add_static(obj, &amp;prop-&gt;prop);<br>
+<br>
+    assert((void *)prop == (void *)&amp;prop-&gt;prop);<br>
+    prop-&gt;release = op-&gt;release;<br>
+    /* array_element_release() will call the original release function */<br>
+    op-&gt;release = array_element_release;<br>
 }<br>
<br>
 static void set_prop_arraylen(Object *obj, Visitor *v, const char *name,<br>
-- <br>
2.28.0<br>
<br>
<br>
</blockquote></div><br clear="all"><br>-- <br><div dir="ltr" class="gmail_signature">Marc-André Lureau<br></div></div>
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,