From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:48380) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TA7Kz-0003St-2Y for qemu-devel@nongnu.org; Fri, 07 Sep 2012 18:47:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TA7Kx-0003BK-FK for qemu-devel@nongnu.org; Fri, 07 Sep 2012 18:47:45 -0400 Received: from mx1.redhat.com ([209.132.183.28]:63191) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TA7Kx-0003BG-5l for qemu-devel@nongnu.org; Fri, 07 Sep 2012 18:47:43 -0400 Date: Sat, 8 Sep 2012 00:47:30 +0200 From: Igor Mammedov Message-ID: <20120908004730.3536350f@thinkpad.mammed.net> In-Reply-To: <504A7130.4050906@CloudSwitch.Com> References: <1347051311-16122-1-git-send-email-imammedo@redhat.com> <1347051311-16122-14-git-send-email-imammedo@redhat.com> <504A7130.4050906@CloudSwitch.Com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH 13/22] add visitor for parsing hz[KMG] input string List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Don Slutz Cc: peter.maydell@linaro.org, aliguori@us.ibm.com, stefanha@linux.vnet.ibm.com, jan.kiszka@siemens.com, mdroth@linux.vnet.ibm.com, qemu-devel@nongnu.org, blauwirbel@gmail.com, don.slutz@gmail.com, avi@redhat.com, pbonzini@redhat.com, lersek@redhat.com, afaerber@suse.de, ehabkost@redhat.com On Fri, 7 Sep 2012 18:12:00 -0400 Don Slutz wrote: > On 09/07/12 16:55, Igor Mammedov wrote: > > Signed-off-by: Igor Mammedov > > Acked-by: Andreas F=E4rber > > -- > > v2: > > * replaced _hz suffix for frequency visitor by _freq suffix > > suggested-by: Andreas F=E4rber > > * fixed typo & extra space spotted-by: Andreas F=E4rber > > --- > > qapi/qapi-visit-core.c | 11 +++++++++++ > > qapi/qapi-visit-core.h | 2 ++ > > qapi/string-input-visitor.c | 22 ++++++++++++++++++++++ > > 3 files changed, 35 insertions(+) > > > > diff --git a/qapi/qapi-visit-core.c b/qapi/qapi-visit-core.c > > index 7a82b63..5c8705e 100644 > > --- a/qapi/qapi-visit-core.c > > +++ b/qapi/qapi-visit-core.c > > @@ -311,3 +311,14 @@ void input_type_enum(Visitor *v, int *obj, const c= har *strings[], > > g_free(enum_str); > > *obj =3D value; > > } > > + > > +void visit_type_freq(Visitor *v, int64_t *obj, const char *name, Error= **errp) > > +{ > > + if (!error_is_set(errp)) { > > + if (v->type_freq) { > > + v->type_freq(v, obj, name, errp); > > + } else { > > + v->type_int(v, obj, name, errp); > > + } > > + } > > +} > > diff --git a/qapi/qapi-visit-core.h b/qapi/qapi-visit-core.h > > index 60aceda..e5e7dd7 100644 > > --- a/qapi/qapi-visit-core.h > > +++ b/qapi/qapi-visit-core.h > > @@ -62,6 +62,7 @@ struct Visitor > > void (*type_int64)(Visitor *v, int64_t *obj, const char *name, Er= ror **errp); > > /* visit_type_size() falls back to (*type_uint64)() if type_size = is unset */ > > void (*type_size)(Visitor *v, uint64_t *obj, const char *name, Er= ror **errp); > > + void (*type_freq)(Visitor *v, int64_t *obj, const char *name, Erro= r **errp); > > }; > > =20 > > void visit_start_handle(Visitor *v, void **obj, const char *kind, > > @@ -91,5 +92,6 @@ void visit_type_size(Visitor *v, uint64_t *obj, const= char *name, Error **errp); > > void visit_type_bool(Visitor *v, bool *obj, const char *name, Error *= *errp); > > void visit_type_str(Visitor *v, char **obj, const char *name, Error *= *errp); > > void visit_type_number(Visitor *v, double *obj, const char *name, Err= or **errp); > > +void visit_type_freq(Visitor *v, int64_t *obj, const char *name, Error= **errp); > > =20 > > #endif > > diff --git a/qapi/string-input-visitor.c b/qapi/string-input-visitor.c > > index 497eb9a..47d2a84 100644 > > --- a/qapi/string-input-visitor.c > > +++ b/qapi/string-input-visitor.c > > @@ -110,6 +110,27 @@ static void parse_start_optional(Visitor *v, bool = *present, > > *present =3D true; > > } > > =20 > > +static void parse_type_freq(Visitor *v, int64_t *obj, const char *name, > > + Error **errp) > > +{ > > + StringInputVisitor *siv =3D DO_UPCAST(StringInputVisitor, visitor,= v); > > + char *endp =3D (char *) siv->string; > > + long long val; > I get: >=20 > cc1: warnings being treated as errors > qapi/string-input-visitor.c: In function 'parse_type_freq': > qapi/string-input-visitor.c:118: error: 'val' may be used uninitialized=20 > in this function > make: *** [qapi/string-input-visitor.o] Error 1 > make: *** Waiting for unfinished jobs.... FC17 with default configure settings doesn't complain. And I really do not see how it could be. > Which the change: >=20 >=20 > diff --git a/qapi/string-input-visitor.c b/qapi/string-input-visitor.c > index 47d2a84..74fe395 100644 > --- a/qapi/string-input-visitor.c > +++ b/qapi/string-input-visitor.c > @@ -115,7 +115,7 @@ static void parse_type_freq(Visitor *v, int64_t=20 > *obj, const char *name, > { > StringInputVisitor *siv =3D DO_UPCAST(StringInputVisitor, visitor, = v); > char *endp =3D (char *) siv->string; > - long long val; > + long long val =3D 0; > errno =3D 0; > if (siv->string) { >=20 > Fixes it for me. >=20 > > + > > + errno =3D 0; > > + if (siv->string) { > > + val =3D strtosz_suffix_unit(siv->string, &endp, > > + STRTOSZ_DEFSUFFIX_B, 1000); > > + } > > + if (!siv->string || val =3D=3D -1 || *endp) { > > + error_set(errp, QERR_INVALID_PARAMETER_VALUE, name, > > + "a value representable as a non-negative int64"); > > + return; > > + } > > + > > + *obj =3D val; > > +} > > + > > Visitor *string_input_get_visitor(StringInputVisitor *v) > > { > > return &v->visitor; > > @@ -132,6 +153,7 @@ StringInputVisitor *string_input_visitor_new(const = char *str) > > v->visitor.type_str =3D parse_type_str; > > v->visitor.type_number =3D parse_type_number; > > v->visitor.start_optional =3D parse_start_optional; > > + v->visitor.type_freq =3D parse_type_freq; > > =20 > > v->string =3D str; > > return v; > -Don Slutz --=20 Regards, Igor