From patchwork Wed Oct 5 13:35:29 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UmFkaW0gS3LEjW3DocWZ?= X-Patchwork-Id: 9362923 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id ED9B8600C8 for ; Wed, 5 Oct 2016 13:37:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DF5162893D for ; Wed, 5 Oct 2016 13:37:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D23F12898A; Wed, 5 Oct 2016 13:37:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.9 required=2.0 tests=BAYES_00,HK_RANDOM_FROM, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 609392893D for ; Wed, 5 Oct 2016 13:37:05 +0000 (UTC) Received: from localhost ([::1]:49202 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1brmNc-0005WU-FO for patchwork-qemu-devel@patchwork.kernel.org; Wed, 05 Oct 2016 09:37:04 -0400 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 Received: from mx1.redhat.com ([209.132.183.28]:46498) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1brmMo-0005tw-II; Wed, 05 Oct 2016 09:36:14 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F241978224; Wed, 5 Oct 2016 13:36:13 +0000 (UTC) Received: from potion (dhcp-1-247.brq.redhat.com [10.34.1.247]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with SMTP id u95DaA1A023753; Wed, 5 Oct 2016 09:36:10 -0400 Received: by potion (sSMTP sendmail emulation); Wed, 05 Oct 2016 15:36:09 +0200 From: =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= To: qemu-devel@nongnu.org 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 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 05 Oct 2016 13:36:14 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 1/2] qom: add object_new_with_class() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Eduardo Habkost , Rob Herring , Igor Mitsyanko , Alexander Graf , Alistair Francis , Max Filippov , qemu-arm@nongnu.org, Paolo Bonzini , "Edgar E. Iglesias" , =?UTF-8?q?Andreas=20F=C3=A4rber?= , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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ář Reviewed-by: Eduardo Habkost Reviewed-by: Alistair Francis --- 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);