[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 03/10] rust: qom: add object creation functionality
From: |
Paolo Bonzini |
Subject: |
Re: [PATCH 03/10] rust: qom: add object creation functionality |
Date: |
Thu, 6 Feb 2025 08:39:01 +0100 |
On Thu, Feb 6, 2025 at 8:29 AM Zhao Liu <zhao1.liu@intel.com> wrote:
> The ref count of Owned<> is decreased on exit, so we need to use
> sysbus_realize() instead of sysbus_realize_and_unref() to ensure ref
> count is correct at C side.
>
> Initially, I hesitated here for an entire morning because this didn't
> seem to conform to the usual usage of sysbus_realize_and_unref() (or,
> further, qdev_realize_and_unref()).
>
> But now I realize that qdev_realize() is used for embedded objects,
> while qdev_realize_and_unref() is used for non-embedded cases. Therefore,
> moving forward, perhaps qdev_realize_and_unref() should not exist on the
> Rust side.
Correct, all unref() operations are handled implicitly by the Drop
implementation of Owned<>
> Owned<> will automatically drop and thus automatically unref, while
> Child<> will not unref.
No, Child<> will also unref. The point of Child<> is to prolong the
life of the child object, so that it dies after instance_finalize
instead() of dying during object_property_del_all(). In C that has to
be done manually (as is the case in the clock creation functions), in
Rust it will be enforced by the type system.
> In the future, maybe we need some wrappers on qdev_realize()/sysbus_realize().
Yep, I'll add a conversion of pl011_create to safe Rust to clarify the
rules around usage of Owned<>.
Paolo