[PATCH v4 01/16] qom/object.c: introduce OBJECT_CLASS_PROPERTY_SCALAR_GETTER(type) macro

Mark Cave-Ayland <[email protected]>
Newsgroups org.nongnu.qemu-arm,org.nongnu.qemu-devel
Message-ID <[email protected]>
This macro will be used to generate the boilerplate property_class_get_type_ptr()
QOM get function for the specified scalar type.

Note that since the macro is currently unused, the object_class_prop_ptr() helper
function is temporarily marked as __attribute__((unused)) to allow compilation to
succeed.

Signed-off-by: Mark Cave-Ayland <[email protected]>
Reviewed-by: Marc-André Lureau <[email protected]>
---
 qom/object.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/qom/object.c b/qom/object.c
index 47977b1f44..e32ae30bd5 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -2703,6 +2703,28 @@ DEFINE_OBJECT_PROPERTY_SCALAR_METHODS(uint64)
 #undef DEFINE_OBJECT_PROPERTY_SCALAR_METHODS
 
 
+__attribute__((unused))
+static void *object_class_prop_ptr(Object *obj, ptrdiff_t offset)
+{
+    void *ptr = obj;
+    ptr += offset;
+
+    return ptr;
+}
+
+#define OBJECT_CLASS_PROPERTY_SCALAR_GETTER(type) \
+    static void property_class_get_##type##_ptr(Object *obj, Visitor *v, \
+                                                const char *name, \
+                                                void *opaque, Error **errp) \
+    { \
+        type##_t value = *(type##_t *)object_class_prop_ptr(obj, \
+                                                        (ptrdiff_t)opaque); \
+        visit_type_##type(v, name, &value, errp); \
+    }
+
+#undef OBJECT_CLASS_PROPERTY_SCALAR_GETTER
+
+
 ObjectProperty *
 object_property_add_uint8_ptr(Object *obj, const char *name,
                               const uint8_t *v,
-- 
2.43.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.