From patchwork Thu May 17 14:33:27 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 159913 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 3B3BAB6FC3 for ; Fri, 18 May 2012 00:34:37 +1000 (EST) Received: from localhost ([::1]:58446 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SV1ml-0008LL-3z for incoming@patchwork.ozlabs.org; Thu, 17 May 2012 10:34:35 -0400 Received: from eggs.gnu.org ([208.118.235.92]:48337) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SV1mO-0007nN-G6 for qemu-devel@nongnu.org; Thu, 17 May 2012 10:34:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SV1mH-0001q7-Pq for qemu-devel@nongnu.org; Thu, 17 May 2012 10:34:12 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36779) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SV1mH-0001pV-Fp for qemu-devel@nongnu.org; Thu, 17 May 2012 10:34:05 -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 q4HEY2Tr028596 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 17 May 2012 10:34:02 -0400 Received: from localhost (ovpn-116-52.ams2.redhat.com [10.36.116.52]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q4HEY0Ng021767; Thu, 17 May 2012 10:34:01 -0400 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Thu, 17 May 2012 11:33:27 -0300 Message-Id: <1337265221-7136-3-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1337265221-7136-1-git-send-email-lcapitulino@redhat.com> References: <1337265221-7136-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 02/16] qemu-option: parse_option_number(): 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 Note that qemu_opt_parse() callers still expect automatic error reporting with QError, so qemu_opts_parse() calls qerror_report_err() to keep the same semantics. Signed-off-by: Luiz Capitulino --- qemu-option.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/qemu-option.c b/qemu-option.c index 9f531c8..72dcb56 100644 --- a/qemu-option.c +++ b/qemu-option.c @@ -186,7 +186,8 @@ static int parse_option_bool(const char *name, const char *value, bool *ret) return 0; } -static int parse_option_number(const char *name, const char *value, uint64_t *ret) +static void parse_option_number(const char *name, const char *value, + uint64_t *ret, Error **errp) { char *postfix; uint64_t number; @@ -194,15 +195,13 @@ static int parse_option_number(const char *name, const char *value, uint64_t *re if (value != NULL) { number = strtoull(value, &postfix, 0); if (*postfix != '\0') { - qerror_report(QERR_INVALID_PARAMETER_VALUE, name, "a number"); - return -1; + error_set(errp, QERR_INVALID_PARAMETER_VALUE, name, "a number"); + return; } *ret = number; } else { - qerror_report(QERR_INVALID_PARAMETER_VALUE, name, "a number"); - return -1; + error_set(errp, QERR_INVALID_PARAMETER_VALUE, name, "a number"); } - return 0; } static int parse_option_size(const char *name, const char *value, uint64_t *ret) @@ -579,8 +578,11 @@ uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t defval) static int qemu_opt_parse(QemuOpt *opt) { + Error *local_err = NULL; + if (opt->desc == NULL) return 0; + switch (opt->desc->type) { case QEMU_OPT_STRING: /* nothing */ @@ -588,12 +590,22 @@ static int qemu_opt_parse(QemuOpt *opt) case QEMU_OPT_BOOL: return parse_option_bool(opt->name, opt->str, &opt->value.boolean); case QEMU_OPT_NUMBER: - return parse_option_number(opt->name, opt->str, &opt->value.uint); + parse_option_number(opt->name, opt->str, &opt->value.uint, + &local_err); + break; case QEMU_OPT_SIZE: return parse_option_size(opt->name, opt->str, &opt->value.uint); 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)