From: Paolo Bonzini <pbonzini@redhat.com>
To: marcandre.lureau@redhat.com, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 1/2] utils: rename strtosz to use qemu prefix
Date: Wed, 16 Sep 2015 18:34:38 +0200 [thread overview]
Message-ID: <55F99A1E.2010401@redhat.com> (raw)
In-Reply-To: <1442419377-9309-1-git-send-email-marcandre.lureau@redhat.com>
On 16/09/2015 18:02, marcandre.lureau@redhat.com wrote:
> From: Marc-André Lureau <marcandre.lureau@redhat.com>
>
> Not only it makes sense, but it gets rid of checkpatch warning:
> WARNING: consider using qemu_strtosz in preference to strtosz
Oops. :)
However, we also need something like this:
----------- 8< ------------
From: Paolo Bonzini <pbonzini@redhat.com>
Subject: [PATCH] checkpatch: do not recomment qemu_strtok
If anything, it should recommend strtok_r!
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index b59a87a..272eef1 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2474,7 +2474,7 @@ sub process {
WARN("__func__ should be used instead of gcc specific __FUNCTION__\n" . $herecurr);
}
-# recommend qemu_strto* over strto*
- if ($line =~ /\b(strto.*?)\s*\(/) {
+# recommend qemu_strto* over strto* for numeric conversions
+ if ($line =~ /\b(strto[^k].*?)\s*\(/) {
WARN("consider using qemu_$1 in preference to $1\n" . $herecurr);
}
# check for module_init(), use category-specific init macros explicitly please
------------- 8< ----------------
Paolo
> Also remove get rid of tabs to please checkpatch.
>
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
> include/qemu-common.h | 27 ++++++++++++++-------------
> monitor.c | 2 +-
> qapi/opts-visitor.c | 4 ++--
> qemu-img.c | 5 +++--
> qemu-io-cmds.c | 2 +-
> target-i386/cpu.c | 4 ++--
> util/cutils.c | 25 +++++++++++++------------
> 7 files changed, 36 insertions(+), 33 deletions(-)
>
> diff --git a/include/qemu-common.h b/include/qemu-common.h
> index 01d29dd..0bd212b 100644
> --- a/include/qemu-common.h
> +++ b/include/qemu-common.h
> @@ -217,22 +217,23 @@ int parse_uint(const char *s, unsigned long long *value, char **endptr,
> int parse_uint_full(const char *s, unsigned long long *value, int base);
>
> /*
> - * strtosz() suffixes used to specify the default treatment of an
> - * argument passed to strtosz() without an explicit suffix.
> + * qemu_strtosz() suffixes used to specify the default treatment of an
> + * argument passed to qemu_strtosz() without an explicit suffix.
> * These should be defined using upper case characters in the range
> - * A-Z, as strtosz() will use qemu_toupper() on the given argument
> + * A-Z, as qemu_strtosz() will use qemu_toupper() on the given argument
> * prior to comparison.
> */
> -#define STRTOSZ_DEFSUFFIX_EB 'E'
> -#define STRTOSZ_DEFSUFFIX_PB 'P'
> -#define STRTOSZ_DEFSUFFIX_TB 'T'
> -#define STRTOSZ_DEFSUFFIX_GB 'G'
> -#define STRTOSZ_DEFSUFFIX_MB 'M'
> -#define STRTOSZ_DEFSUFFIX_KB 'K'
> -#define STRTOSZ_DEFSUFFIX_B 'B'
> -int64_t strtosz(const char *nptr, char **end);
> -int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix);
> -int64_t strtosz_suffix_unit(const char *nptr, char **end,
> +#define QEMU_STRTOSZ_DEFSUFFIX_EB 'E'
> +#define QEMU_STRTOSZ_DEFSUFFIX_PB 'P'
> +#define QEMU_STRTOSZ_DEFSUFFIX_TB 'T'
> +#define QEMU_STRTOSZ_DEFSUFFIX_GB 'G'
> +#define QEMU_STRTOSZ_DEFSUFFIX_MB 'M'
> +#define QEMU_STRTOSZ_DEFSUFFIX_KB 'K'
> +#define QEMU_STRTOSZ_DEFSUFFIX_B 'B'
> +int64_t qemu_strtosz(const char *nptr, char **end);
> +int64_t qemu_strtosz_suffix(const char *nptr, char **end,
> + const char default_suffix);
> +int64_t qemu_strtosz_suffix_unit(const char *nptr, char **end,
> const char default_suffix, int64_t unit);
> #define K_BYTE (1ULL << 10)
> #define M_BYTE (1ULL << 20)
> diff --git a/monitor.c b/monitor.c
> index 5455ab9..1221977 100644
> --- a/monitor.c
> +++ b/monitor.c
> @@ -3911,7 +3911,7 @@ static QDict *monitor_parse_arguments(Monitor *mon,
> break;
> }
> }
> - val = strtosz(p, &end);
> + val = qemu_strtosz(p, &end);
> if (val < 0) {
> monitor_printf(mon, "invalid size\n");
> goto fail;
> diff --git a/qapi/opts-visitor.c b/qapi/opts-visitor.c
> index 7ae33b3..cd10392 100644
> --- a/qapi/opts-visitor.c
> +++ b/qapi/opts-visitor.c
> @@ -474,8 +474,8 @@ opts_type_size(Visitor *v, uint64_t *obj, const char *name, Error **errp)
> return;
> }
>
> - val = strtosz_suffix(opt->str ? opt->str : "", &endptr,
> - STRTOSZ_DEFSUFFIX_B);
> + val = qemu_strtosz_suffix(opt->str ? opt->str : "", &endptr,
> + QEMU_STRTOSZ_DEFSUFFIX_B);
> if (val < 0 || *endptr) {
> error_setg(errp, QERR_INVALID_PARAMETER_VALUE, opt->name,
> "a size value representible as a non-negative int64");
> diff --git a/qemu-img.c b/qemu-img.c
> index 6ff4e85..7d65c0a 100644
> --- a/qemu-img.c
> +++ b/qemu-img.c
> @@ -338,7 +338,8 @@ static int img_create(int argc, char **argv)
> if (optind < argc) {
> int64_t sval;
> char *end;
> - sval = strtosz_suffix(argv[optind++], &end, STRTOSZ_DEFSUFFIX_B);
> + sval = qemu_strtosz_suffix(argv[optind++], &end,
> + QEMU_STRTOSZ_DEFSUFFIX_B);
> if (sval < 0 || *end) {
> if (sval == -ERANGE) {
> error_report("Image size must be less than 8 EiB!");
> @@ -1607,7 +1608,7 @@ static int img_convert(int argc, char **argv)
> {
> int64_t sval;
> char *end;
> - sval = strtosz_suffix(optarg, &end, STRTOSZ_DEFSUFFIX_B);
> + sval = qemu_strtosz_suffix(optarg, &end, QEMU_STRTOSZ_DEFSUFFIX_B);
> if (sval < 0 || *end) {
> error_report("Invalid minimum zero buffer size for sparse output specified");
> ret = -1;
> diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
> index d6572a8..6e5d1e4 100644
> --- a/qemu-io-cmds.c
> +++ b/qemu-io-cmds.c
> @@ -136,7 +136,7 @@ static char **breakline(char *input, int *count)
> static int64_t cvtnum(const char *s)
> {
> char *end;
> - return strtosz_suffix(s, &end, STRTOSZ_DEFSUFFIX_B);
> + return qemu_strtosz_suffix(s, &end, QEMU_STRTOSZ_DEFSUFFIX_B);
> }
>
> #define EXABYTES(x) ((long long)(x) << 60)
> diff --git a/target-i386/cpu.c b/target-i386/cpu.c
> index cfb8aa7..a5bea42 100644
> --- a/target-i386/cpu.c
> +++ b/target-i386/cpu.c
> @@ -1893,8 +1893,8 @@ static void x86_cpu_parse_featurestr(CPUState *cs, char *features,
> char *err;
> char num[32];
>
> - tsc_freq = strtosz_suffix_unit(val, &err,
> - STRTOSZ_DEFSUFFIX_B, 1000);
> + tsc_freq = qemu_strtosz_suffix_unit(val, &err,
> + QEMU_STRTOSZ_DEFSUFFIX_B, 1000);
> if (tsc_freq < 0 || *err) {
> error_setg(errp, "bad numerical value %s", val);
> return;
> diff --git a/util/cutils.c b/util/cutils.c
> index ae35198..cfeb848 100644
> --- a/util/cutils.c
> +++ b/util/cutils.c
> @@ -276,19 +276,19 @@ int fcntl_setfl(int fd, int flag)
> static int64_t suffix_mul(char suffix, int64_t unit)
> {
> switch (qemu_toupper(suffix)) {
> - case STRTOSZ_DEFSUFFIX_B:
> + case QEMU_STRTOSZ_DEFSUFFIX_B:
> return 1;
> - case STRTOSZ_DEFSUFFIX_KB:
> + case QEMU_STRTOSZ_DEFSUFFIX_KB:
> return unit;
> - case STRTOSZ_DEFSUFFIX_MB:
> + case QEMU_STRTOSZ_DEFSUFFIX_MB:
> return unit * unit;
> - case STRTOSZ_DEFSUFFIX_GB:
> + case QEMU_STRTOSZ_DEFSUFFIX_GB:
> return unit * unit * unit;
> - case STRTOSZ_DEFSUFFIX_TB:
> + case QEMU_STRTOSZ_DEFSUFFIX_TB:
> return unit * unit * unit * unit;
> - case STRTOSZ_DEFSUFFIX_PB:
> + case QEMU_STRTOSZ_DEFSUFFIX_PB:
> return unit * unit * unit * unit * unit;
> - case STRTOSZ_DEFSUFFIX_EB:
> + case QEMU_STRTOSZ_DEFSUFFIX_EB:
> return unit * unit * unit * unit * unit * unit;
> }
> return -1;
> @@ -300,7 +300,7 @@ static int64_t suffix_mul(char suffix, int64_t unit)
> * in *end, if not NULL. Return -ERANGE on overflow, Return -EINVAL on
> * other error.
> */
> -int64_t strtosz_suffix_unit(const char *nptr, char **end,
> +int64_t qemu_strtosz_suffix_unit(const char *nptr, char **end,
> const char default_suffix, int64_t unit)
> {
> int64_t retval = -EINVAL;
> @@ -343,14 +343,15 @@ fail:
> return retval;
> }
>
> -int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix)
> +int64_t qemu_strtosz_suffix(const char *nptr, char **end,
> + const char default_suffix)
> {
> - return strtosz_suffix_unit(nptr, end, default_suffix, 1024);
> + return qemu_strtosz_suffix_unit(nptr, end, default_suffix, 1024);
> }
>
> -int64_t strtosz(const char *nptr, char **end)
> +int64_t qemu_strtosz(const char *nptr, char **end)
> {
> - return strtosz_suffix(nptr, end, STRTOSZ_DEFSUFFIX_MB);
> + return qemu_strtosz_suffix(nptr, end, QEMU_STRTOSZ_DEFSUFFIX_MB);
> }
>
> /**
>
prev parent reply other threads:[~2015-09-16 16:34 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-16 16:02 [Qemu-devel] [PATCH 1/2] utils: rename strtosz to use qemu prefix marcandre.lureau
2015-09-16 16:02 ` [Qemu-devel] [PATCH 2/2] tests: add some qemu_strtosz() tests marcandre.lureau
2015-09-16 16:19 ` Eric Blake
2015-09-16 16:13 ` [Qemu-devel] [PATCH 1/2] utils: rename strtosz to use qemu prefix Eric Blake
2015-09-16 16:17 ` Marc-André Lureau
2015-09-16 16:34 ` Paolo Bonzini [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=55F99A1E.2010401@redhat.com \
--to=pbonzini@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.