[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 43/59] object: add direct link flag
From: |
Paolo Bonzini |
Subject: |
[PULL 43/59] object: add direct link flag |
Date: |
Thu, 23 Jan 2020 14:50:33 +0100 |
From: Marc-André Lureau <address@hidden>
Allow the link property to hold the pointer to the target, instead of
indirectly through another variable.
Signed-off-by: Marc-André Lureau <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
include/qom/object.h | 3 +++
qom/object.c | 26 ++++++++++++++++++++------
2 files changed, 23 insertions(+), 6 deletions(-)
diff --git a/include/qom/object.h b/include/qom/object.h
index a163adc..24d6ebe 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -1511,6 +1511,9 @@ void object_property_add_child(Object *obj, const char
*name,
typedef enum {
/* Unref the link pointer when the property is deleted */
OBJ_PROP_LINK_STRONG = 0x1,
+
+ /* private */
+ OBJ_PROP_LINK_DIRECT = 0x2,
} ObjectPropertyLinkFlags;
/**
diff --git a/qom/object.c b/qom/object.c
index bb5b739..a9760d5 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -1713,17 +1713,30 @@ void object_property_allow_set_link(const Object *obj,
const char *name,
}
typedef struct {
- Object **targetp;
+ union {
+ Object **targetp;
+ Object *target; /* if OBJ_PROP_LINK_DIRECT, when holding the pointer
*/
+ };
void (*check)(const Object *, const char *, Object *, Error **);
ObjectPropertyLinkFlags flags;
} LinkProperty;
+static Object **
+object_link_get_targetp(Object *obj, LinkProperty *lprop)
+{
+ if (lprop->flags & OBJ_PROP_LINK_DIRECT) {
+ return &lprop->target;
+ } else {
+ return lprop->targetp;
+ }
+}
+
static void object_get_link_property(Object *obj, Visitor *v,
const char *name, void *opaque,
Error **errp)
{
LinkProperty *lprop = opaque;
- Object **targetp = lprop->targetp;
+ Object **targetp = object_link_get_targetp(obj, lprop);
gchar *path;
if (*targetp) {
@@ -1782,7 +1795,7 @@ static void object_set_link_property(Object *obj, Visitor
*v,
{
Error *local_err = NULL;
LinkProperty *prop = opaque;
- Object **targetp = prop->targetp;
+ Object **targetp = object_link_get_targetp(obj, prop);
Object *old_target = *targetp;
Object *new_target = NULL;
char *path = NULL;
@@ -1816,16 +1829,17 @@ static Object *object_resolve_link_property(Object
*parent, void *opaque, const
{
LinkProperty *lprop = opaque;
- return *lprop->targetp;
+ return *object_link_get_targetp(parent, lprop);
}
static void object_release_link_property(Object *obj, const char *name,
void *opaque)
{
LinkProperty *prop = opaque;
+ Object **targetp = object_link_get_targetp(obj, prop);
- if ((prop->flags & OBJ_PROP_LINK_STRONG) && *prop->targetp) {
- object_unref(*prop->targetp);
+ if ((prop->flags & OBJ_PROP_LINK_STRONG) && *targetp) {
+ object_unref(*targetp);
}
g_free(prop);
}
--
1.8.3.1
- [PULL 33/59] qdev: remove extraneous error, (continued)
- [PULL 33/59] qdev: remove extraneous error, Paolo Bonzini, 2020/01/23
- [PULL 34/59] qdev: move helper function to monitor/misc, Paolo Bonzini, 2020/01/23
- [PULL 35/59] object: avoid extra class property key duplication, Paolo Bonzini, 2020/01/23
- [PULL 36/59] object: add class property initializer, Paolo Bonzini, 2020/01/23
- [PULL 37/59] object: make object_class_property_add* return property, Paolo Bonzini, 2020/01/23
- [PULL 38/59] qstring: add qstring_free(), Paolo Bonzini, 2020/01/23
- [PULL 39/59] object: add object_property_set_default, Paolo Bonzini, 2020/01/23
- [PULL 40/59] object: do not free class properties, Paolo Bonzini, 2020/01/23
- [PULL 41/59] object: check strong flag with &, Paolo Bonzini, 2020/01/23
- [PULL 42/59] object: rename link "child" to "target", Paolo Bonzini, 2020/01/23
- [PULL 43/59] object: add direct link flag,
Paolo Bonzini <=
- [PULL 44/59] object: express const link with link property, Paolo Bonzini, 2020/01/23
- [PULL 45/59] object: add object_class_property_add_link(), Paolo Bonzini, 2020/01/23
- [PULL 46/59] object: release all props, Paolo Bonzini, 2020/01/23
- [PULL 47/59] object: return self in object_ref(), Paolo Bonzini, 2020/01/23
- [PULL 49/59] qdev: rename DeviceClass.props, Paolo Bonzini, 2020/01/23
- [PULL 50/59] qdev: move instance properties to class properties, Paolo Bonzini, 2020/01/23
- [PULL 52/59] vl: print default value in object help, Paolo Bonzini, 2020/01/23
- [PULL 51/59] qdev: register properties as class properties, Paolo Bonzini, 2020/01/23
- [PULL 53/59] qom: simplify qmp_device_list_properties(), Paolo Bonzini, 2020/01/23
- [PULL 54/59] qom: introduce object_property_help(), Paolo Bonzini, 2020/01/23