From patchwork Mon May 21 17:41:48 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 160408 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 58463B6F86 for ; Tue, 22 May 2012 04:28:37 +1000 (EST) Received: from localhost ([::1]:38486 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SWXLP-0007jI-72 for incoming@patchwork.ozlabs.org; Mon, 21 May 2012 14:28:35 -0400 Received: from eggs.gnu.org ([208.118.235.92]:52156) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SWXLE-0007ZS-U0 for qemu-devel@nongnu.org; Mon, 21 May 2012 14:28:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SWXLD-0007At-5M for qemu-devel@nongnu.org; Mon, 21 May 2012 14:28:24 -0400 Received: from mx1.redhat.com ([209.132.183.28]:20971) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SWXLC-0007AR-Sm for qemu-devel@nongnu.org; Mon, 21 May 2012 14:28:23 -0400 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q4LISB3C012007 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 21 May 2012 14:28:20 -0400 Received: from localhost (ovpn-116-87.ams2.redhat.com [10.36.116.87]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q4LHfxII021225; Mon, 21 May 2012 13:42:01 -0400 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Mon, 21 May 2012 14:41:48 -0300 Message-Id: <1337622119-8416-6-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1337622119-8416-1-git-send-email-lcapitulino@redhat.com> References: <1337622119-8416-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: pbonzini@redhat.com, aliguori@us.ibm.com, lersek@redhat.com, mdroth@linux.vnet.ibm.com, armbru@redhat.com Subject: [Qemu-devel] [PATCH 05/16] qemu-option: qemu_opt_parse(): use error_set() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org The functions opt_set() and qemu_opts_validate() both call qemu_opt_parse(), but their callers expect QError semantics. Thus, both functions call qerro_report_err() to keep the expected semantics. Signed-off-by: Luiz Capitulino --- qemu-option.c | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/qemu-option.c b/qemu-option.c index 42bb685..6d36970 100644 --- a/qemu-option.c +++ b/qemu-option.c @@ -581,38 +581,27 @@ uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t defval) return opt->value.uint; } -static int qemu_opt_parse(QemuOpt *opt) +static void qemu_opt_parse(QemuOpt *opt, Error **errp) { - Error *local_err = NULL; - if (opt->desc == NULL) - return 0; + return; switch (opt->desc->type) { case QEMU_OPT_STRING: /* nothing */ - return 0; + return; case QEMU_OPT_BOOL: - parse_option_bool(opt->name, opt->str, &opt->value.boolean, &local_err); + parse_option_bool(opt->name, opt->str, &opt->value.boolean, errp); break; case QEMU_OPT_NUMBER: - parse_option_number(opt->name, opt->str, &opt->value.uint, - &local_err); + parse_option_number(opt->name, opt->str, &opt->value.uint, errp); break; case QEMU_OPT_SIZE: - parse_option_size(opt->name, opt->str, &opt->value.uint, &local_err); + parse_option_size(opt->name, opt->str, &opt->value.uint, errp); break; default: abort(); } - - if (error_is_set(&local_err)) { - qerror_report_err(local_err); - error_free(local_err); - return -1; - } - - return 0; } static void qemu_opt_del(QemuOpt *opt) @@ -628,6 +617,7 @@ static int opt_set(QemuOpts *opts, const char *name, const char *value, { QemuOpt *opt; const QemuOptDesc *desc = opts->list->desc; + Error *local_err = NULL; int i; for (i = 0; desc[i].name != NULL; i++) { @@ -658,10 +648,14 @@ static int opt_set(QemuOpts *opts, const char *name, const char *value, if (value) { opt->str = g_strdup(value); } - if (qemu_opt_parse(opt) < 0) { + qemu_opt_parse(opt, &local_err); + if (error_is_set(&local_err)) { + qerror_report_err(local_err); + error_free(local_err); qemu_opt_del(opt); return -1; } + return 0; } @@ -1050,6 +1044,7 @@ QDict *qemu_opts_to_qdict(QemuOpts *opts, QDict *qdict) int qemu_opts_validate(QemuOpts *opts, const QemuOptDesc *desc) { QemuOpt *opt; + Error *local_err = NULL; assert(opts->list->desc[0].name == NULL); @@ -1068,7 +1063,10 @@ int qemu_opts_validate(QemuOpts *opts, const QemuOptDesc *desc) opt->desc = &desc[i]; - if (qemu_opt_parse(opt) < 0) { + qemu_opt_parse(opt, &local_err); + if (error_is_set(&local_err)) { + qerror_report_err(local_err); + error_free(local_err); return -1; } }