[PATCH v3 51/53] qom: PROP_* macros

Eduardo Habkost posted 53 patches 5 years, 2 months ago
Maintainers: Halil Pasic <pasic@linux.ibm.com>, Gerd Hoffmann <kraxel@redhat.com>, Antony Pavlov <antonynpavlov@gmail.com>, Artyom Tarasenko <atar4qemu@gmail.com>, Michael Rolnik <mrolnik@gmail.com>, Magnus Damm <magnus.damm@gmail.com>, John Snow <jsnow@redhat.com>, Alistair Francis <alistair@alistair23.me>, Michael Walle <michael@walle.cc>, Joel Stanley <joel@jms.id.au>, Fabien Chouteau <chouteau@adacore.com>, "Cédric Le Goater" <clg@kaod.org>, Alberto Garcia <berto@igalia.com>, "Dr. David Alan Gilbert" <dgilbert@redhat.com>, Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>, "Michael S. Tsirkin" <mst@redhat.com>, Andrzej Zaborowski <balrogg@gmail.com>, Max Reitz <mreitz@redhat.com>, Yoshinori Sato <ysato@users.sourceforge.jp>, David Gibson <david@gibson.dropbear.id.au>, "Daniel P. Berrangé" <berrange@redhat.com>, Yuval Shaia <yuval.shaia.ml@gmail.com>, Samuel Thibault <samuel.thibault@ens-lyon.org>, Kevin Wolf <kwolf@redhat.com>, Sarah Harris <S.E.Harris@kent.ac.uk>, Corey Minyard <minyard@acm.org>, "Edgar E. Iglesias" <edgar.iglesias@gmail.com>, Paul Durrant <paul@xen.org>, Christian Borntraeger <borntraeger@de.ibm.com>, Alex Williamson <alex.williamson@redhat.com>, Andrew Baumann <Andrew.Baumann@microsoft.com>, Ben Warren <ben@skyportsystems.com>, Jiri Pirko <jiri@resnulli.us>, Cornelia Huck <cohuck@redhat.com>, Stefano Stabellini <sstabellini@kernel.org>, Fam Zheng <fam@euphon.net>, Igor Mitsyanko <i.mitsyanko@gmail.com>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, KONRAD Frederic <frederic.konrad@adacore.com>, Laurent Vivier <lvivier@redhat.com>, Amit Shah <amit@kernel.org>, Raphael Norwitz <raphael.norwitz@nutanix.com>, Eduardo Habkost <ehabkost@redhat.com>, Thomas Huth <huth@tuxfamily.org>, Anthony Perard <anthony.perard@citrix.com>, Richard Henderson <rth@twiddle.net>, Eric Auger <eric.auger@redhat.com>, "Philippe Mathieu-Daudé" <philmd@redhat.com>, Jason Wang <jasowang@redhat.com>, Stefan Hajnoczi <stefanha@redhat.com>, Peter Chubb <peter.chubb@nicta.com.au>, Beniamino Galvani <b.galvani@gmail.com>, Igor Mammedov <imammedo@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, Juan Quintela <quintela@redhat.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, Peter Maydell <peter.maydell@linaro.org>
[PATCH v3 51/53] qom: PROP_* macros
Posted by Eduardo Habkost 5 years, 2 months ago
The new helper macros are similar to the old DEFINE_PROP_* macros, but
don't take a name argument.  They can be used directly as argument to
object_class_property_add_field().

The DEFINE_PROP_* macros were redefined to just be wrappers to PROP_*.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
Changes v2 -> v3:
* Now the DEFINE_PROP_* macros are defined using PROP_*,
  not the other way around
* Remove unused macros (PROP_UNSIGNED*, PROP_SIGNED*, PROP_UUID)
* Removed PROP_ARRAY because it isn't as trivial as the others
* Now PROP_* won't return a pointer to a static variable anymore,
  but just a compound literal for a Property struct.

This is a new patch added in v2 of the series

---
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: "Daniel P. Berrangé" <berrange@redhat.com>
Cc: Eduardo Habkost <ehabkost@redhat.com>
Cc: qemu-devel@nongnu.org
---
 include/qom/property-types.h | 141 ++++++++++++++++++++++-------------
 1 file changed, 90 insertions(+), 51 deletions(-)

diff --git a/include/qom/property-types.h b/include/qom/property-types.h
index 91b166badf..3132ddafd9 100644
--- a/include/qom/property-types.h
+++ b/include/qom/property-types.h
@@ -23,6 +23,64 @@ extern const PropertyInfo prop_info_size32;
 extern const PropertyInfo prop_info_arraylen;
 extern const PropertyInfo prop_info_link;
 
+#define PROP_SIGNED(_state, _field, _defval, _prop, _type, ...) \
+    FIELD_PROP(_state, _field, _prop, _type,                    \
+               .set_default = true,                             \
+               .defval.i    = (_type)_defval,                   \
+               __VA_ARGS__)
+
+#define PROP_UNSIGNED(_state, _field, _defval, _prop, _type, ...) \
+    FIELD_PROP(_state, _field, _prop, _type,                    \
+               .set_default = true,                             \
+               .defval.u  = (_type)_defval,                     \
+               __VA_ARGS__)
+
+#define PROP_BIT(_state, _field, _bit, _defval, ...) \
+    FIELD_PROP(_state, _field, prop_info_bit, uint32_t,         \
+               .bitnr       = (_bit),                           \
+               .set_default = true,                             \
+               .defval.u    = (bool)_defval,                    \
+               __VA_ARGS__)
+
+#define PROP_BIT64(_state, _field, _bit, _defval, ...) \
+    FIELD_PROP(_state, _field, prop_info_bit64, uint64_t,       \
+               .bitnr    = (_bit),                              \
+               .set_default = true,                             \
+               .defval.u  = (bool)_defval,                      \
+               __VA_ARGS__)
+
+#define PROP_BOOL(_state, _field, _defval, ...) \
+    FIELD_PROP(_state, _field, prop_info_bool, bool,            \
+               .set_default = true,                             \
+               .defval.u    = (bool)_defval,                    \
+               __VA_ARGS__)
+
+#define PROP_LINK(_state, _field, _type, _ptr_type, ...) \
+    FIELD_PROP(_state, _field, prop_info_link, _ptr_type,       \
+               .link_type  = _type,                             \
+               __VA_ARGS__)
+
+#define PROP_UINT8(_s, _f, _d, ...) \
+    PROP_UNSIGNED(_s, _f, _d, prop_info_uint8, uint8_t, __VA_ARGS__)
+#define PROP_UINT16(_s, _f, _d, ...) \
+    PROP_UNSIGNED(_s, _f, _d, prop_info_uint16, uint16_t, __VA_ARGS__)
+#define PROP_UINT32(_s, _f, _d, ...) \
+    PROP_UNSIGNED(_s, _f, _d, prop_info_uint32, uint32_t, __VA_ARGS__)
+#define PROP_INT32(_s, _f, _d, ...) \
+    PROP_SIGNED(_s, _f, _d, prop_info_int32, int32_t, __VA_ARGS__)
+#define PROP_UINT64(_s, _f, _d, ...) \
+    PROP_UNSIGNED(_s, _f, _d, prop_info_uint64, uint64_t, __VA_ARGS__)
+#define PROP_INT64(_s, _f, _d, ...) \
+    PROP_SIGNED(_s, _f, _d, prop_info_int64, int64_t, __VA_ARGS__)
+#define PROP_SIZE(_s, _f, _d, ...) \
+    PROP_UNSIGNED(_s, _f, _d, prop_info_size, uint64_t, __VA_ARGS__)
+#define PROP_STRING(_s, _f, ...) \
+    FIELD_PROP(_s, _f, prop_info_string, char*, __VA_ARGS__)
+#define PROP_ON_OFF_AUTO(_s, _f, _d, ...) \
+    PROP_SIGNED(_s, _f, _d, prop_info_on_off_auto, OnOffAuto, __VA_ARGS__)
+#define PROP_SIZE32(_s, _f, _d, ...) \
+    PROP_UNSIGNED(_s, _f, _d, prop_info_size32, uint32_t, __VA_ARGS__)
+
 /**
  * DEFINE_PROP: Define a #Property struct, including a property name
  *
@@ -43,33 +101,6 @@ extern const PropertyInfo prop_info_link;
                .name_template = (_name),                      \
                __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)
-
-#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)
-
-#define DEFINE_PROP_UNSIGNED(_name, _state, _field, _defval, _prop, _type) \
-    DEFINE_PROP(_name, _state, _field, _prop, _type,                       \
-                .set_default = true,                                       \
-                .defval.u  = (_type)_defval)
-
-#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)
-
-#define DEFINE_PROP_BOOL(_name, _state, _field, _defval)     \
-    DEFINE_PROP(_name, _state, _field, prop_info_bool, bool, \
-                .set_default = true,                         \
-                .defval.u    = (bool)_defval)
-
 #define PROP_ARRAY_LEN_PREFIX "len-"
 
 /**
@@ -106,30 +137,38 @@ extern const PropertyInfo prop_info_link;
                 .arrayfieldsize = sizeof(_arraytype),          \
                 .arrayoffset = offsetof(_state, _arrayfield))
 
-#define DEFINE_PROP_LINK(_name, _state, _field, _type, _ptr_type)     \
-    DEFINE_PROP(_name, _state, _field, prop_info_link, _ptr_type,     \
-                .link_type  = _type)
-
-#define DEFINE_PROP_UINT8(_n, _s, _f, _d)                       \
-    DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, prop_info_uint8, uint8_t)
-#define DEFINE_PROP_UINT16(_n, _s, _f, _d)                      \
-    DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, prop_info_uint16, uint16_t)
-#define DEFINE_PROP_UINT32(_n, _s, _f, _d)                      \
-    DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, prop_info_uint32, uint32_t)
-#define DEFINE_PROP_INT32(_n, _s, _f, _d)                      \
-    DEFINE_PROP_SIGNED(_n, _s, _f, _d, prop_info_int32, int32_t)
-#define DEFINE_PROP_UINT64(_n, _s, _f, _d)                      \
-    DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, prop_info_uint64, uint64_t)
-#define DEFINE_PROP_INT64(_n, _s, _f, _d)                      \
-    DEFINE_PROP_SIGNED(_n, _s, _f, _d, prop_info_int64, int64_t)
-#define DEFINE_PROP_SIZE(_n, _s, _f, _d)                       \
-    DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, prop_info_size, uint64_t)
-#define DEFINE_PROP_STRING(_n, _s, _f)             \
-    DEFINE_PROP(_n, _s, _f, prop_info_string, char*)
-#define DEFINE_PROP_ON_OFF_AUTO(_n, _s, _f, _d) \
-    DEFINE_PROP_SIGNED(_n, _s, _f, _d, prop_info_on_off_auto, OnOffAuto)
-#define DEFINE_PROP_SIZE32(_n, _s, _f, _d)                       \
-    DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, prop_info_size32, uint32_t)
+#define DEFINE_PROP_SIGNED(_n, ...) \
+    PROP_SIGNED(__VA_ARGS__, .name_template = (_n))
+#define DEFINE_PROP_BIT(_n, ...) \
+    PROP_BIT(__VA_ARGS__, .name_template = (_n))
+#define DEFINE_PROP_UNSIGNED(_n, ...) \
+    PROP_UNSIGNED(__VA_ARGS__, .name_template = (_n))
+#define DEFINE_PROP_BIT64(_n, ...) \
+    PROP_BIT64(__VA_ARGS__, .name_template = (_n))
+#define DEFINE_PROP_BOOL(_n, ...) \
+    PROP_BOOL(__VA_ARGS__, .name_template = (_n))
+#define DEFINE_PROP_LINK(_n, ...) \
+    PROP_LINK(__VA_ARGS__, .name_template = (_n))
+#define DEFINE_PROP_UINT8(_n, ...) \
+    PROP_UINT8(__VA_ARGS__, .name_template = (_n))
+#define DEFINE_PROP_UINT16(_n, ...) \
+    PROP_UINT16(__VA_ARGS__, .name_template = (_n))
+#define DEFINE_PROP_UINT32(_n, ...) \
+    PROP_UINT32(__VA_ARGS__, .name_template = (_n))
+#define DEFINE_PROP_INT32(_n, ...) \
+    PROP_INT32(__VA_ARGS__, .name_template = (_n))
+#define DEFINE_PROP_UINT64(_n, ...) \
+    PROP_UINT64(__VA_ARGS__, .name_template = (_n))
+#define DEFINE_PROP_INT64(_n, ...) \
+    PROP_INT64(__VA_ARGS__, .name_template = (_n))
+#define DEFINE_PROP_SIZE(_n, ...) \
+    PROP_SIZE(__VA_ARGS__, .name_template = (_n))
+#define DEFINE_PROP_STRING(_n, ...) \
+    PROP_STRING(__VA_ARGS__, .name_template = (_n))
+#define DEFINE_PROP_ON_OFF_AUTO(_n, ...) \
+    PROP_ON_OFF_AUTO(__VA_ARGS__, .name_template = (_n))
+#define DEFINE_PROP_SIZE32(_n, ...) \
+    PROP_SIZE32(__VA_ARGS__, .name_template = (_n))
 
 #define DEFINE_PROP_END_OF_LIST()               \
     {}
-- 
2.28.0