@@ -521,27 +521,17 @@ const PropertyInfo prop_info_size32 = {
/* --- support for array properties --- */
-/* Used as an opaque for the object properties we add for each
- * array element. Note that the struct Property must be first
- * in the struct so that a pointer to this works as the opaque
- * for the underlying element's property hooks as well as for
- * our own release callback.
- */
-typedef struct {
- struct Property prop;
-} ArrayElementProperty;
-
/* object property release callback for array element properties:
* we call the underlying element's property release hook, and
* then free the memory we allocated when we added the property.
*/
static void array_element_release(Object *obj, const char *name, void *opaque)
{
- ArrayElementProperty *p = opaque;
- if (p->prop.info->release) {
- p->prop.info->release(obj, name, opaque);
+ Property *prop = opaque;
+ if (prop->info->release) {
+ prop->info->release(obj, name, opaque);
}
- g_free(p);
+ g_free(prop);
}
static void set_prop_arraylen(Object *obj, Visitor *v, const char *name,
@@ -585,20 +575,20 @@ static void set_prop_arraylen(Object *obj, Visitor *v, const char *name,
*arrayptr = eltptr = g_malloc0(*alenptr * prop->arrayfieldsize);
for (i = 0; i < *alenptr; i++, eltptr += prop->arrayfieldsize) {
g_autofree char *propname = g_strdup_printf("%s[%d]", arrayname, i);
- ArrayElementProperty *arrayprop = g_new0(ArrayElementProperty, 1);
+ Property *arrayprop = g_new0(Property, 1);
ObjectProperty *elmop;
- arrayprop->prop.info = prop->arrayinfo;
+ arrayprop->info = prop->arrayinfo;
/* This ugly piece of pointer arithmetic sets up the offset so
* that when the underlying get/set hooks call qdev_get_prop_ptr
* they get the right answer despite the array element not actually
* being inside the device struct.
*/
- arrayprop->prop.offset = eltptr - (void *)obj;
- assert(object_field_prop_ptr(obj, &arrayprop->prop) == eltptr);
+ arrayprop->offset = eltptr - (void *)obj;
+ assert(object_field_prop_ptr(obj, arrayprop) == eltptr);
elmop = object_property_add(obj, propname,
- arrayprop->prop.info->name,
- field_prop_getter(arrayprop->prop.info),
- field_prop_setter(arrayprop->prop.info),
+ arrayprop->info->name,
+ field_prop_getter(arrayprop->info),
+ field_prop_setter(arrayprop->info),
array_element_release,
arrayprop);
elmop->allow_set = op->allow_set;
Now that we don't store any additional data about the property in AraryElementStruct, we don't need it anymore. We can just allocate a Property struct directly. Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> --- Change v1 -> v2: * Get rid of the struct, but not of the release function (we still need it, or we will leak the Property struct we allocate) --- 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 | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-)