You need to sign in or sign up before continuing.
提交 19f43952 编写于 作者: J John Ferlan

util: Create common error path for invalid object

If virObjectIsClass fails "internally" to virobject.c, create a
macro to generate the VIR_WARN describing what the problem is.
Also improve the checks and message a bit to indicate which was
the failure - whether the obj was NULL or just not the right class
Signed-off-by: NJohn Ferlan <jferlan@redhat.com>
上级 045d712c
...@@ -47,6 +47,17 @@ struct _virClass { ...@@ -47,6 +47,17 @@ struct _virClass {
virObjectDisposeCallback dispose; virObjectDisposeCallback dispose;
}; };
#define VIR_OBJECT_USAGE_PRINT_WARNING(anyobj, objclass) \
do { \
virObjectPtr obj = anyobj; \
if (!obj) \
VIR_WARN("Object cannot be NULL"); \
else \
VIR_WARN("Object %p (%s) is not a %s instance", \
anyobj, obj->klass->name, #objclass); \
} while (0)
static virClassPtr virObjectClass; static virClassPtr virObjectClass;
static virClassPtr virObjectLockableClass; static virClassPtr virObjectLockableClass;
static virClassPtr virObjectRWLockableClass; static virClassPtr virObjectRWLockableClass;
...@@ -370,15 +381,10 @@ virObjectRef(void *anyobj) ...@@ -370,15 +381,10 @@ virObjectRef(void *anyobj)
static virObjectLockablePtr static virObjectLockablePtr
virObjectGetLockableObj(void *anyobj) virObjectGetLockableObj(void *anyobj)
{ {
virObjectPtr obj;
if (virObjectIsClass(anyobj, virObjectLockableClass)) if (virObjectIsClass(anyobj, virObjectLockableClass))
return anyobj; return anyobj;
obj = anyobj; VIR_OBJECT_USAGE_PRINT_WARNING(anyobj, virObjectLockable);
VIR_WARN("Object %p (%s) is not a virObjectLockable instance",
anyobj, obj ? obj->klass->name : "(unknown)");
return NULL; return NULL;
} }
...@@ -386,15 +392,10 @@ virObjectGetLockableObj(void *anyobj) ...@@ -386,15 +392,10 @@ virObjectGetLockableObj(void *anyobj)
static virObjectRWLockablePtr static virObjectRWLockablePtr
virObjectGetRWLockableObj(void *anyobj) virObjectGetRWLockableObj(void *anyobj)
{ {
virObjectPtr obj;
if (virObjectIsClass(anyobj, virObjectRWLockableClass)) if (virObjectIsClass(anyobj, virObjectRWLockableClass))
return anyobj; return anyobj;
obj = anyobj; VIR_OBJECT_USAGE_PRINT_WARNING(anyobj, virObjectRWLockable);
VIR_WARN("Object %p (%s) is not a virObjectRWLockable instance",
anyobj, obj ? obj->klass->name : "(unknown)");
return NULL; return NULL;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册