From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47711) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1brmN3-0005UM-KN for qemu-devel@nongnu.org; Wed, 05 Oct 2016 09:36:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1brmMy-0005wn-Kn for qemu-devel@nongnu.org; Wed, 05 Oct 2016 09:36:28 -0400 From: =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= Date: Wed, 5 Oct 2016 15:35:29 +0200 Message-Id: <20161005133530.5702-2-rkrcmar@redhat.com> In-Reply-To: <20161005133530.5702-1-rkrcmar@redhat.com> References: <20161005133530.5702-1-rkrcmar@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH 1/2] qom: add object_new_with_class() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Igor Mitsyanko , Peter Maydell , Rob Herring , "Edgar E. Iglesias" , Alistair Francis , =?UTF-8?q?Andreas=20F=C3=A4rber?= , Richard Henderson , Paolo Bonzini , Eduardo Habkost , Alexander Graf , Max Filippov , qemu-arm@nongnu.org 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=C4=8Dm=C3=A1=C5=99 --- 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); =20 /** + * object_new_with_class: + * @class: The object class of the object to instantiate. + * + * This function will initialize a new object using heap allocated memor= y. + * The returned object has a reference count of 1, and will be freed whe= n + * 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; } =20 +Object *object_new_with_class(ObjectClass *class) +{ + return object_new_with_type(class->type); +} + Object *object_new(const char *typename) { TypeImpl *ti =3D type_get_by_name(typename); --=20 2.10.0