From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:42290) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sznqh-0006xi-Hn for qemu-devel@nongnu.org; Fri, 10 Aug 2012 07:57:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Sznqf-00048b-Nu for qemu-devel@nongnu.org; Fri, 10 Aug 2012 07:57:51 -0400 Received: from cantor2.suse.de ([195.135.220.15]:35308 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sznqf-00048V-E6 for qemu-devel@nongnu.org; Fri, 10 Aug 2012 07:57:49 -0400 Message-ID: <5024F736.1080004@suse.de> Date: Fri, 10 Aug 2012 13:57:42 +0200 From: =?ISO-8859-15?Q?Andreas_F=E4rber?= MIME-Version: 1.0 References: <1344597756-2890-1-git-send-email-imammedo@redhat.com> <1344597756-2890-13-git-send-email-imammedo@redhat.com> In-Reply-To: <1344597756-2890-13-git-send-email-imammedo@redhat.com> Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [RFC 12/20] add visitor for parsing hz[KMG] input string List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Igor Mammedov Cc: aliguori@us.ibm.com, stefanha@linux.vnet.ibm.com, gleb@redhat.com, jan.kiszka@siemens.com, mtosatti@redhat.com, mdroth@linux.vnet.ibm.com, qemu-devel@nongnu.org, blauwirbel@gmail.com, avi@redhat.com, pbonzini@redhat.com, akong@redhat.com, lersek@redhat.com, ehabkost@redhat.com Am 10.08.2012 13:22, schrieb Igor Mammedov: > Signed-off-by: Igor Mammedov > --- > qapi/qapi-visit-core.c | 11 +++++++++++ > qapi/qapi-visit-core.h | 2 ++ > qapi/string-input-visitor.c | 22 ++++++++++++++++++++++ > 3 files changed, 35 insertions(+) >=20 > diff --git a/qapi/qapi-visit-core.c b/qapi/qapi-visit-core.c > index 7a82b63..322cfa6 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_hz(Visitor *v, int64_t *obj, const char *name, Error *= *errp) > +{ > + if (!error_is_set(errp)) { > + if (v->type_hz) { > + v->type_hz(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..29d3038 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, Err= or **errp); > /* visit_type_size() falls back to (*type_uint64)() if type_size i= s unset */ > void (*type_size)(Visitor *v, uint64_t *obj, const char *name, Err= or **errp); > + void (*type_hz)(Visitor *v, int64_t *obj, const char *name, Error = **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, Erro= r **errp); > +void visit_type_hz(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..32e3780 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_hz(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; > + > + 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 representible as a non-negative int64"); Thunderbird suggests "representable". > + 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_hz =3D parse_type_hz; > =20 > v->string =3D str; > return v; I would prefer to stay physically exact and do s/hz/freq/g. ;) Seems like a good idea to have a specialized visitor, didn't think of that. Quite possibly there's use cases beyond tsc_freq that we might want to switch as follow-ups. Regards, Andreas --=20 SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 N=FCrnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imend=F6rffer; HRB 16746 AG N=FCrnbe= rg