There is no convenient way to create a QError object without reporting it immediately. This patch adds the qerror_from_args() function to make it easy to create an error in qerror_report() style but without reporting it.
Signed-off-by: Stefan Hajnoczi <stefa...@linux.vnet.ibm.com> --- qerror.c | 21 +++++++++++++++++++++ qerror.h | 6 ++++++ 2 files changed, 27 insertions(+), 0 deletions(-) diff --git a/qerror.c b/qerror.c index d7fcd93..64b41ca 100644 --- a/qerror.c +++ b/qerror.c @@ -443,6 +443,27 @@ void qerror_print(QError *qerror) QDECREF(qstring); } +/** + * qerror_from_args_internal(): Create a new QError + * + * This is a convenience wrapper of the qerror_from_info() function for when a + * va_list is not available. + * + * Return a strong reference. + */ +QError *qerror_from_args_internal(const char *file, int linenr, + const char *func, const char *fmt, ...) +{ + va_list va; + QError *qerror; + + va_start(va, fmt); + qerror = qerror_from_info(file, linenr, func, fmt, &va); + va_end(va); + + return qerror; +} + void qerror_report_internal(const char *file, int linenr, const char *func, const char *fmt, ...) { diff --git a/qerror.h b/qerror.h index 16c830d..173c84f 100644 --- a/qerror.h +++ b/qerror.h @@ -35,6 +35,12 @@ typedef struct QError { QError *qerror_new(void); QError *qerror_from_info(const char *file, int linenr, const char *func, const char *fmt, va_list *va) GCC_FMT_ATTR(4, 0); +QError *qerror_from_args_internal(const char *file, int linenr, + const char *func, const char *fmt, + ...) GCC_FMT_ATTR(4, 0); +#define qerror_from_args(fmt, ...) \ + qerror_from_args_internal(__FILE__, __LINE__, __func__, \ + fmt, ## __VA_ARGS__) QString *qerror_human(const QError *qerror); void qerror_print(QError *qerror); void qerror_report_internal(const char *file, int linenr, const char *func, -- 1.7.5.3