qom: Use qlit to represent property defaults
cover qom: Use qlit to represent property defaults
Based-on: [email protected]
Git branch: https://gitlab.com/ehabkost/qemu/-/commits/work/qdev-qlit-defaults
This extend qlit.h to support all QNum types (signed int, unsigned int, and double), and use QLitObject to represent field property defaults.
It allows us to get rid of most type-specific .set_default_value functions for QOM property types.
Eduardo Habkost (8):
qobject: Include API docs in docs/devel/qobject.html
qnum: Make qnum_get_double() get const pointer
qnum: QNumValue type for QNum value literals
qnum: qnum_value_is_equal() function
qlit: Support all types of QNums
qlit: qlit_type() function
qom: Make object_property_set_default() public
qom: Use qlit to represent property defaults
docs/devel/index.rst | 1 + docs/devel/qobject.rst | 11 +++ include/hw/qdev-properties-system.h | 2 +- include/qapi/qmp/qlit.h | 16 +++- include/qapi/qmp/qnum.h | 47 ++++++++++- include/qapi/qmp/qobject.h | 48 +++++++---- include/qom/field-property-internal.h | 4 - include/qom/field-property.h | 26 +++--- include/qom/object.h | 11 +++ include/qom/property-types.h | 21 ++--- hw/core/qdev-properties-system.c | 8 -- qobject/qlit.c | 4 +- qobject/qnum.c | 116 +++++++++++++++----------- qom/field-property.c | 27 ++++-- qom/object.c | 2 +- qom/property-types.c | 36 ++------ tests/check-qjson.c | 72 ++++++++++++++-- 17 files changed, 295 insertions(+), 157 deletions(-) create mode 100644 docs/devel/qobject.rst
Signature · 1 line
2.28.0
PATCH 1/8 qobject: Include API docs in docs/devel/qobject.html
Render existing doc comments at docs/devel/qobject.html.
--- docs/devel/index.rst | 1 + docs/devel/qobject.rst | 11 +++++++++ include/qapi/qmp/qnum.h | 4 +++- include/qapi/qmp/qobject.h | 48 +++++++++++++++++++++++++------------- qobject/qnum.c | 19 ++++++++++++--- 5 files changed, 63 insertions(+), 20 deletions(-) create mode 100644 docs/devel/qobject.rst
docs/devel/index.rst +1 -0
@@ -34,3 +34,4 @@ Contents: clocks qom block-coroutine-wrapper + qobject
docs/devel/qobject.rst new file +11 -0
@@ -0,0 +1,11 @@ +QObject API +=========== + +.. kernel-doc:: include/qapi/qmp/qobject.h + +QNum module +----------- + +.. kernel-doc:: include/qapi/qmp/qnum.h + +.. kernel-doc:: qobject/qnum.c
include/qapi/qmp/qnum.h +3 -1
@@ -23,7 +23,9 @@ typedef enum { QNUM_DOUBLE } QNumKind; -/* +/** +* DOC: +* * QNum encapsulates how our dialect of JSON fills in the blanks left * by the JSON specification (RFC 8259) regarding numbers. *
include/qapi/qmp/qobject.h +32 -16
97 lines not on this page · raw message
qobject/qnum.c +16 -3
@@ -17,6 +17,7 @@/** * qnum_from_int(): Create a new QNum from an int64_t +* @value: int64_t value * * Return strong reference. */
@@ -33,6 +34,7 @@ QNum *qnum_from_int(int64_t value)/** * qnum_from_uint(): Create a new QNum from an uint64_t +* @value: uint64_t value * * Return strong reference. */
@@ -49,6 +51,7 @@ QNum *qnum_from_uint(uint64_t value)/** * qnum_from_double(): Create a new QNum from a double +* @value: double value * * Return strong reference. */
@@ -65,6 +68,8 @@ QNum *qnum_from_double(double value)/** * qnum_get_try_int(): Get an integer representation of the number +* @qn: QNum object +* @val: pointer to value * * Return true on success. */
@@ -90,6 +95,7 @@ bool qnum_get_try_int(const QNum *qn, int64_t *val)/** * qnum_get_int(): Get an integer representation of the number +* @qn: QNum object * * assert() on failure. */
@@ -102,7 +108,9 @@ int64_t qnum_get_int(const QNum *qn) }/** -* qnum_get_uint(): Get an unsigned integer from the number +* qnum_value_get_try_uint(): Get an unsigned integer from the number +* @qn: QNum object +* @val: pointer to value * * Return true on success. */
@@ -128,6 +136,7 @@ bool qnum_get_try_uint(const QNum *qn, uint64_t *val)/** * qnum_get_uint(): Get an unsigned integer from the number +* @qn: QNum object * * assert() on failure. */
@@ -141,6 +150,7 @@ uint64_t qnum_get_uint(const QNum *qn)/** * qnum_get_double(): Get a float representation of the number +* @qn: QNum object * * qnum_get_double() loses precision for integers beyond 53 bits. */
@@ -200,6 +210,8 @@ char *qnum_to_string(QNum *qn)/** * qnum_is_equal(): Test whether the two QNums are equal +* @x: QNum object +* @y: QNum object * * Negative integers are never considered equal to unsigned integers, * but positive integers in the range [0, INT64_MAX] are considered
@@ -253,8 +265,9 @@ bool qnum_is_equal(const QObject *x, const QObject *y) }/** -* qnum_destroy_obj(): Free all memory allocated by a -* QNum object +* qnum_destroy_obj(): Free all memory allocated by a QNum object +* +* @obj: QNum object to be destroyed */ void qnum_destroy_obj (QObject *obj) {
Signature · 1 line
2.28.0
PATCH 2/8 qnum: Make qnum_get_double() get const pointer
In reply to Eduardo Habkostqnum_get_double() won't change the object, the argument can be const.
--- include/qapi/qmp/qnum.h | 2 +- qobject/qnum.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
include/qapi/qmp/qnum.h +1 -1
@@ -66,7 +66,7 @@ int64_t qnum_get_int(const QNum *qn);bool qnum_get_try_uint (const QNum *qn,uint64_t *val);uint64_t qnum_get_uint (const QNum *qn); -double qnum_get_double (QNum *qn); +double qnum_get_double (const QNum *qn);char *qnum_to_string (QNum *qn);
qobject/qnum.c +1 -1
@@ -154,7 +154,7 @@ uint64_t qnum_get_uint(const QNum *qn)* * qnum_get_double() loses precision for integers beyond 53 bits. */ -double qnum_get_double (QNum *qn) +double qnum_get_double (const QNum *qn) {switch (qn->kind) {case QNUM_I64 :
Signature · 1 line
2.28.0
PATCH 3/8 qnum: QNumValue type for QNum value literals
In reply to Eduardo HabkostProvide a separate QNumValue type that can be used for QNum value literals without the referencing counting and memory allocation features provided by QObject.
--- include/qapi/qmp/qnum.h | 40 +++++++++++++++++++-- qobject/qnum.c | 78 ++++++++++++++++++++--------------------- 2 files changed, 77 insertions(+), 41 deletions(-)
include/qapi/qmp/qnum.h +38 -2
@@ -46,20 +46,56 @@ typedef enum {* in range: qnum_get_try_int() / qnum_get_try_uint() check range and * convert under the hood. */ -struct QNum { -struct QObjectBase_ base; + +/** +* struct QNumValue: the value of a QNum +* +* QNumValue literals can be constructed using the `QNUM_VAL_INT`, +* `QNUM_VAL_UINT`, and `QNUM_VAL_DOUBLE` macros. +*/ +typedef struct QNumValue { +/* private: */ QNumKind kind;union {int64_t i64;uint64_t u64;double dbl; } u; +}QNumValue ; + +#define QNUM_VAL_INT (value) \ + { .kind = QNUM_I64, .u.i64 = value } +#define QNUM_VAL_UINT (value) \ + { .kind = QNUM_U64, .u.u64 = value } +#define QNUM_VAL_DOUBLE (value) \ + { .kind = QNUM_DOUBLE, .u.dbl = value } + +struct QNum { +struct QObjectBase_ base; +QNumValue value; }; +/** +* qnum_from_int(): Create a new QNum from a QNumValue +* @value: QNumValue +* +* Return strong reference. +*/ +QNum *qnum_from_value (QNumValue value); +QNum *qnum_from_int (int64_t value);QNum *qnum_from_uint (uint64_t value);QNum *qnum_from_double (double value); +/** +* qnum_get_value(): Get QNumValue from QNum +* @qn: QNum object +*/ +static inline const QNumValue *qnum_get_value (const QNum *qn) +{ +return &qn->value; +} +bool qnum_get_try_int (const QNum *qn,int64_t *val);int64_t qnum_get_int (const QNum *qn);
qobject/qnum.c +39 -39
156 lines not on this page · raw message
Signature · 1 line
2.28.0
PATCH 4/8 qnum: qnum_value_is_equal() function
In reply to Eduardo HabkostExtract the QNum value comparison logic to a function that takes QNumValue* as argument.
--- include/qapi/qmp/qnum.h | 1 + qobject/qnum.c | 29 +++++++++++++++++++---------- 2 files changed, 20 insertions(+), 10 deletions(-)
include/qapi/qmp/qnum.h +1 -0
@@ -106,6 +106,7 @@ double qnum_get_double(const QNum *qn);char *qnum_to_string (QNum *qn); +bool qnum_value_is_equal (const QNumValue *num_x,const QNumValue *num_y);bool qnum_is_equal (const QObject *x,const QObject *y);void qnum_destroy_obj (QObject *obj);
qobject/qnum.c +19 -10
@@ -207,9 +207,9 @@ char *qnum_to_string(QNum *qn) }/** -* qnum_is_equal(): Test whether the two QNums are equal -* @x: QNum object -* @y: QNum object +* qnum_value_is_equal(): Test whether two QNumValues are equal +* @num_x: QNum value +* @num_y: QNum value * * Negative integers are never considered equal to unsigned integers, * but positive integers in the range [0, INT64_MAX] are considered
@@ -217,13 +217,8 @@ char *qnum_to_string(QNum *qn)* * Doubles are never considered equal to integers. */ -bool qnum_is_equal (const QObject *x,const QObject *y) +bool qnum_value_is_equal (const QNumValue *num_x,const QNumValue *num_y) { -const QNum *qnum_x =qobject_to (QNum, x); -const QNum *qnum_y =qobject_to (QNum, y); -const QNumValue *num_x = &qnum_x->value; -const QNumValue *num_y = &qnum_y->value; -switch (num_x->kind) {case QNUM_I64 :switch (num_y->kind) {
@@ -241,7 +236,7 @@ bool qnum_is_equal(const QObject *x, const QObject *y)case QNUM_U64 :switch (num_y->kind) {case QNUM_I64 : -return qnum_is_equal (y, x); +return qnum_value_is_equal (num_y, num_x);case QNUM_U64 :/* Comparison in native uint64_t type */ return num_x->u.u64 == num_y->u.u64;
@@ -264,6 +259,20 @@ bool qnum_is_equal(const QObject *x, const QObject *y)abort (); } +/** +* qnum_is_equal(): Test whether the two QNums are equal +* @x: QNum object +* @y: QNum object +* +* See qnum_value_is_equal() for details on the comparison rules. +*/ +bool qnum_is_equal (const QObject *x,const QObject *y) +{ +const QNum *qnum_x =qobject_to (QNum, x); +const QNum *qnum_y =qobject_to (QNum, y); +return qnum_value_is_equal (&qnum_x->value, &qnum_y->value); +} +/** * qnum_destroy_obj(): Free all memory allocated by a QNum object *
Signature · 1 line
2.28.0
PATCH 5/8 qlit: Support all types of QNums
In reply to Eduardo HabkostUse QNumValue to represent QNums, so we can also support uint64_t and double QNum values. Add new QLIT_QNUM_(INT|UINT|DOUBLE) macros for each case.
The QLIT_QNUM() macro is being kept for compatibility with existing code, but becomes just a wrapper for QLIT_QNUM_INT().
--- include/qapi/qmp/qlit.h | 11 +++++-- qobject/qlit.c | 4 +-- tests/check-qjson.c | 72 ++++++++++++++++++++++++++++++++++++++--- 3 files changed, 78 insertions(+), 9 deletions(-)
include/qapi/qmp/qlit.h +9 -2
@@ -15,6 +15,7 @@#define QLIT_H #include "qobject.h" +#include "qnum.h" typedef struct QLitDictEntry QLitDictEntry ;typedef struct QLitObject QLitObject ;
@@ -23,7 +24,7 @@ struct QLitObject {QType type;union {bool qbool; -int64_t qnum; +QNumValue qnum;const char *qstr;QLitDictEntry *qdict;QLitObject *qlist;
@@ -39,8 +40,14 @@ struct QLitDictEntry { { .type = QTYPE_QNULL }#define QLIT_QBOOL (val) \ { .type = QTYPE_QBOOL, .value.qbool = (val) } +#define QLIT_QNUM_INT (val) \ + { .type = QTYPE_QNUM, .value.qnum = QNUM_VAL_INT(val) } +#define QLIT_QNUM_UINT (val) \ + { .type = QTYPE_QNUM, .value.qnum = QNUM_VAL_UINT(val) } +#define QLIT_QNUM_DOUBLE (val) \ + { .type = QTYPE_QNUM, .value.qnum = QNUM_VAL_DOUBLE(val) }#define QLIT_QNUM (val) \ - { .type = QTYPE_QNUM, .value.qnum = (val) } + QLIT_QNUM_INT(val)#define QLIT_QSTR (val) \ { .type = QTYPE_QSTRING, .value.qstr = (val) }#define QLIT_QDICT (val) \
qobject/qlit.c +2 -2
@@ -71,7 +71,7 @@ bool qlit_equal_qobject(const QLitObject *lhs, const QObject *rhs)case QTYPE_QBOOL :return lhs->value.qbool ==qbool_get_bool (qobject_to (QBool, rhs));case QTYPE_QNUM : -return lhs->value.qnum ==qnum_get_int (qobject_to (QNum, rhs)); +return qnum_value_is_equal (&lhs->value.qnum,qnum_get_value (qobject_to (QNum, rhs)));case QTYPE_QSTRING :return (strcmp (lhs->value.qstr,qstring_get_str (qobject_to (QString, rhs))) ==0 );
@@ -94,7 +94,7 @@ QObject *qobject_from_qlit(const QLitObject *qlit)case QTYPE_QNULL :return QOBJECT (qnull ());case QTYPE_QNUM : -return QOBJECT (qnum_from_int (qlit->value.qnum)); +return QOBJECT (qnum_from_value (qlit->value.qnum));case QTYPE_QSTRING :return QOBJECT (qstring_from_str (qlit->value.qstr));case QTYPE_QDICT : {
tests/check-qjson.c +67 -5
108 lines not on this page · raw message
Signature · 1 line
2.28.0
PATCH 6/8 qlit: qlit_type() function
In reply to Eduardo HabkostUseful function where we need to check for the qlit type before converting it to an actual QObject.
--- include/qapi/qmp/qlit.h | 5 +++++ 1 file changed, 5 insertions(+)
include/qapi/qmp/qlit.h +5 -0
@@ -59,4 +59,9 @@ bool qlit_equal_qobject(const QLitObject *lhs, const QObject *rhs);QObject *qobject_from_qlit (const QLitObject *qlit); +static inline QType qlit_type (const QLitObject *qlit) +{ +return qlit->type; +} +#endif /* QLIT_H */
Signature · 1 line
2.28.0
PATCH 7/8 qom: Make object_property_set_default() public
In reply to Eduardo HabkostThe function will be used outside qom/object.c, to simplify the field property code that sets the property default value.
--- include/qom/object.h | 11 +++++++++++ qom/object.c | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-)
include/qom/object.h +11 -0
@@ -1090,6 +1090,17 @@ ObjectProperty *object_class_property_add(ObjectClass *klass, const char *name, ObjectPropertyRelease *release, void *opaque); +/** +* object_property_set_default: +* @prop: the property to set +* @value: the value to be written to the property +* +* Set the property default value. +* +* Ownership of @value is transferred to the property. +*/ +void object_property_set_default (ObjectProperty *prop,QObject *value); +/** * object_property_set_default_bool: * @prop: the property to set
qom/object.c +1 -1
@@ -1547,7 +1547,7 @@ static void object_property_init_defval(Object *obj, ObjectProperty *prop)visit_free (v); } -static void object_property_set_default (ObjectProperty *prop,QObject *defval) +void object_property_set_default (ObjectProperty *prop,QObject *defval) {assert (!prop->defval);assert (!prop->init);
Signature · 1 line
2.28.0
PATCH 8/8 qom: Use qlit to represent property defaults
In reply to Eduardo HabkostUsing QLitObject lets us get rid of most of the
.set_default_value functions, and just useobject_property_set_default() directly.
--- 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(-)
include/hw/qdev-properties-system.h +1 -1
@@ -65,7 +65,7 @@ extern const PropertyInfo qdev_prop_pcie_link_width;#define DEFINE_PROP_UUID (_name, _state, _field) \ DEFINE_PROP(_name, _state, _field, qdev_prop_uuid, QemuUUID, \ - .set_default = true) + .defval = QLIT_QSTR("auto"))#define DEFINE_PROP_AUDIODEV (_n, _s, _f) \ DEFINE_PROP(_n, _s, _f, qdev_prop_audiodev, QEMUSoundCard)
include/qom/field-property-internal.h +0 -4
@@ -15,10 +15,6 @@ void field_prop_set_enum(Object *obj, Visitor *v, const char *name,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);void field_prop_get_int32 (Object *obj,Visitor *v,const char *name,void *opaque,Error **errp);
include/qom/field-property.h +10 -16
@@ -6,6 +6,7 @@#include "qom/object.h" #include "qapi/util.h" +#include "qapi/qmp/qlit.h" /** * 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_init). -*/ -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,
include/qom/property-types.h +9 -12
@@ -5,6 +5,7 @@#define QOM_PROPERTY_TYPES_H #include "qom/field-property.h" +#include "qapi/qmp/qlit.h" extern const PropertyInfo prop_info_bit;extern const PropertyInfo prop_info_bit64;
@@ -28,13 +29,14 @@ extern const PropertyInfo prop_info_link; .info = &(_prop), \ .offset = offsetof(_state , _field) \ + type_check(_type, typeof_field(_state, _field)), \ + .defval =QLIT_QNULL , \ +/* Note that __VA_ARGS__ can still override .defval */ \ __VA_ARGS__ \ }#define DEFINE_PROP_SIGNED (_name, _state, _field, _defval, _prop, _type) \ DEFINE_PROP(_name, _state, _field, _prop, _type, \ - .set_default = true, \ - .defval.i = (_type)_defval) + .defval = QLIT_QNUM_INT(_defval))#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 = (_bit), \ - .set_default = true, \ - .defval.u = (bool)_defval) + .defval = QLIT_QBOOL(_defval))#define DEFINE_PROP_UNSIGNED (_name, _state, _field, _defval, _prop, _type) \ DEFINE_PROP(_name, _state, _field, _prop, _type, \ - .set_default = true, \ - .defval.u = (_type)_defval) + .defval = QLIT_QNUM_UINT(_defval))#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 = (_bit), \ - .set_default = true, \ - .defval.u = (bool)_defval) + .defval = QLIT_QBOOL(_defval))/** * 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 = true, \ - .defval.u = (bool)_defval) + .defval = QLIT_QBOOL(_defval))#define PROP_ARRAY_LEN_PREFIX "len-"
@@ -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 = true, \ - .defval.u = 0, \ + .defval = QLIT_QNUM_UINT(0), \ .arrayinfo = &(_arrayprop), \ .arrayfieldsize = sizeof(_arraytype), \ .arrayoffset = offsetof(_state, _arrayfield))
hw/core/qdev-properties-system.c +0 -8
@@ -570,7 +570,6 @@ const PropertyInfo qdev_prop_blocksize = { " and " MAX_BLOCK_SIZE_STR, .get = field_prop_get_size32, .set = set_blocksize, - .set_default_value = field_prop_set_default_value_uint, };/* --- Block device error handling policy --- */
@@ -768,7 +767,6 @@ const PropertyInfo qdev_prop_pci_devfn = { .print = print_pci_devfn, .get = field_prop_get_int32, .set = set_pci_devfn, - .set_default_value = field_prop_set_default_value_int, };/* --- pci host address --- */
@@ -1080,16 +1078,10 @@ static void set_uuid(Object *obj, Visitor *v, const char *name, void *opaque,g_free (str); } -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 = { .name ="str" , .description ="UUID (aka GUID) or \"" UUID_VALUE_AUTO "\" for random value (default)" , .get = get_uuid, .set = set_uuid, - .set_default_value = set_default_uuid_auto, };
qom/field-property.c +19 -8
@@ -47,6 +47,20 @@ static ObjectPropertyAccessor *field_prop_setter(const PropertyInfo *info)return info->set ? field_prop_set :NULL ; } +static void field_prop_set_default_value (ObjectProperty *op, +Property *prop) +{ +if (qlit_type (&prop->defval) ==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); -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); } op->allow_set = allow_set;
@@ -95,9 +107,8 @@ object_class_property_add_field(ObjectClass *oc, const char *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);
qom/property-types.c +5 -31
@@ -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 =qobject_from_qlit (&prop->defval); +const char *str =qapi_enum_lookup (prop->info->enum_table, +qnum_get_int (qobject_to (QNum, defval))); +object_property_set_default_str (op, str); +qobject_unref (defval); }const PropertyInfo prop_info_enum = {
@@ -80,17 +83,11 @@ static void prop_set_bit(Object *obj, Visitor *v, const char *name,bit_prop_set (obj, prop, value); } -static void set_default_value_bool (ObjectProperty *op,const Property *prop) -{ -object_property_set_default_bool (op, prop->defval.u); -} -const PropertyInfo prop_info_bit = { .name ="bool" , .description ="on/off" , .get = prop_get_bit, .set = prop_set_bit, - .set_default_value = set_default_value_bool, };/* Bit64 */
@@ -139,7 +136,6 @@ const PropertyInfo prop_info_bit64 = { .description = "on/off", .get = prop_get_bit64, .set = prop_set_bit64, - .set_default_value = set_default_value_bool, };/* --- bool --- */
@@ -166,7 +162,6 @@ const PropertyInfo prop_info_bool = { .name = "bool", .get = get_bool, .set = set_bool, - .set_default_value = set_default_value_bool, };/* --- 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); } -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 = { .name ="uint8" , .get = get_uint8, .set = set_uint8, - .set_default_value = field_prop_set_default_value_uint, };/* --- 16bit integer --- */
@@ -232,7 +214,6 @@ const PropertyInfo prop_info_uint16 = { .name = "uint16", .get = get_uint16, .set = set_uint16, - .set_default_value = field_prop_set_default_value_uint, };/* --- 32bit integer --- */
@@ -277,14 +258,12 @@ const PropertyInfo prop_info_uint32 = { .name = "uint32", .get = get_uint32, .set = set_uint32, - .set_default_value = field_prop_set_default_value_uint, };const PropertyInfo prop_info_int32 = { .name ="int32" , .get = field_prop_get_int32, .set = set_int32, - .set_default_value = field_prop_set_default_value_int, };/* --- 64bit integer --- */
@@ -329,14 +308,12 @@ const PropertyInfo prop_info_uint64 = { .name = "uint64", .get = get_uint64, .set = set_uint64, - .set_default_value = field_prop_set_default_value_uint, };const PropertyInfo prop_info_int64 = { .name ="int64" , .get = get_int64, .set = set_int64, - .set_default_value = field_prop_set_default_value_int, };/* --- string --- */
@@ -431,7 +408,6 @@ const PropertyInfo prop_info_size32 = { .name = "size", .get = field_prop_get_size32, .set = set_size32, - .set_default_value = field_prop_set_default_value_uint, };/* --- support for array properties --- */
@@ -494,7 +470,6 @@ const PropertyInfo prop_info_arraylen = { .name = "uint32", .get = get_uint32, .set = set_prop_arraylen, - .set_default_value = field_prop_set_default_value_uint, };/* --- 64bit unsigned int 'size' type --- */
@@ -521,7 +496,6 @@ const PropertyInfo prop_info_size = { .name = "size", .get = get_size, .set = set_size, - .set_default_value = field_prop_set_default_value_uint, };/* --- object link property --- */
Signature · 1 line
2.28.0
Patchew URL: https://patchew.org/QEMU/[email protected]/
Patchew URL: https://patchew.org/QEMU/[email protected]/
Hi,
This series seems to have some coding style problems. See output below for more information:
Message-id: [email protected]
Subject: [PATCH 0/8] qom: Use qlit to represent property defaults
Type: series
=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===
Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384 From https://github.com/patchew-project/qemu
* [new tag] patchew/[email protected] -> patchew/[email protected]
Switched to a new branch 'test'
514115e qom: Use qlit to represent property defaults 2ca3561 qom: Make object_property_set_default() public 4c261ae qlit: qlit_type() function
8b601c4 qlit: Support all types of QNums
2d5f1af qnum: qnum_value_is_equal() function be74c49 qnum: QNumValue type for QNum value literals 87b0edc qnum: Make qnum_get_double() get const pointer ab4b510 qobject: Include API docs in docs/devel/qobject.html
=== OUTPUT BEGIN ===
1/8 Checking commit ab4b510c0e22 (qobject: Include API docs in docs/devel/qobject.html)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #23:
new file mode 100644
total: 0 errors, 1 warnings, 201 lines checked
Patch 1/8 has style problems, please review. If any of these errors are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
2/8 Checking commit 87b0edcb50a7 (qnum: Make qnum_get_double() get const pointer) 3/8 Checking commit be74c4978f05 (qnum: QNumValue type for QNum value literals) 4/8 Checking commit 2d5f1af84646 (qnum: qnum_value_is_equal() function) 5/8 Checking commit 8b601c44266e (qlit: Support all types of QNums)
ERROR: line over 90 characters
#64: FILE: qobject/qlit.c:74:
+ return qnum_value_is_equal(&lhs->value.qnum, qnum_get_value(qobject_to(QNum, rhs)));
total: 1 errors, 0 warnings, 154 lines checked
Patch 5/8 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
6/8 Checking commit 4c261ae4c3f2 (qlit: qlit_type() function)
7/8 Checking commit 2ca3561ee690 (qom: Make object_property_set_default() public) 8/8 Checking commit 514115e597f1 (qom: Use qlit to represent property defaults)
WARNING: Block comments use a leading /* on a separate line
#148: FILE: include/qom/property-types.h:33:
+ /* Note that __VA_ARGS__ can still override .defval */ \
total: 0 errors, 1 warnings, 325 lines checked
Patch 8/8 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
=== OUTPUT END ===
Test command exited with code: 1
The full log is available at
http://patchew.org/logs/[email protected]/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]
Quoted 38 lines · Eduardo Habkost
Based-on: [email protected]
Git branch: https://gitlab.com/ehabkost/qemu/-/commits/work/qdev-qlit-defaultsThis extend
qlit.hto support all QNum types (signed int, unsigned int, and double), and use QLitObject to represent field property defaults.It allows us to get rid of most type-specific .set_default_value functions for QOM property types.
Eduardo Habkost (8):
qobject: Include API docs in docs/devel/qobject.html
qnum: Makeqnum_get_double()get const pointer
qnum: QNumValue type for QNum value literals
qnum:qnum_value_is_equal()function
qlit: Support all types of QNums
qlit:qlit_type()function
qom: Makeobject_property_set_default()public
qom: Use qlit to represent property defaultsdocs/devel/index.rst | 1 + docs/devel/qobject.rst | 11 +++ include/hw/qdev-properties-system.h | 2 +- include/qapi/qmp/qlit.h | 16 +++- include/qapi/qmp/qnum.h | 47 ++++++++++- include/qapi/qmp/qobject.h | 48 +++++++---- include/qom/field-property-internal.h | 4 - include/qom/field-property.h | 26 +++--- include/qom/object.h | 11 +++ include/qom/property-types.h | 21 ++--- hw/core/qdev-properties-system.c | 8 -- qobject/qlit.c | 4 +- qobject/qnum.c | 116 +++++++++++++++----------- qom/field-property.c | 27 ++++-- qom/object.c | 2 +- qom/property-types.c | 36 ++------ tests/check-qjson.c | 72 ++++++++++++++-- 17 files changed, 295 insertions(+), 157 deletions(-)
Quoted 2 lines
create mode 100644
docs/devel/qobject.rst
Thanks,
Paolo
Quoted 42 lines · Paolo Bonzini
Quoted 38 lines · Eduardo Habkost
Based-on: [email protected]
Git branch: https://gitlab.com/ehabkost/qemu/-/commits/work/qdev-qlit-defaultsThis extend
qlit.hto support all QNum types (signed int, unsigned int, and double), and use QLitObject to represent field property defaults.It allows us to get rid of most type-specific .set_default_value functions for QOM property types.
Eduardo Habkost (8):
qobject: Include API docs in docs/devel/qobject.html
qnum: Makeqnum_get_double()get const pointer
qnum: QNumValue type for QNum value literals
qnum:qnum_value_is_equal()function
qlit: Support all types of QNums
qlit:qlit_type()function
qom: Makeobject_property_set_default()public
qom: Use qlit to represent property defaultsdocs/devel/index.rst | 1 + docs/devel/qobject.rst | 11 +++ include/hw/qdev-properties-system.h | 2 +- include/qapi/qmp/qlit.h | 16 +++- include/qapi/qmp/qnum.h | 47 ++++++++++- include/qapi/qmp/qobject.h | 48 +++++++---- include/qom/field-property-internal.h | 4 - include/qom/field-property.h | 26 +++--- include/qom/object.h | 11 +++ include/qom/property-types.h | 21 ++--- hw/core/qdev-properties-system.c | 8 -- qobject/qlit.c | 4 +- qobject/qnum.c | 116 +++++++++++++++----------- qom/field-property.c | 27 ++++-- qom/object.c | 2 +- qom/property-types.c | 36 ++------ tests/check-qjson.c | 72 ++++++++++++++-- 17 files changed, 295 insertions(+), 157 deletions(-)Quoted 2 lines
create mode 100644
docs/devel/qobject.rst
Quoted 1 line
Acked-by Paolo Bonzini <[email protected]>
Thanks!
It looks like I broke some unit tests in this series. I will submit v2 after submitting v3 of the field property series.
Signature · 1 line
Eduardo