Message ID | 20201029220246.472693-21-ehabkost@redhat.com |
---|---|
State | New |
Headers | show |
Series | Make qdev static property API usable by any QOM type | expand |
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 <<a href="mailto:ehabkost@redhat.com">ehabkost@redhat.com</a>> 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 <<a href="mailto:ehabkost@redhat.com" target="_blank">ehabkost@redhat.com</a>><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 <<a href="mailto:marcandre.lureau@redhat.com">marcandre.lureau@redhat.com</a>></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 <<a href="mailto:pbonzini@redhat.com" target="_blank">pbonzini@redhat.com</a>><br> Cc: "Daniel P. Berrangé" <<a href="mailto:berrange@redhat.com" target="_blank">berrange@redhat.com</a>><br> Cc: Eduardo Habkost <<a href="mailto:ehabkost@redhat.com" target="_blank">ehabkost@redhat.com</a>><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("%s[%d]", arrayname, index);<br> ArrayElementProperty *arrayprop = g_new0(ArrayElementProperty, 1);<br> - arrayprop->release = array_len_prop->arrayinfo->release;<br> arrayprop->propname = propname;<br> arrayprop-><a href="http://prop.info" rel="noreferrer" target="_blank">prop.info</a> = array_len_prop->arrayinfo;<br> arrayprop-><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-><a href="http://prop.name" rel="noreferrer" target="_blank">prop.name</a>,<br> - prop->prop.info->name,<br> - static_prop_getter(prop-><a href="http://prop.info" rel="noreferrer" target="_blank">prop.info</a>),<br> - static_prop_setter(prop-><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, &prop->prop);<br> +<br> + assert((void *)prop == (void *)&prop->prop);<br> + prop->release = op->release;<br> + /* array_element_release() will call the original release function */<br> + op->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 --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,
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(-)