qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: armbru@redhat.com
Subject: [PATCH 2/5] qom: use object_new_with_class when possible
Date: Tue, 29 Oct 2024 13:26:06 +0100	[thread overview]
Message-ID: <20241029122609.514347-3-pbonzini@redhat.com> (raw)
In-Reply-To: <20241029122609.514347-1-pbonzini@redhat.com>

A small optimization/code simplification, that also makes it clear that
we won't look for a type in a not-loaded-yet module---the module will
have been loaded by a call to module_object_class_by_name(), if present.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 hw/core/qdev.c          | 5 +++--
 qom/object_interfaces.c | 2 +-
 qom/qom-qmp-cmds.c      | 2 +-
 3 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/hw/core/qdev.c b/hw/core/qdev.c
index 17c454334c6..5f13111b77c 100644
--- a/hw/core/qdev.c
+++ b/hw/core/qdev.c
@@ -151,10 +151,11 @@ DeviceState *qdev_new(const char *name)
 
 DeviceState *qdev_try_new(const char *name)
 {
-    if (!module_object_class_by_name(name)) {
+    ObjectClass *oc = module_object_class_by_name(name);
+    if (!oc) {
         return NULL;
     }
-    return DEVICE(object_new(name));
+    return DEVICE(object_new_with_class(oc));
 }
 
 static QTAILQ_HEAD(, DeviceListener) device_listeners
diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c
index e0833c8bfe4..1f2aa133066 100644
--- a/qom/object_interfaces.c
+++ b/qom/object_interfaces.c
@@ -108,7 +108,7 @@ Object *user_creatable_add_type(const char *type, const char *id,
     }
 
     assert(qdict);
-    obj = object_new(type);
+    obj = object_new_with_class(klass);
     object_set_properties_from_qdict(obj, qdict, v, &local_err);
     if (local_err) {
         goto out;
diff --git a/qom/qom-qmp-cmds.c b/qom/qom-qmp-cmds.c
index e91a2353472..69a8e17aa80 100644
--- a/qom/qom-qmp-cmds.c
+++ b/qom/qom-qmp-cmds.c
@@ -141,7 +141,7 @@ ObjectPropertyInfoList *qmp_device_list_properties(const char *typename,
         return NULL;
     }
 
-    obj = object_new(typename);
+    obj = object_new_with_class(klass);
 
     object_property_iter_init(&iter, obj);
     while ((prop = object_property_iter_next(&iter))) {
-- 
2.47.0



  parent reply	other threads:[~2024-10-29 12:27 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-29 12:26 [PATCH 0/5] qom: module loading cleanups Paolo Bonzini
2024-10-29 12:26 ` [PATCH 1/5] qom: remove unused function Paolo Bonzini
2024-10-29 12:35   ` Daniel P. Berrangé
2024-10-29 12:26 ` Paolo Bonzini [this message]
2024-10-29 19:51   ` [PATCH 2/5] qom: use object_new_with_class when possible Philippe Mathieu-Daudé
2024-10-29 12:26 ` [PATCH 3/5] qom: centralize module-loading functionality Paolo Bonzini
2024-10-29 12:26 ` [PATCH 4/5] qom: let object_new use a module if the type is not present Paolo Bonzini
2024-10-29 12:26 ` [PATCH 5/5] qom: allow user-creatable classes to be in modules Paolo Bonzini
2024-10-29 17:05 ` [PATCH 0/5] qom: module loading cleanups Richard Henderson

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=20241029122609.514347-3-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=armbru@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).