mirror of
https://github.com/qemu/qemu.git
synced 2024-11-24 19:33:39 +08:00
qom: pass file/line/function to asserting casts
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Message-id: 1368188203-3407-5-git-send-email-pbonzini@redhat.com Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
parent
793c96b540
commit
be17f18b8c
@ -476,7 +476,8 @@ struct TypeInfo
|
||||
* generated.
|
||||
*/
|
||||
#define OBJECT_CHECK(type, obj, name) \
|
||||
((type *)object_dynamic_cast_assert(OBJECT(obj), (name)))
|
||||
((type *)object_dynamic_cast_assert(OBJECT(obj), (name), \
|
||||
__FILE__, __LINE__, __func__))
|
||||
|
||||
/**
|
||||
* OBJECT_CLASS_CHECK:
|
||||
@ -489,7 +490,8 @@ struct TypeInfo
|
||||
* specific class type.
|
||||
*/
|
||||
#define OBJECT_CLASS_CHECK(class, obj, name) \
|
||||
((class *)object_class_dynamic_cast_assert(OBJECT_CLASS(obj), (name)))
|
||||
((class *)object_class_dynamic_cast_assert(OBJECT_CLASS(obj), (name), \
|
||||
__FILE__, __LINE__, __func__))
|
||||
|
||||
/**
|
||||
* OBJECT_GET_CLASS:
|
||||
@ -547,7 +549,8 @@ struct InterfaceClass
|
||||
* Returns: @obj casted to @interface if cast is valid, otherwise raise error.
|
||||
*/
|
||||
#define INTERFACE_CHECK(interface, obj, name) \
|
||||
((interface *)object_dynamic_cast_assert(OBJECT((obj)), (name)))
|
||||
((interface *)object_dynamic_cast_assert(OBJECT((obj)), (name), \
|
||||
__FILE__, __LINE__, __func__))
|
||||
|
||||
/**
|
||||
* object_new:
|
||||
@ -615,7 +618,8 @@ Object *object_dynamic_cast(Object *obj, const char *typename);
|
||||
* instead of returning #NULL on failure. This function is not meant to be
|
||||
* called directly, but only through the wrapper macro OBJECT_CHECK.
|
||||
*/
|
||||
Object *object_dynamic_cast_assert(Object *obj, const char *typename);
|
||||
Object *object_dynamic_cast_assert(Object *obj, const char *typename,
|
||||
const char *file, int line, const char *func);
|
||||
|
||||
/**
|
||||
* object_get_class:
|
||||
@ -667,7 +671,9 @@ Type type_register(const TypeInfo *info);
|
||||
* OBJECT_CLASS_CHECK and INTERFACE_CHECK.
|
||||
*/
|
||||
ObjectClass *object_class_dynamic_cast_assert(ObjectClass *klass,
|
||||
const char *typename);
|
||||
const char *typename,
|
||||
const char *file, int line,
|
||||
const char *func);
|
||||
|
||||
/**
|
||||
* object_class_dynamic_cast:
|
||||
|
15
qom/object.c
15
qom/object.c
@ -431,15 +431,16 @@ Object *object_dynamic_cast(Object *obj, const char *typename)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Object *object_dynamic_cast_assert(Object *obj, const char *typename)
|
||||
Object *object_dynamic_cast_assert(Object *obj, const char *typename,
|
||||
const char *file, int line, const char *func)
|
||||
{
|
||||
Object *inst;
|
||||
|
||||
inst = object_dynamic_cast(obj, typename);
|
||||
|
||||
if (!inst && obj) {
|
||||
fprintf(stderr, "Object %p is not an instance of type %s\n",
|
||||
obj, typename);
|
||||
fprintf(stderr, "%s:%d:%s: Object %p is not an instance of type %s\n",
|
||||
file, line, func, obj, typename);
|
||||
abort();
|
||||
}
|
||||
|
||||
@ -495,13 +496,15 @@ ObjectClass *object_class_dynamic_cast(ObjectClass *class,
|
||||
}
|
||||
|
||||
ObjectClass *object_class_dynamic_cast_assert(ObjectClass *class,
|
||||
const char *typename)
|
||||
const char *typename,
|
||||
const char *file, int line,
|
||||
const char *func)
|
||||
{
|
||||
ObjectClass *ret = object_class_dynamic_cast(class, typename);
|
||||
|
||||
if (!ret && class) {
|
||||
fprintf(stderr, "Object %p is not an instance of type %s\n",
|
||||
class, typename);
|
||||
fprintf(stderr, "%s:%d:%s: Object %p is not an instance of type %s\n",
|
||||
file, line, func, class, typename);
|
||||
abort();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user