From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:38368) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QWYCW-0005y5-J9 for qemu-devel@nongnu.org; Tue, 14 Jun 2011 14:18:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QWYCT-0006AT-Bj for qemu-devel@nongnu.org; Tue, 14 Jun 2011 14:18:56 -0400 Received: from mtagate7.uk.ibm.com ([194.196.100.167]:59904) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QWYCS-00068D-Dt for qemu-devel@nongnu.org; Tue, 14 Jun 2011 14:18:52 -0400 Received: from d06nrmr1806.portsmouth.uk.ibm.com (d06nrmr1806.portsmouth.uk.ibm.com [9.149.39.193]) by mtagate7.uk.ibm.com (8.13.1/8.13.1) with ESMTP id p5EIIkJO028289 for ; Tue, 14 Jun 2011 18:18:46 GMT Received: from d06av12.portsmouth.uk.ibm.com (d06av12.portsmouth.uk.ibm.com [9.149.37.247]) by d06nrmr1806.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p5EIIkv22683044 for ; Tue, 14 Jun 2011 19:18:46 +0100 Received: from d06av12.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av12.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p5EIIkcI015201 for ; Tue, 14 Jun 2011 12:18:46 -0600 From: Stefan Hajnoczi Date: Tue, 14 Jun 2011 19:18:26 +0100 Message-Id: <1308075511-4745-9-git-send-email-stefanha@linux.vnet.ibm.com> In-Reply-To: <1308075511-4745-1-git-send-email-stefanha@linux.vnet.ibm.com> References: <1308075511-4745-1-git-send-email-stefanha@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH 08/13] qerror: add qerror_from_args() to create qerror objects List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Anthony Liguori , Stefan Hajnoczi , Adam Litke 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 --- 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