@@ -53,6 +53,9 @@ struct PropertyInfo {
* @set_default_value: Callback for initializing the default value
*
* @defval is a weak reference.
+ *
+ * Optional. If not set and Property.defval is not QTYPE_NONE,
+ * object_property_set_default() will be called.
*/
void (*set_default_value)(ObjectProperty *op, const Property *prop,
const QObject *defval);
@@ -72,8 +72,16 @@ static void field_prop_set_default_value(ObjectProperty *op,
}
defval = qobject_from_qlit(&prop->defval);
- assert(prop->info->set_default_value);
- prop->info->set_default_value(op, prop, defval);
+ if (prop->info->set_default_value) {
+ /* .set_default_value() gets a weak reference */
+ prop->info->set_default_value(op, prop, defval);
+ } else {
+ /*
+ * object_property_set_default() takes ownership,
+ * so qobject_ref() is needed.
+ */
+ object_property_set_default(op, qobject_ref(defval));
+ }
qobject_unref(defval);
}
If .set_default_value is not set, call object_property_set_default(). This will let us delete most of the .set_default_value functions later. Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> --- This is a new patch in v3 of this series. In v2 of the series, equivalent functionality was implemented by "qom: Use qlit to represent property defaults". --- include/qom/field-property.h | 3 +++ qom/field-property.c | 12 ++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-)