[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 14/24] qom: Split out object and class caches
From: |
Andreas Färber |
Subject: |
[Qemu-devel] [PULL 14/24] qom: Split out object and class caches |
Date: |
Tue, 24 Dec 2013 17:57:07 +0100 |
From: Peter Crosthwaite <address@hidden>
The object-cast and class-cast caches cannot be shared because class
caching is conditional on the target type not being an interface and
object caching is unconditional. Leads to a bug when a class cast
to an interface follows an object cast to the same interface type:
FooObject = FOO(obj);
FooClass = FOO_GET_CLASS(obj);
Where TYPE_FOO is an interface. The first (object) cast will be
successful and cache the casting result (i.e. TYPE_FOO will be cached).
The second (class) cast will then check the shared cast cache
and register a hit. The issue is, when a class cast hits in the cache
it just returns a pointer cast of the input class (i.e. the concrete
class).
When casting to an interface, the cast itself must return the
interface class, not the concrete class. The implementation of class
cast caching already ensures that the returned cast result is only
a pointer cast before caching. The object cast logic however does
not have this check.
Resolve by just splitting the object and class caches.
Cc: address@hidden
Signed-off-by: Peter Crosthwaite <address@hidden>
Reviewed-by: Paolo Bonzini <address@hidden>
Tested-by: Nathan Rossi <address@hidden>
Reviewed-by: Edgar E. Iglesias <address@hidden>
Signed-off-by: Andreas Färber <address@hidden>
---
include/qom/object.h | 3 ++-
qom/object.c | 13 +++++++------
2 files changed, 9 insertions(+), 7 deletions(-)
diff --git a/include/qom/object.h b/include/qom/object.h
index a275db2..5f78847 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -358,7 +358,8 @@ struct ObjectClass
Type type;
GSList *interfaces;
- const char *cast_cache[OBJECT_CLASS_CAST_CACHE];
+ const char *object_cast_cache[OBJECT_CLASS_CAST_CACHE];
+ const char *class_cast_cache[OBJECT_CLASS_CAST_CACHE];
ObjectUnparent *unparent;
};
diff --git a/qom/object.c b/qom/object.c
index fc19cf6..21b5a0b 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -458,7 +458,7 @@ Object *object_dynamic_cast_assert(Object *obj, const char
*typename,
Object *inst;
for (i = 0; obj && i < OBJECT_CLASS_CAST_CACHE; i++) {
- if (obj->class->cast_cache[i] == typename) {
+ if (obj->class->object_cast_cache[i] == typename) {
goto out;
}
}
@@ -475,9 +475,10 @@ Object *object_dynamic_cast_assert(Object *obj, const char
*typename,
if (obj && obj == inst) {
for (i = 1; i < OBJECT_CLASS_CAST_CACHE; i++) {
- obj->class->cast_cache[i - 1] = obj->class->cast_cache[i];
+ obj->class->object_cast_cache[i - 1] =
+ obj->class->object_cast_cache[i];
}
- obj->class->cast_cache[i - 1] = typename;
+ obj->class->object_cast_cache[i - 1] = typename;
}
out:
@@ -547,7 +548,7 @@ ObjectClass *object_class_dynamic_cast_assert(ObjectClass
*class,
int i;
for (i = 0; class && i < OBJECT_CLASS_CAST_CACHE; i++) {
- if (class->cast_cache[i] == typename) {
+ if (class->class_cast_cache[i] == typename) {
ret = class;
goto out;
}
@@ -568,9 +569,9 @@ ObjectClass *object_class_dynamic_cast_assert(ObjectClass
*class,
#ifdef CONFIG_QOM_CAST_DEBUG
if (class && ret == class) {
for (i = 1; i < OBJECT_CLASS_CAST_CACHE; i++) {
- class->cast_cache[i - 1] = class->cast_cache[i];
+ class->class_cast_cache[i - 1] = class->class_cast_cache[i];
}
- class->cast_cache[i - 1] = typename;
+ class->class_cast_cache[i - 1] = typename;
}
out:
#endif
--
1.8.4
- [Qemu-devel] [PULL 00/24] QOM devices patch queue 2013-12-24, Andreas Färber, 2013/12/24
- [Qemu-devel] [PULL 03/24] cpu: Document why cannot_instantiate_with_device_add_yet, Andreas Färber, 2013/12/24
- [Qemu-devel] [PULL 08/24] vt82c686: Clean up use of cannot_instantiate_with_device_add_yet, Andreas Färber, 2013/12/24
- [Qemu-devel] [PULL 11/24] qdev-monitor: Avoid device_add crashing on non-device driver name, Andreas Färber, 2013/12/24
- [Qemu-devel] [PULL 06/24] ich9: Document why cannot_instantiate_with_device_add_yet, Andreas Färber, 2013/12/24
- [Qemu-devel] [PULL 02/24] sysbus: Set cannot_instantiate_with_device_add_yet, Andreas Färber, 2013/12/24
- [Qemu-devel] [PULL 04/24] apic: Document why cannot_instantiate_with_device_add_yet, Andreas Färber, 2013/12/24
- [Qemu-devel] [PULL 05/24] pci-host: Consistently set cannot_instantiate_with_device_add_yet, Andreas Färber, 2013/12/24
- [Qemu-devel] [PULL 14/24] qom: Split out object and class caches,
Andreas Färber <=
- [Qemu-devel] [PULL 07/24] piix3 piix4: Clean up use of cannot_instantiate_with_device_add_yet, Andreas Färber, 2013/12/24
- [Qemu-devel] [PULL 09/24] isa: Clean up use of cannot_instantiate_with_device_add_yet, Andreas Färber, 2013/12/24
- [Qemu-devel] [PULL 01/24] qdev: Replace no_user by cannot_instantiate_with_device_add_yet, Andreas Färber, 2013/12/24
- [Qemu-devel] [PULL 17/24] qom: Detect bad reentrance during object_class_foreach(), Andreas Färber, 2013/12/24
- [Qemu-devel] [PULL 10/24] qdev: Do not let the user try to device_add when it cannot work, Andreas Färber, 2013/12/24
- [Qemu-devel] [PULL 12/24] hw: cannot_instantiate_with_device_add_yet due to pointer props, Andreas Färber, 2013/12/24
- [Qemu-devel] [PULL 15/24] qom: Do not register interface "types" in the type table and fix names, Andreas Färber, 2013/12/24
- [Qemu-devel] [PULL 13/24] qdev: Document that pointer properties kill device_add, Andreas Färber, 2013/12/24
- [Qemu-devel] [PULL 16/24] tests: Test QOM interface casting, Andreas Färber, 2013/12/24
- [Qemu-devel] [PULL 18/24] qdev: Drop misleading qbus_free() function, Andreas Färber, 2013/12/24