From patchwork Tue Jun 5 17:24:56 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 163132 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 4582AB6FA2 for ; Wed, 6 Jun 2012 04:27:34 +1000 (EST) Received: from localhost ([::1]:47308 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SbyTb-0000ba-Uv for incoming@patchwork.ozlabs.org; Tue, 05 Jun 2012 14:27:31 -0400 Received: from eggs.gnu.org ([208.118.235.92]:54443) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SbxVu-0003Gp-8I for qemu-devel@nongnu.org; Tue, 05 Jun 2012 13:25:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SbxVs-0001C2-IW for qemu-devel@nongnu.org; Tue, 05 Jun 2012 13:25:49 -0400 Received: from mx1.redhat.com ([209.132.183.28]:63367) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SbxVs-0001Bv-8L for qemu-devel@nongnu.org; Tue, 05 Jun 2012 13:25:48 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q55HPknm018712 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 5 Jun 2012 13:25:46 -0400 Received: from localhost (ovpn-116-79.ams2.redhat.com [10.36.116.79]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q55HPiBV017773; Tue, 5 Jun 2012 13:25:46 -0400 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Tue, 5 Jun 2012 14:24:56 -0300 Message-Id: <1338917108-3965-18-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1338917108-3965-1-git-send-email-lcapitulino@redhat.com> References: <1338917108-3965-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: aliguori@us.ibm.com Subject: [Qemu-devel] [PATCH 17/29] 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 Reviewed-By: Laszlo Ersek --- 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; } }