From nobody Mon Feb 9 09:08:55 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1604957708; cv=none; d=zohomail.com; s=zohoarc; b=L7aeuj8TPNSmRFHcGXz3rmMf02BcOWVytnLS3C75ugNx0mCqq0B8O/V/lBoEKgTVOXxs6EmIm1STgoF2RysSx6Or2UwmlTrryp+ghdn35jiK1TlIn0X8R5NwOl1CEFra3qnrICaAZFkZmgZqcOVOUdZIjp9rMtOc0rYMxJfynCc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604957708; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=HNZ23P3owjXbOa0F7aY0nEo1VFpb+WZS7l4fYOJpfss=; b=GAA6qFIqr9zM49yLmU1QysnM2yO4/16N/Sh3fAuuMIu99Im4Dpm/T3BpL0Gh4tgS82fxgv1LkY93qJuZtlL4l5oOsysJZc/L6YN1n2QDG3HTI0lbI6L9gkHuSUh/EPtGWwqs4mwIPXFt50skRRHy+Iq3xyB3N8zrTJ8jC8MakQE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1604957708616464.391367248257; Mon, 9 Nov 2020 13:35:08 -0800 (PST) Received: from localhost ([::1]:40564 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kcEod-0003wj-5f for importer@patchew.org; Mon, 09 Nov 2020 16:35:07 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33704) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kcEg7-00041t-Oy for qemu-devel@nongnu.org; Mon, 09 Nov 2020 16:26:19 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:22699) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kcEg5-0005cl-1e for qemu-devel@nongnu.org; Mon, 09 Nov 2020 16:26:19 -0500 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-152-l2vnL5qpMxaYh-KnK_MLPQ-1; Mon, 09 Nov 2020 16:26:13 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C1913879517 for ; Mon, 9 Nov 2020 21:26:12 +0000 (UTC) Received: from localhost (ovpn-114-68.rdu2.redhat.com [10.10.114.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5E13060BF1; Mon, 9 Nov 2020 21:26:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604957176; 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=HNZ23P3owjXbOa0F7aY0nEo1VFpb+WZS7l4fYOJpfss=; b=gcd9trn+DL2TsdLGMjpCikyZk8LdmLb4LdRfWJRcATgahLvjLeUAF8IUZG5F+rU3ZHMzEs f4GEw7N+8wlwkknWcp5Xz+KdUdsBy/enMjNya5Ms9M/o+uU9CzozzUuV9pYE8P86I1BTWb fjwysqJmd5W27YmMMr0C7AkXQo1sDrI= X-MC-Unique: l2vnL5qpMxaYh-KnK_MLPQ-1 From: Eduardo Habkost To: qemu-devel@nongnu.org Subject: [PATCH 8/8] qom: Use qlit to represent property defaults Date: Mon, 9 Nov 2020 16:25:56 -0500 Message-Id: <20201109212556.3934583-9-ehabkost@redhat.com> In-Reply-To: <20201109212556.3934583-1-ehabkost@redhat.com> References: <20201109212556.3934583-1-ehabkost@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.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/09 01:25:23 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_H5=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: Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Markus Armbruster , Eduardo Habkost Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Using QLitObject lets us get rid of most of the .set_default_value functions, and just use object_property_set_default() directly. Signed-off-by: Eduardo Habkost --- include/hw/qdev-properties-system.h | 2 +- include/qom/field-property-internal.h | 4 --- include/qom/field-property.h | 26 ++++++++----------- include/qom/property-types.h | 21 +++++++--------- hw/core/qdev-properties-system.c | 8 ------ qom/field-property.c | 27 ++++++++++++++------ qom/property-types.c | 36 ++++----------------------- 7 files changed, 44 insertions(+), 80 deletions(-) diff --git a/include/hw/qdev-properties-system.h b/include/hw/qdev-properti= es-system.h index 0ac327ae60..a586424a33 100644 --- a/include/hw/qdev-properties-system.h +++ b/include/hw/qdev-properties-system.h @@ -65,7 +65,7 @@ extern const PropertyInfo qdev_prop_pcie_link_width; =20 #define DEFINE_PROP_UUID(_name, _state, _field) \ DEFINE_PROP(_name, _state, _field, qdev_prop_uuid, QemuUUID, \ - .set_default =3D true) + .defval =3D QLIT_QSTR("auto")) =20 #define DEFINE_PROP_AUDIODEV(_n, _s, _f) \ DEFINE_PROP(_n, _s, _f, qdev_prop_audiodev, QEMUSoundCard) diff --git a/include/qom/field-property-internal.h b/include/qom/field-prop= erty-internal.h index 7aa27ce836..09877d9d6f 100644 --- a/include/qom/field-property-internal.h +++ b/include/qom/field-property-internal.h @@ -15,10 +15,6 @@ void field_prop_set_enum(Object *obj, Visitor *v, const = char *name, =20 void field_prop_set_default_value_enum(ObjectProperty *op, const Property *prop); -void field_prop_set_default_value_int(ObjectProperty *op, - const Property *prop); -void field_prop_set_default_value_uint(ObjectProperty *op, - const Property *prop); =20 void field_prop_get_int32(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp); diff --git a/include/qom/field-property.h b/include/qom/field-property.h index bc866e1c93..b83b424a5e 100644 --- a/include/qom/field-property.h +++ b/include/qom/field-property.h @@ -6,6 +6,7 @@ =20 #include "qom/object.h" #include "qapi/util.h" +#include "qapi/qmp/qlit.h" =20 /** * struct Property: definition of a field property @@ -29,21 +30,8 @@ struct Property { const PropertyInfo *info; ptrdiff_t offset; uint8_t bitnr; - /** - * @set_default: true if the default value should be set from @defval, - * in which case @info->set_default_value must not be NULL - * (if false then no default value is set by the property system - * and the field retains whatever value it was given by instance_i= nit). - */ - bool set_default; - /** - * @defval: default value for the property. This is used only if @set_= default - * is true. - */ - union { - int64_t i; - uint64_t u; - } defval; + /** @defval: If not QNull, the default value for the property */ + QLitObject defval; /* private: */ int arrayoffset; const PropertyInfo *arrayinfo; @@ -63,7 +51,13 @@ struct PropertyInfo { const QEnumLookup *enum_table; /** @print: String formatting function, for the human monitor */ int (*print)(Object *obj, Property *prop, char *dest, size_t len); - /** @set_default_value: Callback for initializing the default value */ + /** + * @set_default_value: Optional callback for initializing the default = value + * + * Most property types don't need to set this, as by default + * object_property_set_default() is called with the value at + * Property.defval. + */ void (*set_default_value)(ObjectProperty *op, const Property *prop); /** @create: Optional callback for creation of property */ ObjectProperty *(*create)(ObjectClass *oc, const char *name, diff --git a/include/qom/property-types.h b/include/qom/property-types.h index 3a36e1fec5..36ca6f9e55 100644 --- a/include/qom/property-types.h +++ b/include/qom/property-types.h @@ -5,6 +5,7 @@ #define QOM_PROPERTY_TYPES_H =20 #include "qom/field-property.h" +#include "qapi/qmp/qlit.h" =20 extern const PropertyInfo prop_info_bit; extern const PropertyInfo prop_info_bit64; @@ -28,13 +29,14 @@ extern const PropertyInfo prop_info_link; .info =3D &(_prop), \ .offset =3D offsetof(_state, _field) \ + type_check(_type, typeof_field(_state, _field)), \ + .defval =3D QLIT_QNULL, \ + /* Note that __VA_ARGS__ can still override .defval */ \ __VA_ARGS__ \ } =20 #define DEFINE_PROP_SIGNED(_name, _state, _field, _defval, _prop, _type) \ DEFINE_PROP(_name, _state, _field, _prop, _type, \ - .set_default =3D true, = \ - .defval.i =3D (_type)_defval) + .defval =3D QLIT_QNUM_INT(_defval)) =20 #define DEFINE_PROP_SIGNED_NODEFAULT(_name, _state, _field, _prop, _type) \ DEFINE_PROP(_name, _state, _field, _prop, _type) @@ -50,13 +52,11 @@ extern const PropertyInfo prop_info_link; #define DEFINE_PROP_BIT(_name, _state, _field, _bit, _defval) \ DEFINE_PROP(_name, _state, _field, prop_info_bit, uint32_t, \ .bitnr =3D (_bit), \ - .set_default =3D true, \ - .defval.u =3D (bool)_defval) + .defval =3D QLIT_QBOOL(_defval)) =20 #define DEFINE_PROP_UNSIGNED(_name, _state, _field, _defval, _prop, _type)= \ DEFINE_PROP(_name, _state, _field, _prop, _type, = \ - .set_default =3D true, = \ - .defval.u =3D (_type)_defval) + .defval =3D QLIT_QNUM_UINT(_defval)) =20 #define DEFINE_PROP_UNSIGNED_NODEFAULT(_name, _state, _field, _prop, _type= ) \ DEFINE_PROP(_name, _state, _field, _prop, _type) @@ -72,8 +72,7 @@ extern const PropertyInfo prop_info_link; #define DEFINE_PROP_BIT64(_name, _state, _field, _bit, _defval) \ DEFINE_PROP(_name, _state, _field, prop_info_bit64, uint64_t, \ .bitnr =3D (_bit), \ - .set_default =3D true, \ - .defval.u =3D (bool)_defval) + .defval =3D QLIT_QBOOL(_defval)) =20 /** * DEFINE_PROP_BOOL: @@ -84,8 +83,7 @@ extern const PropertyInfo prop_info_link; */ #define DEFINE_PROP_BOOL(_name, _state, _field, _defval) \ DEFINE_PROP(_name, _state, _field, prop_info_bool, bool, \ - .set_default =3D true, \ - .defval.u =3D (bool)_defval) + .defval =3D QLIT_QBOOL(_defval)) =20 #define PROP_ARRAY_LEN_PREFIX "len-" =20 @@ -118,8 +116,7 @@ extern const PropertyInfo prop_info_link; _arrayfield, _arrayprop, _arraytype) \ DEFINE_PROP((PROP_ARRAY_LEN_PREFIX _name), \ _state, _field, prop_info_arraylen, uint32_t, \ - .set_default =3D true, \ - .defval.u =3D 0, \ + .defval =3D QLIT_QNUM_UINT(0), \ .arrayinfo =3D &(_arrayprop), \ .arrayfieldsize =3D sizeof(_arraytype), \ .arrayoffset =3D offsetof(_state, _arrayfield)) diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-sys= tem.c index 8da68f076c..d9be5372f6 100644 --- a/hw/core/qdev-properties-system.c +++ b/hw/core/qdev-properties-system.c @@ -570,7 +570,6 @@ const PropertyInfo qdev_prop_blocksize =3D { " and " MAX_BLOCK_SIZE_STR, .get =3D field_prop_get_size32, .set =3D set_blocksize, - .set_default_value =3D field_prop_set_default_value_uint, }; =20 /* --- Block device error handling policy --- */ @@ -768,7 +767,6 @@ const PropertyInfo qdev_prop_pci_devfn =3D { .print =3D print_pci_devfn, .get =3D field_prop_get_int32, .set =3D set_pci_devfn, - .set_default_value =3D field_prop_set_default_value_int, }; =20 /* --- pci host address --- */ @@ -1080,16 +1078,10 @@ static void set_uuid(Object *obj, Visitor *v, const= char *name, void *opaque, g_free(str); } =20 -static void set_default_uuid_auto(ObjectProperty *op, const Property *prop) -{ - object_property_set_default_str(op, UUID_VALUE_AUTO); -} - const PropertyInfo qdev_prop_uuid =3D { .name =3D "str", .description =3D "UUID (aka GUID) or \"" UUID_VALUE_AUTO "\" for random value (default)", .get =3D get_uuid, .set =3D set_uuid, - .set_default_value =3D set_default_uuid_auto, }; diff --git a/qom/field-property.c b/qom/field-property.c index 25a818bb69..727d7199ae 100644 --- a/qom/field-property.c +++ b/qom/field-property.c @@ -47,6 +47,20 @@ static ObjectPropertyAccessor *field_prop_setter(const P= ropertyInfo *info) return info->set ? field_prop_set : NULL; } =20 +static void field_prop_set_default_value(ObjectProperty *op, + Property *prop) +{ + if (qlit_type(&prop->defval) =3D=3D QTYPE_QNULL) { + return; + } + + if (prop->info->set_default_value) { + prop->info->set_default_value(op, prop); + } else { + object_property_set_default(op, qobject_from_qlit(&prop->defval)); + } +} + ObjectProperty * object_property_add_field(Object *obj, const char *name, Property *prop, ObjectPropertyAllowSet allow_set) @@ -65,11 +79,9 @@ object_property_add_field(Object *obj, const char *name,= Property *prop, object_property_set_description(obj, name, prop->info->description); =20 - if (prop->set_default) { - prop->info->set_default_value(op, prop); - if (op->init) { - op->init(obj, op); - } + field_prop_set_default_value(op, prop); + if (op->init) { + op->init(obj, op); } =20 op->allow_set =3D allow_set; @@ -95,9 +107,8 @@ object_class_property_add_field(ObjectClass *oc, const c= har *name, prop->info->release, prop); } - if (prop->set_default) { - prop->info->set_default_value(op, prop); - } + + field_prop_set_default_value(op, prop); if (prop->info->description) { object_class_property_set_description(oc, name, prop->info->description); diff --git a/qom/property-types.c b/qom/property-types.c index f566c05ec2..8bed83c712 100644 --- a/qom/property-types.c +++ b/qom/property-types.c @@ -28,8 +28,11 @@ void field_prop_set_enum(Object *obj, Visitor *v, const = char *name, void field_prop_set_default_value_enum(ObjectProperty *op, const Property *prop) { - object_property_set_default_str(op, - qapi_enum_lookup(prop->info->enum_table, prop->defval.i)); + QObject *defval =3D qobject_from_qlit(&prop->defval); + const char *str =3D qapi_enum_lookup(prop->info->enum_table, + qnum_get_int(qobject_to(QNum, defva= l))); + object_property_set_default_str(op, str); + qobject_unref(defval); } =20 const PropertyInfo prop_info_enum =3D { @@ -80,17 +83,11 @@ static void prop_set_bit(Object *obj, Visitor *v, const= char *name, bit_prop_set(obj, prop, value); } =20 -static void set_default_value_bool(ObjectProperty *op, const Property *pro= p) -{ - object_property_set_default_bool(op, prop->defval.u); -} - const PropertyInfo prop_info_bit =3D { .name =3D "bool", .description =3D "on/off", .get =3D prop_get_bit, .set =3D prop_set_bit, - .set_default_value =3D set_default_value_bool, }; =20 /* Bit64 */ @@ -139,7 +136,6 @@ const PropertyInfo prop_info_bit64 =3D { .description =3D "on/off", .get =3D prop_get_bit64, .set =3D prop_set_bit64, - .set_default_value =3D set_default_value_bool, }; =20 /* --- bool --- */ @@ -166,7 +162,6 @@ const PropertyInfo prop_info_bool =3D { .name =3D "bool", .get =3D get_bool, .set =3D set_bool, - .set_default_value =3D set_default_value_bool, }; =20 /* --- 8bit integer --- */ @@ -189,23 +184,10 @@ static void set_uint8(Object *obj, Visitor *v, const = char *name, void *opaque, visit_type_uint8(v, name, ptr, errp); } =20 -void field_prop_set_default_value_int(ObjectProperty *op, - const Property *prop) -{ - object_property_set_default_int(op, prop->defval.i); -} - -void field_prop_set_default_value_uint(ObjectProperty *op, - const Property *prop) -{ - object_property_set_default_uint(op, prop->defval.u); -} - const PropertyInfo prop_info_uint8 =3D { .name =3D "uint8", .get =3D get_uint8, .set =3D set_uint8, - .set_default_value =3D field_prop_set_default_value_uint, }; =20 /* --- 16bit integer --- */ @@ -232,7 +214,6 @@ const PropertyInfo prop_info_uint16 =3D { .name =3D "uint16", .get =3D get_uint16, .set =3D set_uint16, - .set_default_value =3D field_prop_set_default_value_uint, }; =20 /* --- 32bit integer --- */ @@ -277,14 +258,12 @@ const PropertyInfo prop_info_uint32 =3D { .name =3D "uint32", .get =3D get_uint32, .set =3D set_uint32, - .set_default_value =3D field_prop_set_default_value_uint, }; =20 const PropertyInfo prop_info_int32 =3D { .name =3D "int32", .get =3D field_prop_get_int32, .set =3D set_int32, - .set_default_value =3D field_prop_set_default_value_int, }; =20 /* --- 64bit integer --- */ @@ -329,14 +308,12 @@ const PropertyInfo prop_info_uint64 =3D { .name =3D "uint64", .get =3D get_uint64, .set =3D set_uint64, - .set_default_value =3D field_prop_set_default_value_uint, }; =20 const PropertyInfo prop_info_int64 =3D { .name =3D "int64", .get =3D get_int64, .set =3D set_int64, - .set_default_value =3D field_prop_set_default_value_int, }; =20 /* --- string --- */ @@ -431,7 +408,6 @@ const PropertyInfo prop_info_size32 =3D { .name =3D "size", .get =3D field_prop_get_size32, .set =3D set_size32, - .set_default_value =3D field_prop_set_default_value_uint, }; =20 /* --- support for array properties --- */ @@ -494,7 +470,6 @@ const PropertyInfo prop_info_arraylen =3D { .name =3D "uint32", .get =3D get_uint32, .set =3D set_prop_arraylen, - .set_default_value =3D field_prop_set_default_value_uint, }; =20 /* --- 64bit unsigned int 'size' type --- */ @@ -521,7 +496,6 @@ const PropertyInfo prop_info_size =3D { .name =3D "size", .get =3D get_size, .set =3D set_size, - .set_default_value =3D field_prop_set_default_value_uint, }; =20 /* --- object link property --- */ --=20 2.28.0