From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:47478) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QU1n3-0003TW-Tu for qemu-devel@nongnu.org; Tue, 07 Jun 2011 15:18:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QU1n1-0007ur-Uc for qemu-devel@nongnu.org; Tue, 07 Jun 2011 15:18:13 -0400 Received: from mail-yi0-f45.google.com ([209.85.218.45]:45641) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QU1n1-0007uf-KJ for qemu-devel@nongnu.org; Tue, 07 Jun 2011 15:18:11 -0400 Received: by yia27 with SMTP id 27so1365317yia.4 for ; Tue, 07 Jun 2011 12:18:10 -0700 (PDT) Message-ID: <4DEE796F.5000000@codemonkey.ws> Date: Tue, 07 Jun 2011 14:18:07 -0500 From: Anthony Liguori MIME-Version: 1.0 References: <1306948500-15086-1-git-send-email-mdroth@linux.vnet.ibm.com> <1306948500-15086-2-git-send-email-mdroth@linux.vnet.ibm.com> In-Reply-To: <1306948500-15086-2-git-send-email-mdroth@linux.vnet.ibm.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v1][ 01/14] QError: Introduce qerror_format_desc() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Michael Roth Cc: aliguori@linux.vnet.ibm.com, lcapitulino@redhat.com, agl@linux.vnet.ibm.com, qemu-devel@nongnu.org, Jes.Sorensen@redhat.com On 06/01/2011 12:14 PM, Michael Roth wrote: > From: Luiz Capitulino > > Refactor non-QError-specific bits out of qerror_human() into general > function that can be used by the error_get_pretty() analogue in the > new error-propagation framework. > > Signed-off-by: Luiz Capitulino > Signed-off-by: Michael Roth Applied series1. Thanks. Regards, Anthony Liguori > --- > qerror.c | 44 +++++++++++++++++++++++++------------------- > 1 files changed, 25 insertions(+), 19 deletions(-) > > diff --git a/qerror.c b/qerror.c > index 4855604..af6ed39 100644 > --- a/qerror.c > +++ b/qerror.c > @@ -326,12 +326,14 @@ QError *qerror_from_info(const char *file, int linenr, const char *func, > return qerr; > } > > -static void parse_error(const QError *qerror, int c) > +static void parse_error(const QErrorStringTable *entry, int c) > { > - qerror_abort(qerror, "expected '%c' in '%s'", c, qerror->entry->desc); > + fprintf(stderr, "expected '%c' in '%s'", c, entry->desc); > + abort(); > } > > -static const char *append_field(QString *outstr, const QError *qerror, > +static const char *append_field(QDict *error, QString *outstr, > + const QErrorStringTable *entry, > const char *start) > { > QObject *obj; > @@ -340,23 +342,23 @@ static const char *append_field(QString *outstr, const QError *qerror, > const char *end, *key; > > if (*start != '%') > - parse_error(qerror, '%'); > + parse_error(entry, '%'); > start++; > if (*start != '(') > - parse_error(qerror, '('); > + parse_error(entry, '('); > start++; > > end = strchr(start, ')'); > if (!end) > - parse_error(qerror, ')'); > + parse_error(entry, ')'); > > key_qs = qstring_from_substr(start, 0, end - start - 1); > key = qstring_get_str(key_qs); > > - qdict = qobject_to_qdict(qdict_get(qerror->error, "data")); > + qdict = qobject_to_qdict(qdict_get(error, "data")); > obj = qdict_get(qdict, key); > if (!obj) { > - qerror_abort(qerror, "key '%s' not found in QDict", key); > + abort(); > } > > switch (qobject_type(obj)) { > @@ -367,35 +369,31 @@ static const char *append_field(QString *outstr, const QError *qerror, > qstring_append_int(outstr, qdict_get_int(qdict, key)); > break; > default: > - qerror_abort(qerror, "invalid type '%c'", qobject_type(obj)); > + abort(); > } > > QDECREF(key_qs); > return ++end; > } > > -/** > - * qerror_human(): Format QError data into human-readable string. > - * > - * Formats according to member 'desc' of the specified QError object. > - */ > -QString *qerror_human(const QError *qerror) > +static QString *qerror_format_desc(QDict *error, > + const QErrorStringTable *entry) > { > - const char *p; > QString *qstring; > + const char *p; > > - assert(qerror->entry != NULL); > + assert(entry != NULL); > > qstring = qstring_new(); > > - for (p = qerror->entry->desc; *p != '\0';) { > + for (p = entry->desc; *p != '\0';) { > if (*p != '%') { > qstring_append_chr(qstring, *p++); > } else if (*(p + 1) == '%') { > qstring_append_chr(qstring, '%'); > p += 2; > } else { > - p = append_field(qstring, qerror, p); > + p = append_field(error, qstring, entry, p); > } > } > > @@ -403,6 +401,14 @@ QString *qerror_human(const QError *qerror) > } > > /** > + * qerror_human(): Format QError data into human-readable string. > + */ > +QString *qerror_human(const QError *qerror) > +{ > + return qerror_format_desc(qerror->error, qerror->entry); > +} > + > +/** > * qerror_print(): Print QError data > * > * This function will print the member 'desc' of the specified QError object,