提交 070da02f 编写于 作者: J Jiri Denemark

Introduce virCheckFlags for consistent flags checking

The idea is that every API implementation in driver which has flags
parameter should first call virCheckFlags() macro to check the function
was called with supported flags:

    virCheckFlags(VIR_SUPPORTED_FLAG_1 |
                  VIR_SUPPORTED_FLAG_2 |
                  VIR_ANOTHER_SUPPORTED_FLAG, -1);

The error massage which is printed when unsupported flags are passed
looks like:

    invalid argument in virFooBar: unsupported flags (0x2)

Where the unsupported flags part only prints those flags which were
passed but are not supported rather than all flags passed.
上级 d2327278
......@@ -199,4 +199,30 @@
fprintf(stderr, "Unimplemented block at %s:%d\n", \
__FILE__, __LINE__);
/**
* virCheckFlags:
* @supported: an OR'ed set of supported flags
* @retval: return value in case unsupported flags were passed
*
* To avoid memory leaks this macro has to be used before any non-trivial
* code which could possibly allocate some memory.
*
* Returns nothing. Exits the caller function if unsupported flags were
* passed to it.
*/
# define virCheckFlags(supported, retval) \
do { \
if ((flags & ~(supported))) { \
virReportErrorHelper(NULL, \
VIR_FROM_THIS, \
VIR_ERR_INVALID_ARG, \
__FILE__, \
__FUNCTION__, \
__LINE__, \
_("%s: unsupported flags (0x%x)"), \
__FUNCTION__, flags & ~(supported)); \
return retval; \
} \
} while (0)
#endif /* __VIR_INTERNAL_H__ */
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册