From patchwork Thu Nov 12 21:43:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eduardo Habkost X-Patchwork-Id: 11901907 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5098C16C0 for ; Thu, 12 Nov 2020 22:22:23 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D5B30206C0 for ; Thu, 12 Nov 2020 22:22:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="GTzhHUIS" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D5B30206C0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:42392 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kdKyz-0007cL-P2 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 12 Nov 2020 17:22:21 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:34222) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kdKRE-00006u-5e for qemu-devel@nongnu.org; Thu, 12 Nov 2020 16:47:28 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:23200) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kdKRC-0003nG-82 for qemu-devel@nongnu.org; Thu, 12 Nov 2020 16:47:27 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605217645; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0515GEVNq/EtBK0e9C2VJclhRHGVHipxK5dgMOIhNoA=; b=GTzhHUISiwApRCgcH2eA4lV9ZElN2sZRxedQIIZaQaf4q4wrCBEBolJvdzWF84WwcEYjCf V1u16Gx6NuLMMCJkW3DLemDI5XgYWRy6daFLh1g+ewc9B2x0G3vfJgSOxX5GSXDB8034qM DkRNhHg97swQdYqO9Ruk4ard2cDi4go= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-105-pc4ua6X1MwymxfChUOHSTQ-1; Thu, 12 Nov 2020 16:47:19 -0500 X-MC-Unique: pc4ua6X1MwymxfChUOHSTQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 63854805EF7; Thu, 12 Nov 2020 21:47:18 +0000 (UTC) Received: from localhost (ovpn-114-68.rdu2.redhat.com [10.10.114.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id E1E2910016DA; Thu, 12 Nov 2020 21:47:17 +0000 (UTC) From: Eduardo Habkost To: qemu-devel@nongnu.org Subject: [PATCH v3 49/53] qom: FIELD_PROP macro Date: Thu, 12 Nov 2020 16:43:46 -0500 Message-Id: <20201112214350.872250-50-ehabkost@redhat.com> In-Reply-To: <20201112214350.872250-1-ehabkost@redhat.com> References: <20201112214350.872250-1-ehabkost@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=ehabkost@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=ehabkost@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/12 08:00:44 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , "Daniel P. Berrange" , John Snow , Markus Armbruster , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Marc?= =?utf-8?q?-Andr=C3=A9_Lureau?= , Paolo Bonzini , Igor Mammedov , Stefan Berger Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" The FIELD_PROP macro can be used to define a Property struct when initializing static variables, or as a function parameter (e.g. as a paramter to object_class_property_add_field()). The qdev-specific DEFINE_PROP macro can be defined using the new macro. The only difference is that DEFINE_PROP gets the property name as the first argument. Signed-off-by: Eduardo Habkost --- This is a new patch added in v3 of this series. --- Cc: Paolo Bonzini Cc: "Daniel P. Berrangé" Cc: Eduardo Habkost Cc: qemu-devel@nongnu.org --- include/qom/field-property.h | 17 +++++++++++++++++ include/qom/property-types.h | 26 +++++++++++++++++++------- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/include/qom/field-property.h b/include/qom/field-property.h index a904f98609..0cb1fe2217 100644 --- a/include/qom/field-property.h +++ b/include/qom/field-property.h @@ -108,4 +108,21 @@ object_class_property_add_field(ObjectClass *oc, const char *name, void *object_field_prop_ptr(Object *obj, Property *prop); +/** + * FIELD_PROP: Expands to a compound literal for a #Property struct + * + * @_state: name of the object state structure type + * @_field: name of field in @_state + * @_prop: name of #PropertyInfo variable with type information + * @_type: expected type of field @_field in struct @_state + * @...: additional initializers for #Property struct fields + */ +#define FIELD_PROP(_state, _field, _prop, _type, ...) \ + (Property) { \ + .info = &(_prop), \ + .offset = offsetof(_state, _field) \ + + type_check(_type, typeof_field(_state, _field)), \ + __VA_ARGS__ \ + } + #endif diff --git a/include/qom/property-types.h b/include/qom/property-types.h index 46c82da4e3..62551c77e0 100644 --- a/include/qom/property-types.h +++ b/include/qom/property-types.h @@ -23,13 +23,25 @@ extern const PropertyInfo prop_info_size32; extern const PropertyInfo prop_info_arraylen; extern const PropertyInfo prop_info_link; -#define DEFINE_PROP(_name, _state, _field, _prop, _type, ...) { \ - .name_template = (_name), \ - .info = &(_prop), \ - .offset = offsetof(_state, _field) \ - + type_check(_type, typeof_field(_state, _field)), \ - __VA_ARGS__ \ - } +/** + * DEFINE_PROP: Define a #Property struct, including a property name + * + * @_name: name of the property + * @_state: name of the object state structure type + * @_field: name of field in @_state + * @_prop: name of #PropertyInfo variable with type information + * @_type: expected type of field @_field in struct @_state + * @...: additional initializers for #Property struct fields + * + * `DEFINE_PROP` or other ``DEFINE_PROP_*`` macros are normally + * used when initialiing static const #Property arrays, to be + * used with object_class_add_field_properties() or + * device_class_set_props(). + */ +#define DEFINE_PROP(_name, _state, _field, _prop, _type, ...) \ + FIELD_PROP(_state, _field, _prop, _type, \ + .name_template = (_name), \ + __VA_ARGS__) #define DEFINE_PROP_SIGNED(_name, _state, _field, _defval, _prop, _type) \ DEFINE_PROP(_name, _state, _field, _prop, _type, \