Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NXyVW-00069D-9C for qemu-devel@nongnu.org; Thu, 21 Jan 2010 09:59:38 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NXyVQ-00063c-Uo for qemu-devel@nongnu.org; Thu, 21 Jan 2010 09:59:37 -0500 Received: from [199.232.76.173] (port=37177 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NXyVQ-00063Q-PK for qemu-devel@nongnu.org; Thu, 21 Jan 2010 09:59:32 -0500 Received: from mx1.redhat.com ([209.132.183.28]:24865) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NXyVQ-0004XT-6p for qemu-devel@nongnu.org; Thu, 21 Jan 2010 09:59:32 -0500 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o0LExUFG029112 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 21 Jan 2010 09:59:30 -0500 From: Markus Armbruster Subject: Re: [Qemu-devel] [PATCH v2 3/8] monitor: New argument type 'b' References: <1264003702-17329-1-git-send-email-armbru@redhat.com> <1264003702-17329-4-git-send-email-armbru@redhat.com> <20100121111703.50562cb2@doriath> <20100121122843.7a9f1005@doriath> Date: Thu, 21 Jan 2010 15:59:27 +0100 In-Reply-To: <20100121122843.7a9f1005@doriath> (Luiz Capitulino's message of "Thu, 21 Jan 2010 12:28:43 -0200") Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Luiz Capitulino Cc: qemu-devel@nongnu.org Luiz Capitulino writes: > On Thu, 21 Jan 2010 15:04:43 +0100 > Markus Armbruster wrote: > >> Luiz Capitulino writes: >> >> > On Wed, 20 Jan 2010 17:08:17 +0100 >> > Markus Armbruster wrote: >> > >> >> This is a double value with optional suffixes G, g, M, m, K, k. We'll >> >> need this to get migrate_set_speed() QMP-ready. >> > >> > Nice, not only good for QMP: we're moving this kind of handling >> > from the handlers to common code, which is the right thing to do. >> > >> > The only possible issue is that, if we decide to move all this stuff >> > to json, such types will make the change complex. But that's something >> > for the future. >> > >> > Some comments follow. >> > >> >> Signed-off-by: Markus Armbruster >> >> --- >> >> monitor.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ >> >> 1 files changed, 58 insertions(+), 0 deletions(-) >> >> >> >> diff --git a/monitor.c b/monitor.c >> >> index 775fe3f..ce97e7b 100644 >> >> --- a/monitor.c >> >> +++ b/monitor.c >> >> @@ -47,6 +47,7 @@ >> >> #include "kvm.h" >> >> #include "acl.h" >> >> #include "qint.h" >> >> +#include "qfloat.h" >> >> #include "qlist.h" >> >> #include "qdict.h" >> >> #include "qbool.h" >> >> @@ -70,6 +71,10 @@ >> >> * 'l' target long (32 or 64 bit) >> >> * 'M' just like 'l', except in user mode the value is >> >> * multiplied by 2^20 (think Mebibyte) >> >> + * 'b' double >> >> + * user mode accepts an optional G, g, M, m, K, k suffix, >> >> + * which multiplies the value by 2^30 for suffixes G and >> >> + * g, 2^20 for M and m, 2^10 for K and k >> >> * '/' optional gdb-like print format (like "/10x") >> >> * >> >> * '?' optional type (for all types, except '/') >> >> @@ -3181,6 +3186,27 @@ static int get_expr(Monitor *mon, int64_t *pval, const char **pp) >> >> return 0; >> >> } >> >> >> >> +static int get_double(Monitor *mon, double *pval, const char **pp) >> >> +{ >> >> + const char *p = *pp; >> >> + char *tailp; >> > >> > Better to init to NULL? >> >> Not necessary, as strtod() sets tailp unconditionally. > > Ok. > >> >> + double d; >> >> + >> >> + errno = 0; >> >> + d = strtod(p, &tailp); >> >> + if (tailp == p) { >> >> + monitor_printf(mon, "Number expected\n"); >> >> + return -1; >> >> + } >> >> + if (errno) { >> >> + monitor_printf(mon, "Bad number (%s)\n", strerror(errno)); >> >> + return -1; >> >> + } >> > >> > Should we trust errno this way? The manpage only mentions ERANGE. >> >> Unless we want to ignore errors other than the "Number expected" caught >> above, we have to check errno. strtod() doesn't have a distinct error >> value. >> >> I'm not particular about reporting strerror(errno). > > Ok, no big deal. I just tend to do strictly what the manpages says. We might want to ignore underflow silently, and fail loudly for ininity and NaN. Opinions? [...]