qom: move object_set_prop_keyval into object.c
This matches the location of the object_set_props and object_set_propv methods, since this method is not inherently tied to the user creatable interface. As part of this, object_set_props_from_qdict is also exposed as a public API since it is still called from object_interfaces.c. Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
Daniel P. Berrangé committed
Apr 17, 2026 at 16:17 UTC
655256b340dbbb486dec0a80e477d6dd763ccc55
3 files changed
+67
-52
include/qom/object.h
+31
-16
@@ -748,6 +748,37 @@ bool object_set_props(Object *obj, Error **errp, ...) G_GNUC_NULL_TERMINATED;
748
*/
749
bool object_set_propv(Object *obj, va_list vargs, Error **errp);
750
751
+/**
752
+ * object_set_props_from_qdict:
753
+ * @obj: a QOM object
754
+ * @qdict: a dictionary with the properties to be set
755
+ * @v: a visitor to iterate over @dict
756
+ * @errp: pointer to error object
757
+ *
758
+ * For each key in the dictionary, set the corresponding
759
+ * property in @obj.
760
+ *
761
+ * Returns: %true on success, %false on error.
762
+ */
763
+bool object_set_props_from_qdict(Object *obj, const QDict *qdict,
764
+ Visitor *v, Error **errp);
765
+
766
+/**
767
+ * object_set_props_from_keyval:
768
+ * @obj: a QOM object
769
+ * @qdict: a dictionary with the properties to be set
770
+ * @from_json: true if leaf values of @qdict are typed, false if they
771
+ * are strings
772
+ * @errp: pointer to error object
773
+ *
774
+ * For each key in the dictionary, parse the value string if needed,
775
+ * then set the corresponding property in @obj.
776
+ *
777
+ * Returns: %true on success, %false on error.
778
+ */
779
+bool object_set_props_from_keyval(Object *obj, const QDict *qdict,
780
+ bool from_json, Error **errp);
781
+
782
/**
783
* object_initialize:
784
* @obj: A pointer to the memory to be used for the object.
@@ -914,22 +945,6 @@ type_init(do_qemu_init_ ## type_array)
945
*/
946
bool type_print_class_properties(const char *type);
947
917
-/**
918
- * object_set_props_from_keyval:
919
- * @obj: a QOM object
920
- * @qdict: a dictionary with the properties to be set
921
- * @from_json: true if leaf values of @qdict are typed, false if they
922
- * are strings
923
- * @errp: pointer to error object
924
- *
925
- * For each key in the dictionary, parse the value string if needed,
926
- * then set the corresponding property in @obj.
927
- *
928
- * Returns: %true on success, %false on error.
929
- */
930
-bool object_set_props_from_keyval(Object *obj, const QDict *qdict,
931
- bool from_json, Error **errp);
932
-
948
/**
949
* object_class_dynamic_cast_assert:
950
* @klass: The #ObjectClass to attempt to cast.
qom/object.c
+36
@@ -23,6 +23,7 @@
23
#include "qapi/qobject-input-visitor.h"
24
#include "qapi/forward-visitor.h"
25
#include "qapi/qapi-builtin-visit.h"
26
+#include "qobject/qdict.h"
27
#include "qobject/qjson.h"
28
#include "qemu/id.h"
29
#include "qapi/qmp/qerror.h"
@@ -838,6 +839,41 @@ bool object_set_propv(Object *obj,
839
return true;
840
}
841
842
+bool object_set_props_from_qdict(Object *obj, const QDict *qdict,
843
+ Visitor *v, Error **errp)
844
+{
845
+ ERRP_GUARD();
846
+ const QDictEntry *e;
847
+
848
+ if (!visit_start_struct(v, NULL, NULL, 0, errp)) {
849
+ return false;
850
+ }
851
+ for (e = qdict_first(qdict); e; e = qdict_next(qdict, e)) {
852
+ if (!object_property_set(obj, e->key, v, errp)) {
853
+ goto out;
854
+ }
855
+ }
856
+ visit_check_struct(v, errp);
857
+out:
858
+ visit_end_struct(v, NULL);
859
+
860
+ return *errp == NULL;
861
+}
862
+
863
+bool object_set_props_from_keyval(Object *obj, const QDict *qdict,
864
+ bool from_json, Error **errp)
865
+{
866
+ bool ret;
867
+ Visitor *v;
868
+ if (from_json) {
869
+ v = qobject_input_visitor_new(QOBJECT(qdict));
870
+ } else {
871
+ v = qobject_input_visitor_new_keyval(QOBJECT(qdict));
872
+ }
873
+ ret = object_set_props_from_qdict(obj, qdict, v, errp);
874
+ visit_free(v);
875
+ return ret;
876
+}
877
878
Object *object_dynamic_cast(Object *obj, const char *typename)
879
{
qom/object_interfaces.c
-36
@@ -44,42 +44,6 @@ bool user_creatable_can_be_deleted(UserCreatable *uc)
44
}
45
}
46
47
-static bool object_set_props_from_qdict(Object *obj, const QDict *qdict,
48
- Visitor *v, Error **errp)
49
-{
50
- ERRP_GUARD();
51
- const QDictEntry *e;
52
-
53
- if (!visit_start_struct(v, NULL, NULL, 0, errp)) {
54
- return false;
55
- }
56
- for (e = qdict_first(qdict); e; e = qdict_next(qdict, e)) {
57
- if (!object_property_set(obj, e->key, v, errp)) {
58
- goto out;
59
- }
60
- }
61
- visit_check_struct(v, errp);
62
-out:
63
- visit_end_struct(v, NULL);
64
-
65
- return *errp == NULL;
66
-}
67
-
68
-bool object_set_props_from_keyval(Object *obj, const QDict *qdict,
69
- bool from_json, Error **errp)
70
-{
71
- bool ret;
72
- Visitor *v;
73
- if (from_json) {
74
- v = qobject_input_visitor_new(QOBJECT(qdict));
75
- } else {
76
- v = qobject_input_visitor_new_keyval(QOBJECT(qdict));
77
- }
78
- ret = object_set_props_from_qdict(obj, qdict, v, errp);
79
- visit_free(v);
80
- return ret;
81
-}
82
-
47
Object *user_creatable_add_type(const char *type, const char *id,
48
const QDict *qdict,
49
Visitor *v, Error **errp)