From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42861) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VzzSL-0003gJ-VI for qemu-devel@nongnu.org; Sun, 05 Jan 2014 20:58:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VzzSC-0000jx-Vq for qemu-devel@nongnu.org; Sun, 05 Jan 2014 20:58:17 -0500 Received: from e28smtp02.in.ibm.com ([122.248.162.2]:38831) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VzzSC-0000jU-9e for qemu-devel@nongnu.org; Sun, 05 Jan 2014 20:58:08 -0500 Received: from /spool/local by e28smtp02.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 6 Jan 2014 07:28:04 +0530 Received: from d28relay05.in.ibm.com (d28relay05.in.ibm.com [9.184.220.62]) by d28dlp01.in.ibm.com (Postfix) with ESMTP id 50795E0024 for ; Mon, 6 Jan 2014 07:30:46 +0530 (IST) Received: from d28av05.in.ibm.com (d28av05.in.ibm.com [9.184.220.67]) by d28relay05.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id s061w0xB5439902 for ; Mon, 6 Jan 2014 07:28:00 +0530 Received: from d28av05.in.ibm.com (localhost [127.0.0.1]) by d28av05.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id s061w1da002920 for ; Mon, 6 Jan 2014 07:28:01 +0530 Message-ID: <52CA0DA8.3030209@linux.vnet.ibm.com> Date: Mon, 06 Jan 2014 09:58:00 +0800 From: Wenchao Xia MIME-Version: 1.0 References: <1388718532-18264-1-git-send-email-xiawenc@linux.vnet.ibm.com> <1388718532-18264-4-git-send-email-xiawenc@linux.vnet.ibm.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [Qemu-devel] [PATCH V8 3/8] util: add error_append() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Crosthwaite Cc: Kevin Wolf , Jeff Cody , "qemu-devel@nongnu.org Developers" , Stefan Hajnoczi , mreitz@redhat.com 于 2014/1/3 23:32, Peter Crosthwaite 写道: > On Fri, Jan 3, 2014 at 1:08 PM, Wenchao Xia wrote: >> Signed-off-by: Wenchao Xia >> --- >> include/qapi/error.h | 6 ++++++ >> util/error.c | 21 +++++++++++++++++++++ >> 2 files changed, 27 insertions(+), 0 deletions(-) >> >> diff --git a/include/qapi/error.h b/include/qapi/error.h >> index 7d4c696..bcfb724 100644 >> --- a/include/qapi/error.h >> +++ b/include/qapi/error.h >> @@ -30,6 +30,12 @@ typedef struct Error Error; >> void error_set(Error **err, ErrorClass err_class, const char *fmt, ...) GCC_FMT_ATTR(3, 4); >> >> /** >> + * Append message to err if err != NULL && *err != NULL. "\n" will be inserted >> + * after old message. >> + */ >> +void error_append(Error **err, const char *fmt, ...) GCC_FMT_ATTR(2, 3); >> + >> +/** >> * Set an indirect pointer to an error given a ErrorClass value and a >> * printf-style human message, followed by a strerror() string if >> * @os_error is not zero. >> diff --git a/util/error.c b/util/error.c >> index 3ee362a..64bbb2d 100644 >> --- a/util/error.c >> +++ b/util/error.c >> @@ -46,6 +46,27 @@ void error_set(Error **errp, ErrorClass err_class, const char *fmt, ...) >> errno = saved_errno; >> } >> >> +void error_append(Error **err, const char *fmt, ...) > > errp > >> +{ >> + va_list ap; >> + gchar *msg, *msg_old; >> + >> + if (!err || !*err) { > > Should appending to an unset error really be a nop? You should just > set the error as normal in this case (error_set()?). > > This avoids callers having to: > > if (error_is_set(&err)) { > error_append(&err); > } else { > error_set(&err); > } > > so they can just append if they want appending. > > Generally speaking, appending to nothing should give you something. > > Regards, > Peter > Make sense, will fix as above, thanks for review. >> + return; >> + } >> + >> + va_start(ap, fmt); >> + msg = g_strdup_vprintf(fmt, ap); >> + va_end(ap); >> + >> + msg_old = (*err)->msg; >> + (*err)->msg = g_strdup_printf("%s\n%s", msg_old, msg); >> + >> + g_free(msg); >> + g_free(msg_old); >> + >> +} >> + >> void error_set_errno(Error **errp, int os_errno, ErrorClass err_class, >> const char *fmt, ...) >> { >> -- >> 1.7.1 >> >> >