On Thu, May 22, 2014 at 12:05 AM, Paolo Bonzini <pbonz...@redhat.com> wrote: > Il 21/05/2014 22:22, Stefan Hajnoczi ha scritto: >> +void object_property_add_alias(Object *obj, const char *name, >> + Object *target_obj, const char >> *target_name, >> + Error **errp) >> +{ >> + AliasProperty *prop; >> + ObjectProperty *target_prop; >> + >> + target_prop = object_property_find(target_obj, target_name, errp); >> + if (!target_prop) { >> + return; >> + } >> + >> + prop = g_malloc(sizeof(*prop)); >> + prop->target_obj = target_obj; >> + prop->target_name = target_name; >> + >> + object_property_add(obj, name, target_prop->type, >> + property_get_alias, >> + property_set_alias, >> + property_release_alias, >> + prop, errp); >> +} > > > ref target_obj here, and unref in property_release_alias?
No. I originally did this but realized it is probably not a good idea. 1. If you want to alias a property on the same object instance (foo.a -> foo.b) this would create a refcount leak (unless someone explicitly deletes this property to bring the refcount back to 1). 2. The virtio callers already have a child reference and I suspect other callers would too. Therefore we don't need to do extra refcounting. I had an intermediate version of this patch with a flag so you could tell object_property_add_alias() whether or not to ref the target object. But in the end it seems like overengineering since the refcount case is rare or non-existent. The refcount is a convenience feature just for the case where you want to alias to a random object that you don't otherwise hold a refcount on (I couldn't think of an example). Do you see what I mean? Stefan