[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 06/22] char: add a /chardevs container
From: |
Paolo Bonzini |
Subject: |
Re: [Qemu-devel] [PATCH 06/22] char: add a /chardevs container |
Date: |
Fri, 10 Feb 2017 13:26:37 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 |
On 10/02/2017 13:14, Marc-André Lureau wrote:
> Hi
>
> On Fri, Feb 10, 2017 at 4:18 AM Paolo Bonzini <address@hidden
> <mailto:address@hidden>> wrote:
>
>
>
> On 07/02/2017 21:03, Marc-André Lureau wrote:
> > Hi
> >
> > ----- Original Message -----
> >>
> >>
> >> On 02/02/2017 15:51, Marc-André Lureau wrote:
> >>> + if (QTAILQ_IN_USE(chr, next)) {
> >>> + QTAILQ_REMOVE(&chardevs, chr, next);
> >>> + }
> >>> + if (OBJECT(chr)->parent) {
> >>> + object_unparent(OBJECT(chr));
> >>> + } else {
> >>> + object_unref(OBJECT(chr));
> >>> + }
> >>
> >> What's the case where the "else" is used? Probably qemu_chr_delete
> >> callers should be changed to use object_unparent or object_unref
> directly.
> >
> > I thought about that, but calling object_unparent() seems weird,
> > since callers aren't much aware of the fact that chardev are added
> or not to a
> > container (useless distinction imho). I wish the last object_unref()
> > would automatically unparent, if the object has a parent. Would
> that be
> > acceptable?
>
> There is a distinction between the two. The idea is that unparent
> removes all persistent references in the object tree, while unref only
> removes transient references. So for example unparent will detach a
> device from its bus. Unparent is basically exploiting the object tree
> in order to simplify the handling of reference cycles.
>
> Once you add an object with object_property_add_child, you probably
> should remove any transient references you have (such as the one you got
> with object_new) and from that point on use object_unparent only.
>
>
> But if you unparent with the last ref, you remove the burden of knowing
> if the object has been parented from the user. I don't see why that
> would conflict with object_unparent(), you could still unparent(), and
> keep the object referenced somewhere else.
Isn't that exactly why you want them to be different? unparent can do
much more than unref, for example in the case of a device it will also
unrealize it and destroy all buses underneath it. Because the device
and bus have a circular reference, you cannot trigger the magic unparent
behavior just by unref'ing the device.
There are just two cases:
- destruction immediately after creation, e.g. on error: new/unref
- successful creation: new/add_child/unref, unparent when deleting
and it's simpler to remember these two than to add magic behavior.
> The two are not incompatible
> to me. Afaik, most widget/hierarchy API work like that, the last unref
> will implicitely unparent.
LibreOffice's has some similarity with QOM, search for "dispose" at
https://people.gnome.org/~michael/blog/2015-08-05-under-the-hood-5-0.html
Paolo
- [Qemu-devel] [PATCH 04/22] container: don't leak container reference, (continued)
- [Qemu-devel] [PATCH 06/22] char: add a /chardevs container, Marc-André Lureau, 2017/02/02
- Re: [Qemu-devel] [PATCH 06/22] char: add a /chardevs container, Paolo Bonzini, 2017/02/06
- Re: [Qemu-devel] [PATCH 06/22] char: add a /chardevs container, Marc-André Lureau, 2017/02/07
- Re: [Qemu-devel] [PATCH 06/22] char: add a /chardevs container, Paolo Bonzini, 2017/02/09
- Re: [Qemu-devel] [PATCH 06/22] char: add a /chardevs container, Marc-André Lureau, 2017/02/10
- Re: [Qemu-devel] [PATCH 06/22] char: add a /chardevs container,
Paolo Bonzini <=
- Re: [Qemu-devel] [PATCH 06/22] char: add a /chardevs container, Marc-André Lureau, 2017/02/10
- Re: [Qemu-devel] [PATCH 06/22] char: add a /chardevs container, Paolo Bonzini, 2017/02/10
[Qemu-devel] [PATCH 07/22] char: use /chardevs container instead of chardevs list, Marc-André Lureau, 2017/02/02
[Qemu-devel] [PATCH 08/22] char: remove qemu_chardev_add, Marc-André Lureau, 2017/02/02
[Qemu-devel] [PATCH 09/22] char: remove chardevs list, Marc-André Lureau, 2017/02/02
[Qemu-devel] [PATCH 10/22] char: useless NULL check, Marc-André Lureau, 2017/02/02
[Qemu-devel] [PATCH 11/22] qcow2: remove useless NULL check, Marc-André Lureau, 2017/02/02
[Qemu-devel] [PATCH 12/22] char-socket: introduce update_disconnected_filename(), Marc-André Lureau, 2017/02/02
[Qemu-devel] [PATCH 13/22] char-socket: update local address after listen, Marc-André Lureau, 2017/02/02