qom: Split out object and class caches
commit0ab4c94c844cb3953adedbd27adc378b3cf31d9e
authorPeter Crosthwaite <peter.crosthwaite@xilinx.com>
Thu, 28 Nov 2013 04:27:33 +0000 (27 20:27 -0800)
committerAndreas Färber <afaerber@suse.de>
Tue, 24 Dec 2013 16:27:17 +0000 (24 17:27 +0100)
treea4755b0c34aa6f7bc3c97ae673e7ac2f82e24e4c
parentc272758f93b9c88c884461a2baa37b8f4008bf02
qom: Split out object and class caches

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: qemu-stable@nongnu.org
Signed-off-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Tested-by: Nathan Rossi <nathan.rossi@xilinx.com>
Reviewed-by: Edgar E. Iglesias <edgar.iglesias@gmail.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
include/qom/object.h
qom/object.c