diff mbox

[6/7] cutils: Normalize qemu_strto[u]ll() signature

Message ID 1443184788-18859-7-git-send-email-afaerber@suse.de
State New
Headers show

Commit Message

Andreas Färber Sept. 25, 2015, 12:39 p.m. UTC
Instead of using int64_t for qemu_strtoll() and uiint64_t for
qemu_strtoull(), use long long and unsigned long long as their name
implies.

The only affected callers are our test cases.

This prepares for following checkpatch's recommendation of using it more,
by making it easier to switch from POSIX to QEMU versions.
Remaining difference is const-ness.

Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 include/qemu-common.h |  4 +--
 tests/test-cutils.c   | 76 +++++++++++++++++++++++++--------------------------
 util/cutils.c         |  4 +--
 3 files changed, 42 insertions(+), 42 deletions(-)

Comments

Paolo Bonzini Sept. 25, 2015, 12:42 p.m. UTC | #1
On 25/09/2015 14:39, Andreas Färber wrote:
> Instead of using int64_t for qemu_strtoll() and uiint64_t for
> qemu_strtoull(), use long long and unsigned long long as their name
> implies.
> 
> The only affected callers are our test cases.
> 
> This prepares for following checkpatch's recommendation of using it more,
> by making it easier to switch from POSIX to QEMU versions.
> Remaining difference is const-ness.

Do we actually use long long and unsigned long long anywhere?

Paolo
Andreas Färber Sept. 25, 2015, 12:44 p.m. UTC | #2
Am 25.09.2015 um 14:42 schrieb Paolo Bonzini:
> On 25/09/2015 14:39, Andreas Färber wrote:
>> Instead of using int64_t for qemu_strtoll() and uiint64_t for
>> qemu_strtoull(), use long long and unsigned long long as their name
>> implies.
>>
>> The only affected callers are our test cases.
>>
>> This prepares for following checkpatch's recommendation of using it more,
>> by making it easier to switch from POSIX to QEMU versions.
>> Remaining difference is const-ness.
> 
> Do we actually use long long and unsigned long long anywhere?

The next patch does, because checkpatch asks for it. :)

qemu_strtoull() has some special handling for Windows apparently.

Cheers,
Andreas
Paolo Bonzini Sept. 25, 2015, 12:56 p.m. UTC | #3
On 25/09/2015 14:44, Andreas Färber wrote:
> > Do we actually use long long and unsigned long long anywhere?
> 
> The next patch does, because checkpatch asks for it. :)
> 
> qemu_strtoull() has some special handling for Windows apparently.

No, I really mean the types. :) The qemu_strtoll/qemu_strtoull functions
use {,u}int64_t because they are much more used than long long and
unsigned long long.

Paolo
Andreas Färber Sept. 25, 2015, 1:27 p.m. UTC | #4
Am 25.09.2015 um 14:56 schrieb Paolo Bonzini:
> On 25/09/2015 14:44, Andreas Färber wrote:
>>> Do we actually use long long and unsigned long long anywhere?
>>
>> The next patch does, because checkpatch asks for it. :)
>>
>> qemu_strtoull() has some special handling for Windows apparently.
> 
> No, I really mean the types. :) The qemu_strtoll/qemu_strtoull functions
> use {,u}int64_t because they are much more used than long long and
> unsigned long long.

Well, my answer still stands: The next patch has code using long long.

Problem is that uint64_t foo = strtoull(...) works, while
qemu_strtoull(..., &foo) causes a pointer mismatch warning treated as
error. I could've converted those to uint64_t (assuming the type is not
needed for something else), but I rather wanted to keep changes small.

If we want functions using [u]int64_t, we should name them
...strto[u]64, not mixing C and POSIX types.

But I assumed there may be some controversy, so I intentionally put this
after the actual bug fixes and test cases, they can easily be dropped. :)

Cheers,
Andreas
Paolo Bonzini Sept. 25, 2015, 1:47 p.m. UTC | #5
On 25/09/2015 15:27, Andreas Färber wrote:
>> > 
>> > No, I really mean the types. :) The qemu_strtoll/qemu_strtoull functions
>> > use {,u}int64_t because they are much more used than long long and
>> > unsigned long long.
> Well, my answer still stands: The next patch has code using long long.
> 
> Problem is that uint64_t foo = strtoull(...) works, while
> qemu_strtoull(..., &foo) causes a pointer mismatch warning treated as
> error. I could've converted those to uint64_t (assuming the type is not
> needed for something else), but I rather wanted to keep changes small.
> 
> If we want functions using [u]int64_t, we should name them
> ...strto[u]64, not mixing C and POSIX types.

Good point.  Yes, I would prefer the function to be renamed and using
uint64_t in string-input-visitor.

Paolo

> But I assumed there may be some controversy, so I intentionally put this
> after the actual bug fixes and test cases, they can easily be dropped. :)
Eric Blake Sept. 25, 2015, 2:59 p.m. UTC | #6
On 09/25/2015 06:39 AM, Andreas Färber wrote:
> Instead of using int64_t for qemu_strtoll() and uiint64_t for

s/uiint64/uint64/

> qemu_strtoull(), use long long and unsigned long long as their name
> implies.
> 
> The only affected callers are our test cases.
> 
> This prepares for following checkpatch's recommendation of using it more,
> by making it easier to switch from POSIX to QEMU versions.
> Remaining difference is const-ness.
> 
> Signed-off-by: Andreas Färber <afaerber@suse.de>
> ---
>  include/qemu-common.h |  4 +--
>  tests/test-cutils.c   | 76 +++++++++++++++++++++++++--------------------------
>  util/cutils.c         |  4 +--
>  3 files changed, 42 insertions(+), 42 deletions(-)

I concur with Paolo's suggestion to instead rename the functions to make
it obvious that we are parsing [u]int64, since that is more likely to
match the type that the bulk of callers will already have on hand.
diff mbox

Patch

diff --git a/include/qemu-common.h b/include/qemu-common.h
index 01d29dd..2575152 100644
--- a/include/qemu-common.h
+++ b/include/qemu-common.h
@@ -208,9 +208,9 @@  int qemu_strtol(const char *nptr, const char **endptr, int base,
 int qemu_strtoul(const char *nptr, const char **endptr, int base,
                  unsigned long *result);
 int qemu_strtoll(const char *nptr, const char **endptr, int base,
-                 int64_t *result);
+                 long long *result);
 int qemu_strtoull(const char *nptr, const char **endptr, int base,
-                  uint64_t *result);
+                  unsigned long long *result);
 
 int parse_uint(const char *s, unsigned long long *value, char **endptr,
                int base);
diff --git a/tests/test-cutils.c b/tests/test-cutils.c
index 0046c61..f00150e 100644
--- a/tests/test-cutils.c
+++ b/tests/test-cutils.c
@@ -794,7 +794,7 @@  static void test_qemu_strtoll_correct(void)
     const char *str = "12345 foo";
     char f = 'X';
     const char *endptr = &f;
-    int64_t res = 999;
+    long long res = 999;
     int err;
 
     err = qemu_strtoll(str, &endptr, 0, &res);
@@ -808,7 +808,7 @@  static void test_qemu_strtoll_null(void)
 {
     char f = 'X';
     const char *endptr = &f;
-    int64_t res = 999;
+    long long res = 999;
     int err;
 
     err = qemu_strtoll(NULL, &endptr, 0, &res);
@@ -822,7 +822,7 @@  static void test_qemu_strtoll_empty(void)
     const char *str = "";
     char f = 'X';
     const char *endptr = &f;
-    int64_t res = 999;
+    long long res = 999;
     int err;
 
     err = qemu_strtoll(str, &endptr, 0, &res);
@@ -835,7 +835,7 @@  static void test_qemu_strtoll_whitespace(void)
     const char *str = "  \t  ";
     char f = 'X';
     const char *endptr = &f;
-    int64_t res = 999;
+    long long res = 999;
     int err;
 
     err = qemu_strtoll(str, &endptr, 0, &res);
@@ -848,7 +848,7 @@  static void test_qemu_strtoll_invalid(void)
     const char *str = "   xxxx  \t abc";
     char f = 'X';
     const char *endptr = &f;
-    int64_t res = 999;
+    long long res = 999;
     int err;
 
     err = qemu_strtoll(str, &endptr, 0, &res);
@@ -861,7 +861,7 @@  static void test_qemu_strtoll_trailing(void)
     const char *str = "123xxx";
     char f = 'X';
     const char *endptr = &f;
-    int64_t res = 999;
+    long long res = 999;
     int err;
 
     err = qemu_strtoll(str, &endptr, 0, &res);
@@ -876,7 +876,7 @@  static void test_qemu_strtoll_octal(void)
     const char *str = "0123";
     char f = 'X';
     const char *endptr = &f;
-    int64_t res = 999;
+    long long res = 999;
     int err;
 
     err = qemu_strtoll(str, &endptr, 8, &res);
@@ -899,7 +899,7 @@  static void test_qemu_strtoll_decimal(void)
     const char *str = "0123";
     char f = 'X';
     const char *endptr = &f;
-    int64_t res = 999;
+    long long res = 999;
     int err;
 
     err = qemu_strtoll(str, &endptr, 10, &res);
@@ -923,7 +923,7 @@  static void test_qemu_strtoll_hex(void)
     const char *str = "0123";
     char f = 'X';
     const char *endptr = &f;
-    int64_t res = 999;
+    long long res = 999;
     int err;
 
     err = qemu_strtoll(str, &endptr, 16, &res);
@@ -947,7 +947,7 @@  static void test_qemu_strtoll_max(void)
     const char *str = g_strdup_printf("%lld", LLONG_MAX);
     char f = 'X';
     const char *endptr = &f;
-    int64_t res = 999;
+    long long res = 999;
     int err;
 
     err = qemu_strtoll(str, &endptr, 0, &res);
@@ -962,7 +962,7 @@  static void test_qemu_strtoll_overflow(void)
     const char *str = "99999999999999999999999999999999999999999999";
     char f = 'X';
     const char *endptr = &f;
-    int64_t res = 999;
+    long long res = 999;
     int err;
 
     err = qemu_strtoll(str, &endptr, 0, &res);
@@ -977,7 +977,7 @@  static void test_qemu_strtoll_underflow(void)
     const char *str = "-99999999999999999999999999999999999999999999";
     char f = 'X';
     const char *endptr = &f;
-    int64_t res = 999;
+    long long res = 999;
     int err;
 
     err  = qemu_strtoll(str, &endptr, 0, &res);
@@ -992,7 +992,7 @@  static void test_qemu_strtoll_negative(void)
     const char *str = "  \t -321";
     char f = 'X';
     const char *endptr = &f;
-    int64_t res = 999;
+    long long res = 999;
     int err;
 
     err = qemu_strtoll(str, &endptr, 0, &res);
@@ -1005,7 +1005,7 @@  static void test_qemu_strtoll_negative(void)
 static void test_qemu_strtoll_full_correct(void)
 {
     const char *str = "123";
-    int64_t res = 999;
+    long long res = 999;
     int err;
 
     err = qemu_strtoll(str, NULL, 0, &res);
@@ -1016,7 +1016,7 @@  static void test_qemu_strtoll_full_correct(void)
 
 static void test_qemu_strtoll_full_null(void)
 {
-    int64_t res = 999;
+    long long res = 999;
     int err;
 
     err = qemu_strtoll(NULL, NULL, 0, &res);
@@ -1027,7 +1027,7 @@  static void test_qemu_strtoll_full_null(void)
 static void test_qemu_strtoll_full_empty(void)
 {
     const char *str = "";
-    int64_t res = 999;
+    long long res = 999;
     int err;
 
     err = qemu_strtoll(str, NULL, 0, &res);
@@ -1038,7 +1038,7 @@  static void test_qemu_strtoll_full_empty(void)
 static void test_qemu_strtoll_full_negative(void)
 {
     const char *str = " \t -321";
-    int64_t res = 999;
+    long long res = 999;
     int err;
 
     err = qemu_strtoll(str, NULL, 0, &res);
@@ -1050,7 +1050,7 @@  static void test_qemu_strtoll_full_negative(void)
 static void test_qemu_strtoll_full_trailing(void)
 {
     const char *str = "123xxx";
-    int64_t res = 999;
+    long long res = 999;
     int err;
 
     err = qemu_strtoll(str, NULL, 0, &res);
@@ -1062,7 +1062,7 @@  static void test_qemu_strtoll_full_max(void)
 {
 
     const char *str = g_strdup_printf("%lld", LLONG_MAX);
-    int64_t res;
+    long long res;
     int err;
 
     err = qemu_strtoll(str, NULL, 0, &res);
@@ -1076,7 +1076,7 @@  static void test_qemu_strtoull_correct(void)
     const char *str = "12345 foo";
     char f = 'X';
     const char *endptr = &f;
-    uint64_t res = 999;
+    unsigned long long res = 999;
     int err;
 
     err = qemu_strtoull(str, &endptr, 0, &res);
@@ -1090,7 +1090,7 @@  static void test_qemu_strtoull_null(void)
 {
     char f = 'X';
     const char *endptr = &f;
-    uint64_t res = 999;
+    unsigned long long res = 999;
     int err;
 
     err = qemu_strtoull(NULL, &endptr, 0, &res);
@@ -1104,7 +1104,7 @@  static void test_qemu_strtoull_empty(void)
     const char *str = "";
     char f = 'X';
     const char *endptr = &f;
-    uint64_t res = 999;
+    unsigned long long res = 999;
     int err;
 
     err = qemu_strtoull(str, &endptr, 0, &res);
@@ -1117,7 +1117,7 @@  static void test_qemu_strtoull_whitespace(void)
     const char *str = "  \t  ";
     char f = 'X';
     const char *endptr = &f;
-    uint64_t res = 999;
+    unsigned long long res = 999;
     int err;
 
     err = qemu_strtoull(str, &endptr, 0, &res);
@@ -1130,7 +1130,7 @@  static void test_qemu_strtoull_invalid(void)
     const char *str = "   xxxx  \t abc";
     char f = 'X';
     const char *endptr = &f;
-    uint64_t res = 999;
+    unsigned long long res = 999;
     int err;
 
     err = qemu_strtoull(str, &endptr, 0, &res);
@@ -1143,7 +1143,7 @@  static void test_qemu_strtoull_trailing(void)
     const char *str = "123xxx";
     char f = 'X';
     const char *endptr = &f;
-    uint64_t res = 999;
+    unsigned long long res = 999;
     int err;
 
     err = qemu_strtoull(str, &endptr, 0, &res);
@@ -1158,7 +1158,7 @@  static void test_qemu_strtoull_octal(void)
     const char *str = "0123";
     char f = 'X';
     const char *endptr = &f;
-    uint64_t res = 999;
+    unsigned long long res = 999;
     int err;
 
     err = qemu_strtoull(str, &endptr, 8, &res);
@@ -1181,7 +1181,7 @@  static void test_qemu_strtoull_decimal(void)
     const char *str = "0123";
     char f = 'X';
     const char *endptr = &f;
-    uint64_t res = 999;
+    unsigned long long res = 999;
     int err;
 
     err = qemu_strtoull(str, &endptr, 10, &res);
@@ -1205,7 +1205,7 @@  static void test_qemu_strtoull_hex(void)
     const char *str = "0123";
     char f = 'X';
     const char *endptr = &f;
-    uint64_t res = 999;
+    unsigned long long res = 999;
     int err;
 
     err = qemu_strtoull(str, &endptr, 16, &res);
@@ -1229,7 +1229,7 @@  static void test_qemu_strtoull_max(void)
     const char *str = g_strdup_printf("%llu", ULLONG_MAX);
     char f = 'X';
     const char *endptr = &f;
-    uint64_t res = 999;
+    unsigned long long res = 999;
     int err;
 
     err = qemu_strtoull(str, &endptr, 0, &res);
@@ -1244,7 +1244,7 @@  static void test_qemu_strtoull_overflow(void)
     const char *str = "99999999999999999999999999999999999999999999";
     char f = 'X';
     const char *endptr = &f;
-    uint64_t res = 999;
+    unsigned long long res = 999;
     int err;
 
     err = qemu_strtoull(str, &endptr, 0, &res);
@@ -1259,7 +1259,7 @@  static void test_qemu_strtoull_underflow(void)
     const char *str = "-99999999999999999999999999999999999999999999";
     char f = 'X';
     const char *endptr = &f;
-    uint64_t res = 999;
+    unsigned long long res = 999;
     int err;
 
     err  = qemu_strtoull(str, &endptr, 0, &res);
@@ -1274,7 +1274,7 @@  static void test_qemu_strtoull_negative(void)
     const char *str = "  \t -321";
     char f = 'X';
     const char *endptr = &f;
-    uint64_t res = 999;
+    unsigned long long res = 999;
     int err;
 
     err = qemu_strtoull(str, &endptr, 0, &res);
@@ -1287,7 +1287,7 @@  static void test_qemu_strtoull_negative(void)
 static void test_qemu_strtoull_full_correct(void)
 {
     const char *str = "18446744073709551614";
-    uint64_t res = 999;
+    unsigned long long res = 999;
     int err;
 
     err = qemu_strtoull(str, NULL, 0, &res);
@@ -1298,7 +1298,7 @@  static void test_qemu_strtoull_full_correct(void)
 
 static void test_qemu_strtoull_full_null(void)
 {
-    uint64_t res = 999;
+    unsigned long long res = 999;
     int err;
 
     err = qemu_strtoull(NULL, NULL, 0, &res);
@@ -1309,7 +1309,7 @@  static void test_qemu_strtoull_full_null(void)
 static void test_qemu_strtoull_full_empty(void)
 {
     const char *str = "";
-    uint64_t res = 999;
+    unsigned long long res = 999;
     int err;
 
     err = qemu_strtoull(str, NULL, 0, &res);
@@ -1320,7 +1320,7 @@  static void test_qemu_strtoull_full_empty(void)
 static void test_qemu_strtoull_full_negative(void)
 {
     const char *str = " \t -321";
-    uint64_t res = 999;
+    unsigned long long res = 999;
     int err;
 
     err = qemu_strtoull(str, NULL, 0, &res);
@@ -1332,7 +1332,7 @@  static void test_qemu_strtoull_full_negative(void)
 static void test_qemu_strtoull_full_trailing(void)
 {
     const char *str = "18446744073709551614xxxxxx";
-    uint64_t res = 999;
+    unsigned long long res = 999;
     int err;
 
     err = qemu_strtoull(str, NULL, 0, &res);
@@ -1343,7 +1343,7 @@  static void test_qemu_strtoull_full_trailing(void)
 static void test_qemu_strtoull_full_max(void)
 {
     const char *str = g_strdup_printf("%lld", ULLONG_MAX);
-    uint64_t res = 999;
+    unsigned long long res = 999;
     int err;
 
     err = qemu_strtoull(str, NULL, 0, &res);
diff --git a/util/cutils.c b/util/cutils.c
index ae35198..9e865df 100644
--- a/util/cutils.c
+++ b/util/cutils.c
@@ -459,7 +459,7 @@  int qemu_strtoul(const char *nptr, const char **endptr, int base,
  * See qemu_strtol() documentation for more info.
  */
 int qemu_strtoll(const char *nptr, const char **endptr, int base,
-                 int64_t *result)
+                 long long *result)
 {
     char *p;
     int err = 0;
@@ -482,7 +482,7 @@  int qemu_strtoll(const char *nptr, const char **endptr, int base,
  * See qemu_strtol() documentation for more info.
  */
 int qemu_strtoull(const char *nptr, const char **endptr, int base,
-                  uint64_t *result)
+                  unsigned long long *result)
 {
     char *p;
     int err = 0;