qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Radim Krčmář" <rkrcmar@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Igor Mitsyanko" <i.mitsyanko@gmail.com>,
	"Peter Maydell" <peter.maydell@linaro.org>,
	"Rob Herring" <robh@kernel.org>,
	"Edgar E. Iglesias" <edgar.iglesias@gmail.com>,
	"Alistair Francis" <alistair.francis@xilinx.com>,
	"Andreas Färber" <afaerber@suse.de>,
	"Richard Henderson" <rth@twiddle.net>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Eduardo Habkost" <ehabkost@redhat.com>,
	"Alexander Graf" <agraf@suse.de>,
	"Max Filippov" <jcmvbkbc@gmail.com>,
	qemu-arm@nongnu.org
Subject: [Qemu-devel] [PATCH 1/2] qom: add object_new_with_class()
Date: Wed,  5 Oct 2016 15:35:29 +0200	[thread overview]
Message-ID: <20161005133530.5702-2-rkrcmar@redhat.com> (raw)
In-Reply-To: <20161005133530.5702-1-rkrcmar@redhat.com>

object_new_with_object_class() was a close contender for the name, but
it is longer, the type system will catch possible errors, and the only
reasonable replacement would be a polymorphic function that would not
break existing users.

Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
---
 include/qom/object.h | 12 ++++++++++++
 qom/object.c         |  5 +++++
 2 files changed, 17 insertions(+)

diff --git a/include/qom/object.h b/include/qom/object.h
index 5ecc2d166d08..e50012237ce4 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -599,6 +599,18 @@ Object *object_new(const char *typename);
 Object *object_new_with_type(Type type);
 
 /**
+ * object_new_with_class:
+ * @class: The object class of the object to instantiate.
+ *
+ * This function will initialize a new object using heap allocated memory.
+ * The returned object has a reference count of 1, and will be freed when
+ * the last reference is dropped.
+ *
+ * Returns: The newly allocated and instantiated object.
+ */
+Object *object_new_with_class(ObjectClass *class);
+
+/**
  * object_new_with_props:
  * @typename:  The name of the type of the object to instantiate.
  * @parent: the parent object
diff --git a/qom/object.c b/qom/object.c
index 8166b7dace61..be75d6efc464 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -481,6 +481,11 @@ Object *object_new_with_type(Type type)
     return obj;
 }
 
+Object *object_new_with_class(ObjectClass *class)
+{
+    return object_new_with_type(class->type);
+}
+
 Object *object_new(const char *typename)
 {
     TypeImpl *ti = type_get_by_name(typename);
-- 
2.10.0

  reply	other threads:[~2016-10-05 13:36 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-05 13:35 [Qemu-devel] [PATCH 0/2] qom+coccinelle: add and use object_new_with_class() Radim Krčmář
2016-10-05 13:35 ` Radim Krčmář [this message]
2016-10-05 14:44   ` [Qemu-devel] [PATCH 1/2] qom: add object_new_with_class() Eduardo Habkost
2016-10-05 15:54     ` Alistair Francis
2016-10-05 13:35 ` [Qemu-devel] [PATCH 2/2] coccinelle: use object_new_with_class() in obvious cases Radim Krčmář
2016-10-05 14:44   ` Eduardo Habkost
2016-10-05 15:56     ` Alistair Francis
2016-10-05 13:42 ` [Qemu-devel] [PATCH 0/2] qom+coccinelle: add and use object_new_with_class() Radim Krčmář
2016-11-03 16:54 ` Markus Armbruster
2016-11-03 19:16   ` Eduardo Habkost

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=20161005133530.5702-2-rkrcmar@redhat.com \
    --to=rkrcmar@redhat.com \
    --cc=afaerber@suse.de \
    --cc=agraf@suse.de \
    --cc=alistair.francis@xilinx.com \
    --cc=edgar.iglesias@gmail.com \
    --cc=ehabkost@redhat.com \
    --cc=i.mitsyanko@gmail.com \
    --cc=jcmvbkbc@gmail.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=robh@kernel.org \
    --cc=rth@twiddle.net \
    /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).