From nobody Wed Nov 5 23:06:48 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1537528549474864.3825484820752; Fri, 21 Sep 2018 04:15:49 -0700 (PDT) Received: from localhost ([::1]:55115 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g3JPY-0006AA-9y for importer@patchew.org; Fri, 21 Sep 2018 07:15:48 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39479) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g3JNp-0005H7-Ag for qemu-devel@nongnu.org; Fri, 21 Sep 2018 07:14:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g3JNm-00084t-3V for qemu-devel@nongnu.org; Fri, 21 Sep 2018 07:14:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40406) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g3JNl-00083s-Qr for qemu-devel@nongnu.org; Fri, 21 Sep 2018 07:13:58 -0400 Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 15849804E2; Fri, 21 Sep 2018 11:13:57 +0000 (UTC) Received: from localhost (ovpn-112-64.ams2.redhat.com [10.36.112.64]) by smtp.corp.redhat.com (Postfix) with ESMTP id B7C0E89B12; Fri, 21 Sep 2018 11:13:49 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Fri, 21 Sep 2018 15:13:31 +0400 Message-Id: <20180921111332.12973-2-marcandre.lureau@redhat.com> In-Reply-To: <20180921111332.12973-1-marcandre.lureau@redhat.com> References: <20180921111332.12973-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 21 Sep 2018 11:13:57 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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] object: recommend a few type check macros 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: Eduardo Habkost , "Michael S. Tsirkin" , Xiao Guangrong , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Igor Mammedov , Paolo Bonzini , =?UTF-8?q?Andreas=20F=C3=A4rber?= , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" I sometime regret that we have to resort to long object{_class}_dynamic_cast() calls instead of having a shorter and more readable macros available, similar to the one recommended by GObject (https://developer.gnome.org/gobject/stable/gtype-conventions.html). Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Eduardo Habkost --- include/qom/object.h | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/include/qom/object.h b/include/qom/object.h index f0b0bf39cc..c16e0bc91e 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -101,24 +101,31 @@ typedef struct InterfaceInfo InterfaceInfo; * * * - * Every type has an #ObjectClass associated with it. #ObjectClass deriva= tives - * are instantiated dynamically but there is only ever one instance for any - * given type. The #ObjectClass typically holds a table of function point= ers - * for the virtual methods implemented by this type. + * Every type has an #ObjectClass associated with it. #ObjectClass + * derivatives are instantiated dynamically but there is only ever one + * instance for any given type. The #ObjectClass typically holds a + * table of function pointers for the virtual methods implemented by + * this type. You can cast an #ObjectClass to a subclass (or + * base-class) type using object_class_dynamic_cast(). * - * Using object_new(), a new #Object derivative will be instantiated. You= can - * cast an #Object to a subclass (or base-class) type using - * object_dynamic_cast(). You typically want to define macro wrappers aro= und - * OBJECT_CHECK() and OBJECT_CLASS_CHECK() to make it easier to convert to= a - * specific type: + * Using object_new(), a new #Object derivative will be instantiated. + * You can cast an #Object to a subclass (or base-class) type using + * object_dynamic_cast(). + * + * You typically want to define macro wrappers to make it easier to + * handle casting: * * * Typecasting macros * * #define MY_DEVICE_GET_CLASS(obj) \ * OBJECT_GET_CLASS(MyDeviceClass, obj, TYPE_MY_DEVICE) + * #define IS_MY_DEVICE_CLASS(klass) \ + * object_class_dynamic_cast(OBJECT_CLASS(klass), TYPE_MY_DEVICE) * #define MY_DEVICE_CLASS(klass) \ * OBJECT_CLASS_CHECK(MyDeviceClass, klass, TYPE_MY_DEVICE) + * #define IS_MY_DEVICE(obj) \ + * object_dynamic_cast(OBJECT(obj), TYPE_MY_DEVICE) * #define MY_DEVICE(obj) \ * OBJECT_CHECK(MyDevice, obj, TYPE_MY_DEVICE) * --=20 2.19.0