From: Peter Xu <peterx@redhat.com>
To: "Daniel P. Berrangé" <berrange@redhat.com>
Cc: qemu-devel@nongnu.org, Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [RFC 3/5] convert code to object_new_dynamic() where appropriate
Date: Thu, 31 Oct 2024 15:21:17 -0400 [thread overview]
Message-ID: <ZyPYreQWvtG7bH3P@x1n> (raw)
In-Reply-To: <20241031155350.3240361-4-berrange@redhat.com>
On Thu, Oct 31, 2024 at 03:53:48PM +0000, Daniel P. Berrangé wrote:
> In cases where object_new() is not being passed a static, const
> string, the caller cannot be sure what type they are instantiating.
> There is a risk that instantiation could fail, if it is an abstract
> type.
>
> Convert such cases over to use object_new_dynamic() such that they
> are forced to expect failure. In some cases failure can be easily
> propagated, but in others using &error_abort maintainers existing
> behaviour.
>
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
> chardev/char.c | 5 ++++-
> hw/core/bus.c | 2 +-
> hw/core/cpu-common.c | 2 +-
> hw/core/qdev.c | 4 ++--
> hw/i386/x86-common.c | 5 ++++-
> hw/i386/xen/xen-pvh.c | 2 +-
> hw/vfio/common.c | 6 +++++-
> hw/vfio/container.c | 6 +++++-
> qom/object_interfaces.c | 7 ++-----
> qom/qom-qmp-cmds.c | 15 +++++++++------
> tests/unit/check-qom-interface.c | 3 ++-
> tests/unit/test-smp-parse.c | 20 ++++++++++----------
> 12 files changed, 46 insertions(+), 31 deletions(-)
I think we could leave the test cases alone without _dynamic(), because
they do test static types (even if they used "opaque"..), and they should
really (and forever) assert on failures..
IMHO we should keep _dynamic() usages small if we'd like to introduce it,
only in the paths where its failure will be properly handled. Basically, I
think we shouldn't use _dynamic() if we know it'll be error_abort.. because
that's fundamentally identical to object_new().
A small set of _dynamic() usages also keep us easy to track all the paths
where QEMU can create some totally random objects too.
--
Peter Xu
next prev parent reply other threads:[~2024-10-31 19:22 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-31 15:53 [RFC 0/5] RFC: require error handling for dynamically created objects Daniel P. Berrangé
2024-10-31 15:53 ` [RFC 1/5] qom: refactor checking abstract property when creating instances Daniel P. Berrangé
2024-10-31 15:53 ` [RFC 2/5] qom: allow failure of object_new_with_class Daniel P. Berrangé
2024-10-31 19:09 ` Peter Xu
2024-11-01 11:29 ` Daniel P. Berrangé
2024-10-31 15:53 ` [RFC 3/5] convert code to object_new_dynamic() where appropriate Daniel P. Berrangé
2024-10-31 19:21 ` Peter Xu [this message]
2024-11-01 11:32 ` Daniel P. Berrangé
2024-10-31 15:53 ` [RFC 4/5] qom: introduce object_new_dynamic() Daniel P. Berrangé
2024-10-31 19:22 ` Peter Xu
2024-11-01 11:32 ` Daniel P. Berrangé
2024-10-31 15:53 ` [RFC 5/5] qom: enforce use of static, const string with object_new() Daniel P. Berrangé
2024-10-31 19:32 ` Peter Xu
2024-10-31 19:46 ` [RFC 0/5] RFC: require error handling for dynamically created objects Peter Xu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZyPYreQWvtG7bH3P@x1n \
--to=peterx@redhat.com \
--cc=berrange@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).