mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
maint: improve VIR_ERR_INVALID_CONN usage
The datatype.c object checks could result in a message like: error: invalid connection pointer in no connection This consolidates all clients of this message to have uniform contents: error: invalid connection pointer in someFunc Note that virCheckConnectReturn raises an error immediately; in datatypes.c, where we don't need to raise the error (but instead just leave it in the thread-local setting), we use virCheckConnectGoto and the cleanup label instead. Then, for consistency in that file, all subsequent error messages are touched to also use the cleanup error label. * src/datatypes.h (virCheckConnectReturn) (virCheckConnectGoto): New macros. * src/datatypes.c: Use new macro. * src/libvirt-qemu.c (virDomainQemuAttach): Likewise. (virLibConnError): Delete unused macro. * src/libvirt-lxc.c (virLibConnError): Likewise. * src/libvirt.c: Use new macro throughout. * docs/api_extension.html.in: Modernize documentation. Signed-off-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
@@ -42,6 +42,25 @@ extern virClassPtr virStoragePoolClass;
|
||||
|
||||
# define VIR_IS_CONNECT(obj) \
|
||||
(virObjectIsClass((obj), virConnectClass))
|
||||
# define virCheckConnectReturn(obj, retval) \
|
||||
do { \
|
||||
if (!VIR_IS_CONNECT(obj)) { \
|
||||
virReportErrorHelper(VIR_FROM_THIS, VIR_ERR_INVALID_CONN, \
|
||||
__FILE__, __FUNCTION__, __LINE__, \
|
||||
__FUNCTION__); \
|
||||
virDispatchError(NULL); \
|
||||
return retval; \
|
||||
} \
|
||||
} while (0)
|
||||
# define virCheckConnectGoto(obj, label) \
|
||||
do { \
|
||||
if (!VIR_IS_CONNECT(obj)) { \
|
||||
virReportErrorHelper(VIR_FROM_THIS, VIR_ERR_INVALID_CONN, \
|
||||
__FILE__, __FUNCTION__, __LINE__, \
|
||||
__FUNCTION__); \
|
||||
goto label; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
# define VIR_IS_DOMAIN(obj) \
|
||||
(virObjectIsClass((obj), virDomainClass))
|
||||
|
||||
Reference in New Issue
Block a user