qom: Make all the object_property_add_FOO() return the property

Some object_property_add_FOO() return the newly added property, some
don't.  Clean that up.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200505152926.18877-7-armbru@redhat.com>
This commit is contained in:
Markus Armbruster 2020-05-05 17:29:14 +02:00
parent 44a17fe05a
commit 7025188772
2 changed files with 164 additions and 136 deletions

View File

@ -1491,9 +1491,11 @@ Object *object_resolve_path_component(Object *parent, const char *part);
* The value of a child property as a C string will be the child object's * The value of a child property as a C string will be the child object's
* canonical path. It can be retrieved using object_property_get_str(). * canonical path. It can be retrieved using object_property_get_str().
* The child object itself can be retrieved using object_property_get_link(). * The child object itself can be retrieved using object_property_get_link().
*
* Returns: The newly added property on success, or %NULL on failure.
*/ */
void object_property_add_child(Object *obj, const char *name, ObjectProperty *object_property_add_child(Object *obj, const char *name,
Object *child, Error **errp); Object *child, Error **errp);
typedef enum { typedef enum {
/* Unref the link pointer when the property is deleted */ /* Unref the link pointer when the property is deleted */
@ -1542,8 +1544,10 @@ void object_property_allow_set_link(const Object *, const char *,
* <code>@flags</code> <code>OBJ_PROP_LINK_STRONG</code> bit is set, * <code>@flags</code> <code>OBJ_PROP_LINK_STRONG</code> bit is set,
* the reference count is decremented when the property is deleted or * the reference count is decremented when the property is deleted or
* modified. * modified.
*
* Returns: The newly added property on success, or %NULL on failure.
*/ */
void object_property_add_link(Object *obj, const char *name, ObjectProperty *object_property_add_link(Object *obj, const char *name,
const char *type, Object **targetp, const char *type, Object **targetp,
void (*check)(const Object *obj, const char *name, void (*check)(const Object *obj, const char *name,
Object *val, Error **errp), Object *val, Error **errp),
@ -1569,8 +1573,10 @@ ObjectProperty *object_class_property_add_link(ObjectClass *oc,
* *
* Add a string property using getters/setters. This function will add a * Add a string property using getters/setters. This function will add a
* property of type 'string'. * property of type 'string'.
*
* Returns: The newly added property on success, or %NULL on failure.
*/ */
void object_property_add_str(Object *obj, const char *name, ObjectProperty *object_property_add_str(Object *obj, const char *name,
char *(*get)(Object *, Error **), char *(*get)(Object *, Error **),
void (*set)(Object *, const char *, Error **), void (*set)(Object *, const char *, Error **),
Error **errp); Error **errp);
@ -1592,8 +1598,10 @@ ObjectProperty *object_class_property_add_str(ObjectClass *klass,
* *
* Add a bool property using getters/setters. This function will add a * Add a bool property using getters/setters. This function will add a
* property of type 'bool'. * property of type 'bool'.
*
* Returns: The newly added property on success, or %NULL on failure.
*/ */
void object_property_add_bool(Object *obj, const char *name, ObjectProperty *object_property_add_bool(Object *obj, const char *name,
bool (*get)(Object *, Error **), bool (*get)(Object *, Error **),
void (*set)(Object *, bool, Error **), void (*set)(Object *, bool, Error **),
Error **errp); Error **errp);
@ -1615,8 +1623,10 @@ ObjectProperty *object_class_property_add_bool(ObjectClass *klass,
* *
* Add an enum property using getters/setters. This function will add a * Add an enum property using getters/setters. This function will add a
* property of type '@typename'. * property of type '@typename'.
*
* Returns: The newly added property on success, or %NULL on failure.
*/ */
void object_property_add_enum(Object *obj, const char *name, ObjectProperty *object_property_add_enum(Object *obj, const char *name,
const char *typename, const char *typename,
const QEnumLookup *lookup, const QEnumLookup *lookup,
int (*get)(Object *, Error **), int (*get)(Object *, Error **),
@ -1640,8 +1650,10 @@ ObjectProperty *object_class_property_add_enum(ObjectClass *klass,
* *
* Add a read-only struct tm valued property using a getter function. * Add a read-only struct tm valued property using a getter function.
* This function will add a property of type 'struct tm'. * This function will add a property of type 'struct tm'.
*
* Returns: The newly added property on success, or %NULL on failure.
*/ */
void object_property_add_tm(Object *obj, const char *name, ObjectProperty *object_property_add_tm(Object *obj, const char *name,
void (*get)(Object *, struct tm *, Error **), void (*get)(Object *, struct tm *, Error **),
Error **errp); Error **errp);
@ -1669,8 +1681,10 @@ typedef enum {
* *
* Add an integer property in memory. This function will add a * Add an integer property in memory. This function will add a
* property of type 'uint8'. * property of type 'uint8'.
*
* Returns: The newly added property on success, or %NULL on failure.
*/ */
void object_property_add_uint8_ptr(Object *obj, const char *name, ObjectProperty *object_property_add_uint8_ptr(Object *obj, const char *name,
const uint8_t *v, ObjectPropertyFlags flags, const uint8_t *v, ObjectPropertyFlags flags,
Error **errp); Error **errp);
@ -1690,8 +1704,10 @@ ObjectProperty *object_class_property_add_uint8_ptr(ObjectClass *klass,
* *
* Add an integer property in memory. This function will add a * Add an integer property in memory. This function will add a
* property of type 'uint16'. * property of type 'uint16'.
*
* Returns: The newly added property on success, or %NULL on failure.
*/ */
void object_property_add_uint16_ptr(Object *obj, const char *name, ObjectProperty *object_property_add_uint16_ptr(Object *obj, const char *name,
const uint16_t *v, const uint16_t *v,
ObjectPropertyFlags flags, ObjectPropertyFlags flags,
Error **errp); Error **errp);
@ -1712,8 +1728,10 @@ ObjectProperty *object_class_property_add_uint16_ptr(ObjectClass *klass,
* *
* Add an integer property in memory. This function will add a * Add an integer property in memory. This function will add a
* property of type 'uint32'. * property of type 'uint32'.
*
* Returns: The newly added property on success, or %NULL on failure.
*/ */
void object_property_add_uint32_ptr(Object *obj, const char *name, ObjectProperty *object_property_add_uint32_ptr(Object *obj, const char *name,
const uint32_t *v, const uint32_t *v,
ObjectPropertyFlags flags, ObjectPropertyFlags flags,
Error **errp); Error **errp);
@ -1734,8 +1752,10 @@ ObjectProperty *object_class_property_add_uint32_ptr(ObjectClass *klass,
* *
* Add an integer property in memory. This function will add a * Add an integer property in memory. This function will add a
* property of type 'uint64'. * property of type 'uint64'.
*
* Returns: The newly added property on success, or %NULL on failure.
*/ */
void object_property_add_uint64_ptr(Object *obj, const char *name, ObjectProperty *object_property_add_uint64_ptr(Object *obj, const char *name,
const uint64_t *v, const uint64_t *v,
ObjectPropertyFlags flags, ObjectPropertyFlags flags,
Error **Errp); Error **Errp);
@ -1761,8 +1781,10 @@ ObjectProperty *object_class_property_add_uint64_ptr(ObjectClass *klass,
* this property exists. In the case of a child object or an alias on the same * this property exists. In the case of a child object or an alias on the same
* object this will be the case. For aliases to other objects the caller is * object this will be the case. For aliases to other objects the caller is
* responsible for taking a reference. * responsible for taking a reference.
*
* Returns: The newly added property on success, or %NULL on failure.
*/ */
void object_property_add_alias(Object *obj, const char *name, ObjectProperty *object_property_add_alias(Object *obj, const char *name,
Object *target_obj, const char *target_name, Object *target_obj, const char *target_name,
Error **errp); Error **errp);
@ -1780,8 +1802,10 @@ void object_property_add_alias(Object *obj, const char *name,
* this property exists. In the case @target is a child of @obj, * this property exists. In the case @target is a child of @obj,
* this will be the case. Otherwise, the caller is responsible for * this will be the case. Otherwise, the caller is responsible for
* taking a reference. * taking a reference.
*
* Returns: The newly added property on success, or %NULL on failure.
*/ */
void object_property_add_const_link(Object *obj, const char *name, ObjectProperty *object_property_add_const_link(Object *obj, const char *name,
Object *target, Error **errp); Object *target, Error **errp);
/** /**

View File

@ -1646,33 +1646,30 @@ static void object_finalize_child_property(Object *obj, const char *name,
object_unref(child); object_unref(child);
} }
void object_property_add_child(Object *obj, const char *name, ObjectProperty *
Object *child, Error **errp) object_property_add_child(Object *obj, const char *name,
Object *child, Error **errp)
{ {
Error *local_err = NULL; g_autofree char *type = NULL;
char *type;
ObjectProperty *op; ObjectProperty *op;
if (child->parent != NULL) { if (child->parent != NULL) {
error_setg(errp, "child object is already parented"); error_setg(errp, "child object is already parented");
return; return NULL;
} }
type = g_strdup_printf("child<%s>", object_get_typename(OBJECT(child))); type = g_strdup_printf("child<%s>", object_get_typename(OBJECT(child)));
op = object_property_add(obj, name, type, object_get_child_property, NULL, op = object_property_add(obj, name, type, object_get_child_property, NULL,
object_finalize_child_property, child, &local_err); object_finalize_child_property, child, errp);
if (local_err) { if (!op) {
error_propagate(errp, local_err); return NULL;
goto out;
} }
op->resolve = object_resolve_child_property; op->resolve = object_resolve_child_property;
object_ref(child); object_ref(child);
child->parent = obj; child->parent = obj;
return op;
out:
g_free(type);
} }
void object_property_allow_set_link(const Object *obj, const char *name, void object_property_allow_set_link(const Object *obj, const char *name,
@ -1819,16 +1816,16 @@ static void object_release_link_property(Object *obj, const char *name,
} }
} }
static void object_add_link_prop(Object *obj, const char *name, static ObjectProperty *
const char *type, void *ptr, object_add_link_prop(Object *obj, const char *name,
void (*check)(const Object *, const char *, const char *type, void *ptr,
Object *, Error **), void (*check)(const Object *, const char *,
ObjectPropertyLinkFlags flags, Object *, Error **),
Error **errp) ObjectPropertyLinkFlags flags,
Error **errp)
{ {
Error *local_err = NULL;
LinkProperty *prop = g_malloc(sizeof(*prop)); LinkProperty *prop = g_malloc(sizeof(*prop));
char *full_type; g_autofree char *full_type = NULL;
ObjectProperty *op; ObjectProperty *op;
if (flags & OBJ_PROP_LINK_DIRECT) { if (flags & OBJ_PROP_LINK_DIRECT) {
@ -1846,27 +1843,26 @@ static void object_add_link_prop(Object *obj, const char *name,
check ? object_set_link_property : NULL, check ? object_set_link_property : NULL,
object_release_link_property, object_release_link_property,
prop, prop,
&local_err); errp);
if (local_err) { if (!op) {
error_propagate(errp, local_err);
g_free(prop); g_free(prop);
goto out; return NULL;
} }
op->resolve = object_resolve_link_property; op->resolve = object_resolve_link_property;
return op;
out:
g_free(full_type);
} }
void object_property_add_link(Object *obj, const char *name, ObjectProperty *
const char *type, Object **targetp, object_property_add_link(Object *obj, const char *name,
void (*check)(const Object *, const char *, const char *type, Object **targetp,
Object *, Error **), void (*check)(const Object *, const char *,
ObjectPropertyLinkFlags flags, Object *, Error **),
Error **errp) ObjectPropertyLinkFlags flags,
Error **errp)
{ {
object_add_link_prop(obj, name, type, targetp, check, flags, errp); return object_add_link_prop(obj, name, type, targetp, check, flags,
errp);
} }
ObjectProperty * ObjectProperty *
@ -1908,11 +1904,13 @@ out:
return op; return op;
} }
void object_property_add_const_link(Object *obj, const char *name, ObjectProperty *
Object *target, Error **errp) object_property_add_const_link(Object *obj, const char *name,
Object *target, Error **errp)
{ {
object_add_link_prop(obj, name, object_get_typename(target), target, return object_add_link_prop(obj, name,
NULL, OBJ_PROP_LINK_DIRECT, errp); object_get_typename(target), target,
NULL, OBJ_PROP_LINK_DIRECT, errp);
} }
char *object_get_canonical_path_component(Object *obj) char *object_get_canonical_path_component(Object *obj)
@ -2121,26 +2119,27 @@ static void property_release_str(Object *obj, const char *name,
g_free(prop); g_free(prop);
} }
void object_property_add_str(Object *obj, const char *name, ObjectProperty *
char *(*get)(Object *, Error **), object_property_add_str(Object *obj, const char *name,
void (*set)(Object *, const char *, Error **), char *(*get)(Object *, Error **),
Error **errp) void (*set)(Object *, const char *, Error **),
Error **errp)
{ {
Error *local_err = NULL;
StringProperty *prop = g_malloc0(sizeof(*prop)); StringProperty *prop = g_malloc0(sizeof(*prop));
ObjectProperty *op;
prop->get = get; prop->get = get;
prop->set = set; prop->set = set;
object_property_add(obj, name, "string", op = object_property_add(obj, name, "string",
get ? property_get_str : NULL, get ? property_get_str : NULL,
set ? property_set_str : NULL, set ? property_set_str : NULL,
property_release_str, property_release_str,
prop, &local_err); prop, errp);
if (local_err) { if (!op) {
error_propagate(errp, local_err);
g_free(prop); g_free(prop);
} }
return op;
} }
ObjectProperty * ObjectProperty *
@ -2215,26 +2214,27 @@ static void property_release_bool(Object *obj, const char *name,
g_free(prop); g_free(prop);
} }
void object_property_add_bool(Object *obj, const char *name, ObjectProperty *
bool (*get)(Object *, Error **), object_property_add_bool(Object *obj, const char *name,
void (*set)(Object *, bool, Error **), bool (*get)(Object *, Error **),
Error **errp) void (*set)(Object *, bool, Error **),
Error **errp)
{ {
Error *local_err = NULL;
BoolProperty *prop = g_malloc0(sizeof(*prop)); BoolProperty *prop = g_malloc0(sizeof(*prop));
ObjectProperty *op;
prop->get = get; prop->get = get;
prop->set = set; prop->set = set;
object_property_add(obj, name, "bool", op = object_property_add(obj, name, "bool",
get ? property_get_bool : NULL, get ? property_get_bool : NULL,
set ? property_set_bool : NULL, set ? property_set_bool : NULL,
property_release_bool, property_release_bool,
prop, &local_err); prop, errp);
if (local_err) { if (!op) {
error_propagate(errp, local_err);
g_free(prop); g_free(prop);
} }
return op;
} }
ObjectProperty * ObjectProperty *
@ -2301,29 +2301,30 @@ static void property_release_enum(Object *obj, const char *name,
g_free(prop); g_free(prop);
} }
void object_property_add_enum(Object *obj, const char *name, ObjectProperty *
const char *typename, object_property_add_enum(Object *obj, const char *name,
const QEnumLookup *lookup, const char *typename,
int (*get)(Object *, Error **), const QEnumLookup *lookup,
void (*set)(Object *, int, Error **), int (*get)(Object *, Error **),
Error **errp) void (*set)(Object *, int, Error **),
Error **errp)
{ {
Error *local_err = NULL;
EnumProperty *prop = g_malloc(sizeof(*prop)); EnumProperty *prop = g_malloc(sizeof(*prop));
ObjectProperty *op;
prop->lookup = lookup; prop->lookup = lookup;
prop->get = get; prop->get = get;
prop->set = set; prop->set = set;
object_property_add(obj, name, typename, op = object_property_add(obj, name, typename,
get ? property_get_enum : NULL, get ? property_get_enum : NULL,
set ? property_set_enum : NULL, set ? property_set_enum : NULL,
property_release_enum, property_release_enum,
prop, &local_err); prop, errp);
if (local_err) { if (!op) {
error_propagate(errp, local_err);
g_free(prop); g_free(prop);
} }
return op;
} }
ObjectProperty * ObjectProperty *
@ -2414,23 +2415,24 @@ static void property_release_tm(Object *obj, const char *name,
g_free(prop); g_free(prop);
} }
void object_property_add_tm(Object *obj, const char *name, ObjectProperty *
void (*get)(Object *, struct tm *, Error **), object_property_add_tm(Object *obj, const char *name,
Error **errp) void (*get)(Object *, struct tm *, Error **),
Error **errp)
{ {
Error *local_err = NULL;
TMProperty *prop = g_malloc0(sizeof(*prop)); TMProperty *prop = g_malloc0(sizeof(*prop));
ObjectProperty *op;
prop->get = get; prop->get = get;
object_property_add(obj, name, "struct tm", op = object_property_add(obj, name, "struct tm",
get ? property_get_tm : NULL, NULL, get ? property_get_tm : NULL, NULL,
property_release_tm, property_release_tm,
prop, &local_err); prop, errp);
if (local_err) { if (!op) {
error_propagate(errp, local_err);
g_free(prop); g_free(prop);
} }
return op;
} }
ObjectProperty * ObjectProperty *
@ -2553,10 +2555,11 @@ static void property_set_uint64_ptr(Object *obj, Visitor *v, const char *name,
*field = value; *field = value;
} }
void object_property_add_uint8_ptr(Object *obj, const char *name, ObjectProperty *
const uint8_t *v, object_property_add_uint8_ptr(Object *obj, const char *name,
ObjectPropertyFlags flags, const uint8_t *v,
Error **errp) ObjectPropertyFlags flags,
Error **errp)
{ {
ObjectPropertyAccessor *getter = NULL; ObjectPropertyAccessor *getter = NULL;
ObjectPropertyAccessor *setter = NULL; ObjectPropertyAccessor *setter = NULL;
@ -2569,8 +2572,8 @@ void object_property_add_uint8_ptr(Object *obj, const char *name,
setter = property_set_uint8_ptr; setter = property_set_uint8_ptr;
} }
object_property_add(obj, name, "uint8", return object_property_add(obj, name, "uint8",
getter, setter, NULL, (void *)v, errp); getter, setter, NULL, (void *)v, errp);
} }
ObjectProperty * ObjectProperty *
@ -2594,10 +2597,11 @@ object_class_property_add_uint8_ptr(ObjectClass *klass, const char *name,
getter, setter, NULL, (void *)v, errp); getter, setter, NULL, (void *)v, errp);
} }
void object_property_add_uint16_ptr(Object *obj, const char *name, ObjectProperty *
const uint16_t *v, object_property_add_uint16_ptr(Object *obj, const char *name,
ObjectPropertyFlags flags, const uint16_t *v,
Error **errp) ObjectPropertyFlags flags,
Error **errp)
{ {
ObjectPropertyAccessor *getter = NULL; ObjectPropertyAccessor *getter = NULL;
ObjectPropertyAccessor *setter = NULL; ObjectPropertyAccessor *setter = NULL;
@ -2610,8 +2614,8 @@ void object_property_add_uint16_ptr(Object *obj, const char *name,
setter = property_set_uint16_ptr; setter = property_set_uint16_ptr;
} }
object_property_add(obj, name, "uint16", return object_property_add(obj, name, "uint16",
getter, setter, NULL, (void *)v, errp); getter, setter, NULL, (void *)v, errp);
} }
ObjectProperty * ObjectProperty *
@ -2635,10 +2639,11 @@ object_class_property_add_uint16_ptr(ObjectClass *klass, const char *name,
getter, setter, NULL, (void *)v, errp); getter, setter, NULL, (void *)v, errp);
} }
void object_property_add_uint32_ptr(Object *obj, const char *name, ObjectProperty *
const uint32_t *v, object_property_add_uint32_ptr(Object *obj, const char *name,
ObjectPropertyFlags flags, const uint32_t *v,
Error **errp) ObjectPropertyFlags flags,
Error **errp)
{ {
ObjectPropertyAccessor *getter = NULL; ObjectPropertyAccessor *getter = NULL;
ObjectPropertyAccessor *setter = NULL; ObjectPropertyAccessor *setter = NULL;
@ -2651,8 +2656,8 @@ void object_property_add_uint32_ptr(Object *obj, const char *name,
setter = property_set_uint32_ptr; setter = property_set_uint32_ptr;
} }
object_property_add(obj, name, "uint32", return object_property_add(obj, name, "uint32",
getter, setter, NULL, (void *)v, errp); getter, setter, NULL, (void *)v, errp);
} }
ObjectProperty * ObjectProperty *
@ -2676,10 +2681,11 @@ object_class_property_add_uint32_ptr(ObjectClass *klass, const char *name,
getter, setter, NULL, (void *)v, errp); getter, setter, NULL, (void *)v, errp);
} }
void object_property_add_uint64_ptr(Object *obj, const char *name, ObjectProperty *
const uint64_t *v, object_property_add_uint64_ptr(Object *obj, const char *name,
ObjectPropertyFlags flags, const uint64_t *v,
Error **errp) ObjectPropertyFlags flags,
Error **errp)
{ {
ObjectPropertyAccessor *getter = NULL; ObjectPropertyAccessor *getter = NULL;
ObjectPropertyAccessor *setter = NULL; ObjectPropertyAccessor *setter = NULL;
@ -2692,8 +2698,8 @@ void object_property_add_uint64_ptr(Object *obj, const char *name,
setter = property_set_uint64_ptr; setter = property_set_uint64_ptr;
} }
object_property_add(obj, name, "uint64", return object_property_add(obj, name, "uint64",
getter, setter, NULL, (void *)v, errp); getter, setter, NULL, (void *)v, errp);
} }
ObjectProperty * ObjectProperty *
@ -2754,19 +2760,19 @@ static void property_release_alias(Object *obj, const char *name, void *opaque)
g_free(prop); g_free(prop);
} }
void object_property_add_alias(Object *obj, const char *name, ObjectProperty *
Object *target_obj, const char *target_name, object_property_add_alias(Object *obj, const char *name,
Error **errp) Object *target_obj, const char *target_name,
Error **errp)
{ {
AliasProperty *prop; AliasProperty *prop;
ObjectProperty *op; ObjectProperty *op;
ObjectProperty *target_prop; ObjectProperty *target_prop;
char *prop_type; g_autofree char *prop_type = NULL;
Error *local_err = NULL;
target_prop = object_property_find(target_obj, target_name, errp); target_prop = object_property_find(target_obj, target_name, errp);
if (!target_prop) { if (!target_prop) {
return; return NULL;
} }
if (object_property_is_child(target_prop)) { if (object_property_is_child(target_prop)) {
@ -2784,12 +2790,12 @@ void object_property_add_alias(Object *obj, const char *name,
property_get_alias, property_get_alias,
property_set_alias, property_set_alias,
property_release_alias, property_release_alias,
prop, &local_err); prop, errp);
if (local_err) { if (!op) {
error_propagate(errp, local_err);
g_free(prop); g_free(prop);
goto out; return NULL;
} }
op->resolve = property_resolve_alias; op->resolve = property_resolve_alias;
if (target_prop->defval) { if (target_prop->defval) {
op->defval = qobject_ref(target_prop->defval); op->defval = qobject_ref(target_prop->defval);
@ -2798,9 +2804,7 @@ void object_property_add_alias(Object *obj, const char *name,
object_property_set_description(obj, op->name, object_property_set_description(obj, op->name,
target_prop->description, target_prop->description,
&error_abort); &error_abort);
return op;
out:
g_free(prop_type);
} }
void object_property_set_description(Object *obj, const char *name, void object_property_set_description(Object *obj, const char *name,