qom: allow casting of a NULL class
This mimics what we do in object_dynamic_cast_assert. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Message-id: 1368188203-3407-3-git-send-email-pbonzini@redhat.com Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
parent
33bc94eb20
commit
bf0fda3466
12
qom/object.c
12
qom/object.c
@ -449,10 +449,16 @@ Object *object_dynamic_cast_assert(Object *obj, const char *typename)
|
|||||||
ObjectClass *object_class_dynamic_cast(ObjectClass *class,
|
ObjectClass *object_class_dynamic_cast(ObjectClass *class,
|
||||||
const char *typename)
|
const char *typename)
|
||||||
{
|
{
|
||||||
TypeImpl *target_type = type_get_by_name(typename);
|
|
||||||
TypeImpl *type = class->type;
|
|
||||||
ObjectClass *ret = NULL;
|
ObjectClass *ret = NULL;
|
||||||
|
TypeImpl *target_type;
|
||||||
|
TypeImpl *type;
|
||||||
|
|
||||||
|
if (!class) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
type = class->type;
|
||||||
|
target_type = type_get_by_name(typename);
|
||||||
if (!target_type) {
|
if (!target_type) {
|
||||||
/* target class type unknown, so fail the cast */
|
/* target class type unknown, so fail the cast */
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -488,7 +494,7 @@ ObjectClass *object_class_dynamic_cast_assert(ObjectClass *class,
|
|||||||
{
|
{
|
||||||
ObjectClass *ret = object_class_dynamic_cast(class, typename);
|
ObjectClass *ret = object_class_dynamic_cast(class, typename);
|
||||||
|
|
||||||
if (!ret) {
|
if (!ret && class) {
|
||||||
fprintf(stderr, "Object %p is not an instance of type %s\n",
|
fprintf(stderr, "Object %p is not an instance of type %s\n",
|
||||||
class, typename);
|
class, typename);
|
||||||
abort();
|
abort();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user