qom/object.c: introduce OBJECT_PROPERTY_SCALAR_SETTER(type) macro
This macro can be used to generate the boilerplate property_set_type_ptr() QOM set function for the specified scalar type. Replace the existing scaler set 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-3-mark.caveayland@nutanix.com>
Mark Cave-Ayland committed
Jul 17, 2026 at 14:51 UTC
5f8edcbc3ca0371b1ed0b38f7191ca91ef3cf7e4
1 file changed
+22
-50
qom/object.c
+22
-50
@@ -2671,62 +2671,34 @@ static char *object_get_type(Object *obj, Error **errp)
2671
visit_type_##type(v, name, &value, errp); \
2672
}
2673
2674
+
2675
+#define OBJECT_PROPERTY_SCALAR_SETTER(type) \
2676
+ static void property_set_##type##_ptr(Object *obj, Visitor *v, \
2677
+ const char *name, \
2678
+ void *opaque, Error **errp) \
2679
+ { \
2680
+ type##_t *field = opaque; \
2681
+ type##_t value; \
2682
+ \
2683
+ if (!visit_type_##type(v, name, &value, errp)) { \
2684
+ return; \
2685
+ } \
2686
+ \
2687
+ *field = value; \
2688
+ }
2689
+
2690
OBJECT_PROPERTY_SCALAR_GETTER(uint8)
2691
+OBJECT_PROPERTY_SCALAR_SETTER(uint8)
2692
OBJECT_PROPERTY_SCALAR_GETTER(uint16)
2693
+OBJECT_PROPERTY_SCALAR_SETTER(uint16)
2694
OBJECT_PROPERTY_SCALAR_GETTER(uint32)
2695
+OBJECT_PROPERTY_SCALAR_SETTER(uint32)
2696
OBJECT_PROPERTY_SCALAR_GETTER(uint64)
2697
+OBJECT_PROPERTY_SCALAR_SETTER(uint64)
2698
2679
-static void property_set_uint8_ptr(Object *obj, Visitor *v, const char *name,
2680
- void *opaque, Error **errp)
2681
-{
2682
- uint8_t *field = opaque;
2683
- uint8_t value;
2684
-
2685
- if (!visit_type_uint8(v, name, &value, errp)) {
2686
- return;
2687
- }
2688
-
2689
- *field = value;
2690
-}
2691
-
2692
-static void property_set_uint16_ptr(Object *obj, Visitor *v, const char *name,
2693
- void *opaque, Error **errp)
2694
-{
2695
- uint16_t *field = opaque;
2696
- uint16_t value;
2697
-
2698
- if (!visit_type_uint16(v, name, &value, errp)) {
2699
- return;
2700
- }
2701
-
2702
- *field = value;
2703
-}
2704
-
2705
-static void property_set_uint32_ptr(Object *obj, Visitor *v, const char *name,
2706
- void *opaque, Error **errp)
2707
-{
2708
- uint32_t *field = opaque;
2709
- uint32_t value;
2710
-
2711
- if (!visit_type_uint32(v, name, &value, errp)) {
2712
- return;
2713
- }
2714
-
2715
- *field = value;
2716
-}
2717
-
2718
-static void property_set_uint64_ptr(Object *obj, Visitor *v, const char *name,
2719
- void *opaque, Error **errp)
2720
-{
2721
- uint64_t *field = opaque;
2722
- uint64_t value;
2723
-
2724
- if (!visit_type_uint64(v, name, &value, errp)) {
2725
- return;
2726
- }
2699
+#undef OBJECT_PROPERTY_SCALAR_GETTER
2700
+#undef OBJECT_PROPERTY_SCALAR_SETTER
2701
2728
- *field = value;
2729
-}
2702
2703
ObjectProperty *
2704
object_property_add_uint8_ptr(Object *obj, const char *name,