@samitouri / QOSamiQemu / commits / 167882fe86

qom/object.c: introduce OBJECT_PROPERTY_SCALAR_GETTER(type) macro

This macro can be used to generate the boilerplate property_get_type_ptr() QOM get function for the specified scalar type. Replace the existing scaler get functions with the new macro. Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Message-Id: <20260717135254.508701-2-mark.caveayland@nutanix.com>

Mark Cave-Ayland committed Jul 17, 2026 at 14:51 UTC 167882fe86d7b266bc7df27c58428ea40e10245d
1 file changed +14 -27
qom/object.c
+14 -27
@@ -2661,12 +2661,20 @@ static char *object_get_type(Object *obj, Error **errp)
2661 return g_strdup(object_get_typename(obj));
2662 }
2663
2664 -static void property_get_uint8_ptr(Object *obj, Visitor *v, const char *name,
2665 - void *opaque, Error **errp)
2666 -{
2667 - uint8_t value = *(uint8_t *)opaque;
2668 - visit_type_uint8(v, name, &value, errp);
2669 -}
2664 +
2665 +#define OBJECT_PROPERTY_SCALAR_GETTER(type) \
2666 + static void property_get_##type##_ptr(Object *obj, Visitor *v, \
2667 + const char *name, \
2668 + void *opaque, Error **errp) \
2669 + { \
2670 + type##_t value = *(type##_t *)opaque; \
2671 + visit_type_##type(v, name, &value, errp); \
2672 + }
2673 +
2674 +OBJECT_PROPERTY_SCALAR_GETTER(uint8)
2675 +OBJECT_PROPERTY_SCALAR_GETTER(uint16)
2676 +OBJECT_PROPERTY_SCALAR_GETTER(uint32)
2677 +OBJECT_PROPERTY_SCALAR_GETTER(uint64)
2678
2679 static void property_set_uint8_ptr(Object *obj, Visitor *v, const char *name,
2680 void *opaque, Error **errp)
@@ -2681,13 +2689,6 @@ static void property_set_uint8_ptr(Object *obj, Visitor *v, const char *name,
2689 *field = value;
2690 }
2691
2684 -static void property_get_uint16_ptr(Object *obj, Visitor *v, const char *name,
2685 - void *opaque, Error **errp)
2686 -{
2687 - uint16_t value = *(uint16_t *)opaque;
2688 - visit_type_uint16(v, name, &value, errp);
2689 -}
2690 -
2692 static void property_set_uint16_ptr(Object *obj, Visitor *v, const char *name,
2693 void *opaque, Error **errp)
2694 {
@@ -2701,13 +2702,6 @@ static void property_set_uint16_ptr(Object *obj, Visitor *v, const char *name,
2702 *field = value;
2703 }
2704
2704 -static void property_get_uint32_ptr(Object *obj, Visitor *v, const char *name,
2705 - void *opaque, Error **errp)
2706 -{
2707 - uint32_t value = *(uint32_t *)opaque;
2708 - visit_type_uint32(v, name, &value, errp);
2709 -}
2710 -
2705 static void property_set_uint32_ptr(Object *obj, Visitor *v, const char *name,
2706 void *opaque, Error **errp)
2707 {
@@ -2721,13 +2715,6 @@ static void property_set_uint32_ptr(Object *obj, Visitor *v, const char *name,
2715 *field = value;
2716 }
2717
2724 -static void property_get_uint64_ptr(Object *obj, Visitor *v, const char *name,
2725 - void *opaque, Error **errp)
2726 -{
2727 - uint64_t value = *(uint64_t *)opaque;
2728 - visit_type_uint64(v, name, &value, errp);
2729 -}
2730 -
2718 static void property_set_uint64_ptr(Object *obj, Visitor *v, const char *name,
2719 void *opaque, Error **errp)
2720 {