All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v4 0/4] strtosz() cleanups
@ 2011-01-24 15:33 Jes.Sorensen
  2011-01-24 15:33 ` [Qemu-devel] [PATCH 1/4] strtosz(): use unsigned char and switch to qemu_isspace() Jes.Sorensen
                   ` (4 more replies)
  0 siblings, 5 replies; 22+ messages in thread
From: Jes.Sorensen @ 2011-01-24 15:33 UTC (permalink / raw)
  To: kwolf; +Cc: qemu-devel

From: Jes Sorensen <Jes.Sorensen@redhat.com>

Hi,

Here is an updated version of the strtosz() fixes that were discussed
earlier. Per discussing with Anthony on irc, he is ok with them going
in like this.

This is a respin to fix a patch conflict in the block tree, and it
pulls the two patch sets into one set of four patches instead. No
functional change.

Cheers,
Jes


Jes Sorensen (4):
  strtosz(): use unsigned char and switch to qemu_isspace()
  strtosz() use qemu_toupper() to simplify switch statement
  strtosz(): Fix name confusion in use of modf()
  strtosz(): Use suffix macros in switch() statement

 cutils.c |   28 ++++++++++++----------------
 1 files changed, 12 insertions(+), 16 deletions(-)

-- 
1.7.3.4

^ permalink raw reply	[flat|nested] 22+ messages in thread

* [Qemu-devel] [PATCH 1/4] strtosz(): use unsigned char and switch to qemu_isspace()
  2011-01-24 15:33 [Qemu-devel] [PATCH v4 0/4] strtosz() cleanups Jes.Sorensen
@ 2011-01-24 15:33 ` Jes.Sorensen
  2011-01-24 16:10   ` Markus Armbruster
  2011-01-24 15:33 ` [Qemu-devel] [PATCH 2/4] strtosz() use qemu_toupper() to simplify switch statement Jes.Sorensen
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 22+ messages in thread
From: Jes.Sorensen @ 2011-01-24 15:33 UTC (permalink / raw)
  To: kwolf; +Cc: qemu-devel

From: Jes Sorensen <Jes.Sorensen@redhat.com>

isspace() behavior is undefined for signed char.

Bug pointed out by Eric Blake, thanks!

Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
---
 cutils.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/cutils.c b/cutils.c
index 4d2e27c..a067cf4 100644
--- a/cutils.c
+++ b/cutils.c
@@ -294,7 +294,8 @@ int fcntl_setfl(int fd, int flag)
 int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix)
 {
     int64_t retval = -1;
-    char *endptr, c, d;
+    char *endptr;
+    unsigned char c, d;
     int mul_required = 0;
     double val, mul, integral, fraction;
 
@@ -314,7 +315,7 @@ int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix)
      */
     c = *endptr;
     d = c;
-    if (isspace(c) || c == '\0' || c == ',') {
+    if (qemu_isspace(c) || c == '\0' || c == ',') {
         c = 0;
         if (default_suffix) {
             d = default_suffix;
@@ -361,7 +362,7 @@ int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix)
      */
     if (c != 0) {
         endptr++;
-        if (!isspace(*endptr) && *endptr != ',' && *endptr != 0) {
+        if (!qemu_isspace(*endptr) && *endptr != ',' && *endptr != 0) {
             goto fail;
         }
     }
-- 
1.7.3.4

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [Qemu-devel] [PATCH 2/4] strtosz() use qemu_toupper() to simplify switch statement
  2011-01-24 15:33 [Qemu-devel] [PATCH v4 0/4] strtosz() cleanups Jes.Sorensen
  2011-01-24 15:33 ` [Qemu-devel] [PATCH 1/4] strtosz(): use unsigned char and switch to qemu_isspace() Jes.Sorensen
@ 2011-01-24 15:33 ` Jes.Sorensen
  2011-01-24 15:33 ` [Qemu-devel] [PATCH 3/4] strtosz(): Fix name confusion in use of modf() Jes.Sorensen
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 22+ messages in thread
From: Jes.Sorensen @ 2011-01-24 15:33 UTC (permalink / raw)
  To: kwolf; +Cc: qemu-devel

From: Jes Sorensen <Jes.Sorensen@redhat.com>

Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
---
 cutils.c |    7 +------
 1 files changed, 1 insertions(+), 6 deletions(-)

diff --git a/cutils.c b/cutils.c
index a067cf4..78d35e2 100644
--- a/cutils.c
+++ b/cutils.c
@@ -323,16 +323,14 @@ int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix)
             d = c;
         }
     }
-    switch (d) {
+    switch (qemu_toupper(d)) {
     case 'B':
-    case 'b':
         mul = 1;
         if (mul_required) {
             goto fail;
         }
         break;
     case 'K':
-    case 'k':
         mul = 1 << 10;
         break;
     case 0:
@@ -340,15 +338,12 @@ int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix)
             goto fail;
         }
     case 'M':
-    case 'm':
         mul = 1ULL << 20;
         break;
     case 'G':
-    case 'g':
         mul = 1ULL << 30;
         break;
     case 'T':
-    case 't':
         mul = 1ULL << 40;
         break;
     default:
-- 
1.7.3.4

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [Qemu-devel] [PATCH 3/4] strtosz(): Fix name confusion in use of modf()
  2011-01-24 15:33 [Qemu-devel] [PATCH v4 0/4] strtosz() cleanups Jes.Sorensen
  2011-01-24 15:33 ` [Qemu-devel] [PATCH 1/4] strtosz(): use unsigned char and switch to qemu_isspace() Jes.Sorensen
  2011-01-24 15:33 ` [Qemu-devel] [PATCH 2/4] strtosz() use qemu_toupper() to simplify switch statement Jes.Sorensen
@ 2011-01-24 15:33 ` Jes.Sorensen
  2011-01-24 15:33 ` [Qemu-devel] [PATCH 4/4] strtosz(): Use suffix macros in switch() statement Jes.Sorensen
  2011-01-24 15:45 ` [Qemu-devel] Re: [PATCH v4 0/4] strtosz() cleanups Kevin Wolf
  4 siblings, 0 replies; 22+ messages in thread
From: Jes.Sorensen @ 2011-01-24 15:33 UTC (permalink / raw)
  To: kwolf; +Cc: qemu-devel

From: Jes Sorensen <Jes.Sorensen@redhat.com>

Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
---
 cutils.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/cutils.c b/cutils.c
index 78d35e2..369a016 100644
--- a/cutils.c
+++ b/cutils.c
@@ -304,8 +304,8 @@ int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix)
     if (isnan(val) || endptr == nptr || errno != 0) {
         goto fail;
     }
-    integral = modf(val, &fraction);
-    if (integral != 0) {
+    fraction = modf(val, &integral);
+    if (fraction != 0) {
         mul_required = 1;
     }
     /*
-- 
1.7.3.4

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [Qemu-devel] [PATCH 4/4] strtosz(): Use suffix macros in switch() statement
  2011-01-24 15:33 [Qemu-devel] [PATCH v4 0/4] strtosz() cleanups Jes.Sorensen
                   ` (2 preceding siblings ...)
  2011-01-24 15:33 ` [Qemu-devel] [PATCH 3/4] strtosz(): Fix name confusion in use of modf() Jes.Sorensen
@ 2011-01-24 15:33 ` Jes.Sorensen
  2011-01-24 16:08   ` Markus Armbruster
  2011-01-24 15:45 ` [Qemu-devel] Re: [PATCH v4 0/4] strtosz() cleanups Kevin Wolf
  4 siblings, 1 reply; 22+ messages in thread
From: Jes.Sorensen @ 2011-01-24 15:33 UTC (permalink / raw)
  To: kwolf; +Cc: qemu-devel

From: Jes Sorensen <Jes.Sorensen@redhat.com>

Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
---
 cutils.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/cutils.c b/cutils.c
index 369a016..8d562b2 100644
--- a/cutils.c
+++ b/cutils.c
@@ -324,26 +324,26 @@ int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix)
         }
     }
     switch (qemu_toupper(d)) {
-    case 'B':
+    case STRTOSZ_DEFSUFFIX_B:
         mul = 1;
         if (mul_required) {
             goto fail;
         }
         break;
-    case 'K':
+    case STRTOSZ_DEFSUFFIX_KB:
         mul = 1 << 10;
         break;
     case 0:
         if (mul_required) {
             goto fail;
         }
-    case 'M':
+    case STRTOSZ_DEFSUFFIX_MB:
         mul = 1ULL << 20;
         break;
-    case 'G':
+    case STRTOSZ_DEFSUFFIX_GB:
         mul = 1ULL << 30;
         break;
-    case 'T':
+    case STRTOSZ_DEFSUFFIX_TB:
         mul = 1ULL << 40;
         break;
     default:
-- 
1.7.3.4

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [Qemu-devel] Re: [PATCH v4 0/4] strtosz() cleanups
  2011-01-24 15:33 [Qemu-devel] [PATCH v4 0/4] strtosz() cleanups Jes.Sorensen
                   ` (3 preceding siblings ...)
  2011-01-24 15:33 ` [Qemu-devel] [PATCH 4/4] strtosz(): Use suffix macros in switch() statement Jes.Sorensen
@ 2011-01-24 15:45 ` Kevin Wolf
  2011-01-24 17:28   ` Stefan Weil
  4 siblings, 1 reply; 22+ messages in thread
From: Kevin Wolf @ 2011-01-24 15:45 UTC (permalink / raw)
  To: Jes.Sorensen; +Cc: qemu-devel

Am 24.01.2011 16:33, schrieb Jes.Sorensen@redhat.com:
> From: Jes Sorensen <Jes.Sorensen@redhat.com>
> 
> Hi,
> 
> Here is an updated version of the strtosz() fixes that were discussed
> earlier. Per discussing with Anthony on irc, he is ok with them going
> in like this.
> 
> This is a respin to fix a patch conflict in the block tree, and it
> pulls the two patch sets into one set of four patches instead. No
> functional change.
> 
> Cheers,
> Jes
> 
> 
> Jes Sorensen (4):
>   strtosz(): use unsigned char and switch to qemu_isspace()
>   strtosz() use qemu_toupper() to simplify switch statement
>   strtosz(): Fix name confusion in use of modf()
>   strtosz(): Use suffix macros in switch() statement
> 
>  cutils.c |   28 ++++++++++++----------------
>  1 files changed, 12 insertions(+), 16 deletions(-)
> 

Thanks, applied all to the block branch.

Kevin

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [Qemu-devel] [PATCH 4/4] strtosz(): Use suffix macros in switch() statement
  2011-01-24 15:33 ` [Qemu-devel] [PATCH 4/4] strtosz(): Use suffix macros in switch() statement Jes.Sorensen
@ 2011-01-24 16:08   ` Markus Armbruster
  2011-01-24 16:10     ` Jes Sorensen
  0 siblings, 1 reply; 22+ messages in thread
From: Markus Armbruster @ 2011-01-24 16:08 UTC (permalink / raw)
  To: Jes.Sorensen; +Cc: kwolf, qemu-devel

Jes.Sorensen@redhat.com writes:

> From: Jes Sorensen <Jes.Sorensen@redhat.com>
>
> Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
> ---
>  cutils.c |   10 +++++-----
>  1 files changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/cutils.c b/cutils.c
> index 369a016..8d562b2 100644
> --- a/cutils.c
> +++ b/cutils.c
> @@ -324,26 +324,26 @@ int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix)
>          }
>      }
>      switch (qemu_toupper(d)) {
> -    case 'B':
> +    case STRTOSZ_DEFSUFFIX_B:
>          mul = 1;
>          if (mul_required) {
>              goto fail;
>          }
>          break;
> -    case 'K':
> +    case STRTOSZ_DEFSUFFIX_KB:
>          mul = 1 << 10;
>          break;
>      case 0:
>          if (mul_required) {
>              goto fail;
>          }
> -    case 'M':
> +    case STRTOSZ_DEFSUFFIX_MB:
>          mul = 1ULL << 20;
>          break;
> -    case 'G':
> +    case STRTOSZ_DEFSUFFIX_GB:
>          mul = 1ULL << 30;
>          break;
> -    case 'T':
> +    case STRTOSZ_DEFSUFFIX_TB:
>          mul = 1ULL << 40;
>          break;
>      default:

Phony abstraction.  And it leaks: code here assumes the
STRTOSZ_DEFSUFFIX_T* are all upper case.

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [Qemu-devel] [PATCH 4/4] strtosz(): Use suffix macros in switch() statement
  2011-01-24 16:08   ` Markus Armbruster
@ 2011-01-24 16:10     ` Jes Sorensen
  2011-01-24 16:39       ` Markus Armbruster
  0 siblings, 1 reply; 22+ messages in thread
From: Jes Sorensen @ 2011-01-24 16:10 UTC (permalink / raw)
  To: Markus Armbruster; +Cc: kwolf, qemu-devel

On 01/24/11 17:08, Markus Armbruster wrote:
> Jes.Sorensen@redhat.com writes:
> 
>> From: Jes Sorensen <Jes.Sorensen@redhat.com>
>>
>> Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
>> ---
>>  cutils.c |   10 +++++-----
>>  1 files changed, 5 insertions(+), 5 deletions(-)
>>
>> diff --git a/cutils.c b/cutils.c
>> index 369a016..8d562b2 100644
>> --- a/cutils.c
>> +++ b/cutils.c
>> @@ -324,26 +324,26 @@ int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix)
>>          }
>>      }
>>      switch (qemu_toupper(d)) {
>> -    case 'B':
>> +    case STRTOSZ_DEFSUFFIX_B:
>>          mul = 1;
>>          if (mul_required) {
>>              goto fail;
>>          }
>>          break;
>> -    case 'K':
>> +    case STRTOSZ_DEFSUFFIX_KB:
>>          mul = 1 << 10;
>>          break;
>>      case 0:
>>          if (mul_required) {
>>              goto fail;
>>          }
>> -    case 'M':
>> +    case STRTOSZ_DEFSUFFIX_MB:
>>          mul = 1ULL << 20;
>>          break;
>> -    case 'G':
>> +    case STRTOSZ_DEFSUFFIX_GB:
>>          mul = 1ULL << 30;
>>          break;
>> -    case 'T':
>> +    case STRTOSZ_DEFSUFFIX_TB:
>>          mul = 1ULL << 40;
>>          break;
>>      default:
> 
> Phony abstraction.  And it leaks: code here assumes the
> STRTOSZ_DEFSUFFIX_T* are all upper case.

qemu_toupper() - whats the problem?

Jes

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [Qemu-devel] [PATCH 1/4] strtosz(): use unsigned char and switch to qemu_isspace()
  2011-01-24 15:33 ` [Qemu-devel] [PATCH 1/4] strtosz(): use unsigned char and switch to qemu_isspace() Jes.Sorensen
@ 2011-01-24 16:10   ` Markus Armbruster
  2011-01-24 16:11     ` Jes Sorensen
  0 siblings, 1 reply; 22+ messages in thread
From: Markus Armbruster @ 2011-01-24 16:10 UTC (permalink / raw)
  To: Jes.Sorensen; +Cc: kwolf, qemu-devel

Jes.Sorensen@redhat.com writes:

> From: Jes Sorensen <Jes.Sorensen@redhat.com>
>
> isspace() behavior is undefined for signed char.
>
> Bug pointed out by Eric Blake, thanks!
>
> Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
> ---
>  cutils.c |    7 ++++---
>  1 files changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/cutils.c b/cutils.c
> index 4d2e27c..a067cf4 100644
> --- a/cutils.c
> +++ b/cutils.c
> @@ -294,7 +294,8 @@ int fcntl_setfl(int fd, int flag)
>  int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix)
>  {
>      int64_t retval = -1;
> -    char *endptr, c, d;
> +    char *endptr;
> +    unsigned char c, d;
>      int mul_required = 0;
>      double val, mul, integral, fraction;
>  

I doubt this hunk is still needed.

> @@ -314,7 +315,7 @@ int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix)
>       */
>      c = *endptr;
>      d = c;
> -    if (isspace(c) || c == '\0' || c == ',') {
> +    if (qemu_isspace(c) || c == '\0' || c == ',') {
>          c = 0;
>          if (default_suffix) {
>              d = default_suffix;
> @@ -361,7 +362,7 @@ int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix)
>       */
>      if (c != 0) {
>          endptr++;
> -        if (!isspace(*endptr) && *endptr != ',' && *endptr != 0) {
> +        if (!qemu_isspace(*endptr) && *endptr != ',' && *endptr != 0) {
>              goto fail;
>          }
>      }

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [Qemu-devel] [PATCH 1/4] strtosz(): use unsigned char and switch to qemu_isspace()
  2011-01-24 16:10   ` Markus Armbruster
@ 2011-01-24 16:11     ` Jes Sorensen
  2011-01-24 16:40       ` Markus Armbruster
  0 siblings, 1 reply; 22+ messages in thread
From: Jes Sorensen @ 2011-01-24 16:11 UTC (permalink / raw)
  To: Markus Armbruster; +Cc: kwolf, qemu-devel

On 01/24/11 17:10, Markus Armbruster wrote:
> Jes.Sorensen@redhat.com writes:
> 
>> From: Jes Sorensen <Jes.Sorensen@redhat.com>
>>
>> isspace() behavior is undefined for signed char.
>>
>> Bug pointed out by Eric Blake, thanks!
>>
>> Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
>> ---
>>  cutils.c |    7 ++++---
>>  1 files changed, 4 insertions(+), 3 deletions(-)
>>
>> diff --git a/cutils.c b/cutils.c
>> index 4d2e27c..a067cf4 100644
>> --- a/cutils.c
>> +++ b/cutils.c
>> @@ -294,7 +294,8 @@ int fcntl_setfl(int fd, int flag)
>>  int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix)
>>  {
>>      int64_t retval = -1;
>> -    char *endptr, c, d;
>> +    char *endptr;
>> +    unsigned char c, d;
>>      int mul_required = 0;
>>      double val, mul, integral, fraction;
>>  
> 
> I doubt this hunk is still needed.

It isn't strictly due to qemu_toupper() but it is prettier to match the
real behavior of pure toupper() anyway.

Jes

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [Qemu-devel] [PATCH 4/4] strtosz(): Use suffix macros in switch() statement
  2011-01-24 16:10     ` Jes Sorensen
@ 2011-01-24 16:39       ` Markus Armbruster
  2011-01-24 16:41         ` Jes Sorensen
  0 siblings, 1 reply; 22+ messages in thread
From: Markus Armbruster @ 2011-01-24 16:39 UTC (permalink / raw)
  To: Jes Sorensen; +Cc: kwolf, qemu-devel

Jes Sorensen <Jes.Sorensen@redhat.com> writes:

> On 01/24/11 17:08, Markus Armbruster wrote:
>> Jes.Sorensen@redhat.com writes:
>> 
>>> From: Jes Sorensen <Jes.Sorensen@redhat.com>
>>>
>>> Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
>>> ---
>>>  cutils.c |   10 +++++-----
>>>  1 files changed, 5 insertions(+), 5 deletions(-)
>>>
>>> diff --git a/cutils.c b/cutils.c
>>> index 369a016..8d562b2 100644
>>> --- a/cutils.c
>>> +++ b/cutils.c
>>> @@ -324,26 +324,26 @@ int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix)
>>>          }
>>>      }
>>>      switch (qemu_toupper(d)) {
>>> -    case 'B':
>>> +    case STRTOSZ_DEFSUFFIX_B:
>>>          mul = 1;
>>>          if (mul_required) {
>>>              goto fail;
>>>          }
>>>          break;
>>> -    case 'K':
>>> +    case STRTOSZ_DEFSUFFIX_KB:
>>>          mul = 1 << 10;
>>>          break;
>>>      case 0:
>>>          if (mul_required) {
>>>              goto fail;
>>>          }
>>> -    case 'M':
>>> +    case STRTOSZ_DEFSUFFIX_MB:
>>>          mul = 1ULL << 20;
>>>          break;
>>> -    case 'G':
>>> +    case STRTOSZ_DEFSUFFIX_GB:
>>>          mul = 1ULL << 30;
>>>          break;
>>> -    case 'T':
>>> +    case STRTOSZ_DEFSUFFIX_TB:
>>>          mul = 1ULL << 40;
>>>          break;
>>>      default:
>> 
>> Phony abstraction.  And it leaks: code here assumes the
>> STRTOSZ_DEFSUFFIX_T* are all upper case.
>
> qemu_toupper() - whats the problem?

If a STRTOSZ_DEFSUFFIX_T? expands to a lower case character, its case
will not match any input.

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [Qemu-devel] [PATCH 1/4] strtosz(): use unsigned char and switch to qemu_isspace()
  2011-01-24 16:11     ` Jes Sorensen
@ 2011-01-24 16:40       ` Markus Armbruster
  0 siblings, 0 replies; 22+ messages in thread
From: Markus Armbruster @ 2011-01-24 16:40 UTC (permalink / raw)
  To: Jes Sorensen; +Cc: kwolf, qemu-devel

Jes Sorensen <Jes.Sorensen@redhat.com> writes:

> On 01/24/11 17:10, Markus Armbruster wrote:
>> Jes.Sorensen@redhat.com writes:
>> 
>>> From: Jes Sorensen <Jes.Sorensen@redhat.com>
>>>
>>> isspace() behavior is undefined for signed char.
>>>
>>> Bug pointed out by Eric Blake, thanks!
>>>
>>> Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
>>> ---
>>>  cutils.c |    7 ++++---
>>>  1 files changed, 4 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/cutils.c b/cutils.c
>>> index 4d2e27c..a067cf4 100644
>>> --- a/cutils.c
>>> +++ b/cutils.c
>>> @@ -294,7 +294,8 @@ int fcntl_setfl(int fd, int flag)
>>>  int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix)
>>>  {
>>>      int64_t retval = -1;
>>> -    char *endptr, c, d;
>>> +    char *endptr;
>>> +    unsigned char c, d;
>>>      int mul_required = 0;
>>>      double val, mul, integral, fraction;
>>>  
>> 
>> I doubt this hunk is still needed.
>
> It isn't strictly due to qemu_toupper() but it is prettier to match the
> real behavior of pure toupper() anyway.

Frequent casting between signed and unsigned has been shown to cause
headaches in laboratory rats.

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [Qemu-devel] [PATCH 4/4] strtosz(): Use suffix macros in switch() statement
  2011-01-24 16:39       ` Markus Armbruster
@ 2011-01-24 16:41         ` Jes Sorensen
  2011-01-24 17:47           ` Markus Armbruster
  0 siblings, 1 reply; 22+ messages in thread
From: Jes Sorensen @ 2011-01-24 16:41 UTC (permalink / raw)
  To: Markus Armbruster; +Cc: kwolf, qemu-devel

On 01/24/11 17:39, Markus Armbruster wrote:
>>>> +    case STRTOSZ_DEFSUFFIX_TB:
>>>> >>>          mul = 1ULL << 40;
>>>> >>>          break;
>>>> >>>      default:
>>> >> 
>>> >> Phony abstraction.  And it leaks: code here assumes the
>>> >> STRTOSZ_DEFSUFFIX_T* are all upper case.
>> >
>> > qemu_toupper() - whats the problem?
> If a STRTOSZ_DEFSUFFIX_T? expands to a lower case character, its case
> will not match any input.

Right, so one has to be careful when adding new suffix constants.
However given that we already have all the likely to be used ones for
the near future, that isn't exactly a big issue.

On the other hand forcing the use of the macros makes it less likely
that someone specifies an unsupported constant by hitting 'y' instead of
't' or similar.

Jes

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [Qemu-devel] Re: [PATCH v4 0/4] strtosz() cleanups
  2011-01-24 15:45 ` [Qemu-devel] Re: [PATCH v4 0/4] strtosz() cleanups Kevin Wolf
@ 2011-01-24 17:28   ` Stefan Weil
  2011-01-25  9:18     ` Jes Sorensen
  0 siblings, 1 reply; 22+ messages in thread
From: Stefan Weil @ 2011-01-24 17:28 UTC (permalink / raw)
  To: Kevin Wolf; +Cc: Jes.Sorensen, qemu-devel

Am 24.01.2011 16:45, schrieb Kevin Wolf:
> Am 24.01.2011 16:33, schrieb Jes.Sorensen@redhat.com:
>> From: Jes Sorensen <Jes.Sorensen@redhat.com>
>>
>> Hi,
>>
>> Here is an updated version of the strtosz() fixes that were discussed
>> earlier. Per discussing with Anthony on irc, he is ok with them going
>> in like this.
>>
>> This is a respin to fix a patch conflict in the block tree, and it
>> pulls the two patch sets into one set of four patches instead. No
>> functional change.
>>
>> Cheers,
>> Jes
>>
>>
>> Jes Sorensen (4):
>> strtosz(): use unsigned char and switch to qemu_isspace()
>> strtosz() use qemu_toupper() to simplify switch statement
>> strtosz(): Fix name confusion in use of modf()
>> strtosz(): Use suffix macros in switch() statement
>>
>> cutils.c | 28 ++++++++++++----------------
>> 1 files changed, 12 insertions(+), 16 deletions(-)
>>
>
> Thanks, applied all to the block branch.
>
> Kevin

There was some discussion regarding this patch set.
I agree with Markus that part of the first patch
should be removed: don't change char to unsigned char.

It's not necessary, and the result is, that now unsigned chars
are assigned to chars which might raise future compiler
warnings.

Stefan

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [Qemu-devel] [PATCH 4/4] strtosz(): Use suffix macros in switch() statement
  2011-01-24 16:41         ` Jes Sorensen
@ 2011-01-24 17:47           ` Markus Armbruster
  2011-01-25  9:19             ` Jes Sorensen
  0 siblings, 1 reply; 22+ messages in thread
From: Markus Armbruster @ 2011-01-24 17:47 UTC (permalink / raw)
  To: Jes Sorensen; +Cc: kwolf, qemu-devel

Jes Sorensen <Jes.Sorensen@redhat.com> writes:

> On 01/24/11 17:39, Markus Armbruster wrote:
>>>>> +    case STRTOSZ_DEFSUFFIX_TB:
>>>>> >>>          mul = 1ULL << 40;
>>>>> >>>          break;
>>>>> >>>      default:
>>>> >> 
>>>> >> Phony abstraction.  And it leaks: code here assumes the
>>>> >> STRTOSZ_DEFSUFFIX_T* are all upper case.
>>> >
>>> > qemu_toupper() - whats the problem?
>> If a STRTOSZ_DEFSUFFIX_T? expands to a lower case character, its case
>> will not match any input.
>
> Right, so one has to be careful when adding new suffix constants.

Calls for a comment right next to the definition of the
STRTOSZ_DEFSUFFIX_T*.

I hate unstated restrictions that are hidden far away from the place
where you can break them.

> However given that we already have all the likely to be used ones for
> the near future, that isn't exactly a big issue.
>
> On the other hand forcing the use of the macros makes it less likely
> that someone specifies an unsupported constant by hitting 'y' instead of
> 't' or similar.

Takes a combination of butterfingers, cross-eyedness, and near-total
incompetence at basic smoke-testing.

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [Qemu-devel] Re: [PATCH v4 0/4] strtosz() cleanups
  2011-01-24 17:28   ` Stefan Weil
@ 2011-01-25  9:18     ` Jes Sorensen
  2011-01-25 10:14       ` Markus Armbruster
  0 siblings, 1 reply; 22+ messages in thread
From: Jes Sorensen @ 2011-01-25  9:18 UTC (permalink / raw)
  To: Stefan Weil; +Cc: Kevin Wolf, qemu-devel

On 01/24/11 18:28, Stefan Weil wrote:
> There was some discussion regarding this patch set.
> I agree with Markus that part of the first patch
> should be removed: don't change char to unsigned char.

The unsigned char should definitely go in, leaving it as a signed char
doesn't serve any purpose.

> It's not necessary, and the result is, that now unsigned chars
> are assigned to chars which might raise future compiler
> warnings.

We already do that cast by calling qemu_toupper() and qemu_isspace() so
that argument is void.

Jes

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [Qemu-devel] [PATCH 4/4] strtosz(): Use suffix macros in switch() statement
  2011-01-24 17:47           ` Markus Armbruster
@ 2011-01-25  9:19             ` Jes Sorensen
  2011-01-25 10:17               ` Markus Armbruster
  0 siblings, 1 reply; 22+ messages in thread
From: Jes Sorensen @ 2011-01-25  9:19 UTC (permalink / raw)
  To: Markus Armbruster; +Cc: kwolf, qemu-devel

On 01/24/11 18:47, Markus Armbruster wrote:
> Jes Sorensen <Jes.Sorensen@redhat.com> writes:
>>>>> qemu_toupper() - whats the problem?
>>> If a STRTOSZ_DEFSUFFIX_T? expands to a lower case character, its case
>>> will not match any input.
>>
>> Right, so one has to be careful when adding new suffix constants.
> 
> Calls for a comment right next to the definition of the
> STRTOSZ_DEFSUFFIX_T*.
> 
> I hate unstated restrictions that are hidden far away from the place
> where you can break them.

Well I am fine with a comment in the code.

>> However given that we already have all the likely to be used ones for
>> the near future, that isn't exactly a big issue.
>>
>> On the other hand forcing the use of the macros makes it less likely
>> that someone specifies an unsupported constant by hitting 'y' instead of
>> 't' or similar.
> 
> Takes a combination of butterfingers, cross-eyedness, and near-total
> incompetence at basic smoke-testing.

Not really, all it takes is someone writing a piece of code, not
thinking about it, therefore only testing things where a suffix is
specified as an argument and it gets missed.

Jes

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [Qemu-devel] Re: [PATCH v4 0/4] strtosz() cleanups
  2011-01-25  9:18     ` Jes Sorensen
@ 2011-01-25 10:14       ` Markus Armbruster
  2011-01-25 11:52         ` Jes Sorensen
  0 siblings, 1 reply; 22+ messages in thread
From: Markus Armbruster @ 2011-01-25 10:14 UTC (permalink / raw)
  To: Jes Sorensen; +Cc: Kevin Wolf, qemu-devel

Jes Sorensen <Jes.Sorensen@redhat.com> writes:

> On 01/24/11 18:28, Stefan Weil wrote:
>> There was some discussion regarding this patch set.
>> I agree with Markus that part of the first patch
>> should be removed: don't change char to unsigned char.
>
> The unsigned char should definitely go in, leaving it as a signed char
> doesn't serve any purpose.

Leaving something as is doesn't need justification.  Changing it does.
The justification presented so far was "it is prettier to match the real
behavior of pure toupper()".  Which I don't buy.  But without commit
access, I'm not a buyer.

[...]

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [Qemu-devel] [PATCH 4/4] strtosz(): Use suffix macros in switch() statement
  2011-01-25  9:19             ` Jes Sorensen
@ 2011-01-25 10:17               ` Markus Armbruster
  2011-01-25 11:54                 ` Jes Sorensen
  0 siblings, 1 reply; 22+ messages in thread
From: Markus Armbruster @ 2011-01-25 10:17 UTC (permalink / raw)
  To: Jes Sorensen; +Cc: kwolf, qemu-devel

Jes Sorensen <Jes.Sorensen@redhat.com> writes:

> On 01/24/11 18:47, Markus Armbruster wrote:
>> Jes Sorensen <Jes.Sorensen@redhat.com> writes:
>>>>>> qemu_toupper() - whats the problem?
>>>> If a STRTOSZ_DEFSUFFIX_T? expands to a lower case character, its case
>>>> will not match any input.
>>>
>>> Right, so one has to be careful when adding new suffix constants.
>> 
>> Calls for a comment right next to the definition of the
>> STRTOSZ_DEFSUFFIX_T*.
>> 
>> I hate unstated restrictions that are hidden far away from the place
>> where you can break them.
>
> Well I am fine with a comment in the code.

Such a comment improves it from "wrong" to merely "ugly".  I can live
with that.

Thanks.

[...]

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [Qemu-devel] Re: [PATCH v4 0/4] strtosz() cleanups
  2011-01-25 10:14       ` Markus Armbruster
@ 2011-01-25 11:52         ` Jes Sorensen
  2011-01-25 13:19           ` Markus Armbruster
  0 siblings, 1 reply; 22+ messages in thread
From: Jes Sorensen @ 2011-01-25 11:52 UTC (permalink / raw)
  To: Markus Armbruster; +Cc: Kevin Wolf, qemu-devel

On 01/25/11 11:14, Markus Armbruster wrote:
> Jes Sorensen <Jes.Sorensen@redhat.com> writes:
> 
>> On 01/24/11 18:28, Stefan Weil wrote:
>>> There was some discussion regarding this patch set.
>>> I agree with Markus that part of the first patch
>>> should be removed: don't change char to unsigned char.
>>
>> The unsigned char should definitely go in, leaving it as a signed char
>> doesn't serve any purpose.
> 
> Leaving something as is doesn't need justification.  Changing it does.
> The justification presented so far was "it is prettier to match the real
> behavior of pure toupper()".  Which I don't buy.  But without commit
> access, I'm not a buyer.

Well that is just too bad. qemu_toupper() is a hack around the fact that
people often forget to use the right type, it is not an excuse for using
the wrong type in the code.

Jes

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [Qemu-devel] [PATCH 4/4] strtosz(): Use suffix macros in switch() statement
  2011-01-25 10:17               ` Markus Armbruster
@ 2011-01-25 11:54                 ` Jes Sorensen
  0 siblings, 0 replies; 22+ messages in thread
From: Jes Sorensen @ 2011-01-25 11:54 UTC (permalink / raw)
  To: Markus Armbruster; +Cc: kwolf, qemu-devel

On 01/25/11 11:17, Markus Armbruster wrote:
> Jes Sorensen <Jes.Sorensen@redhat.com> writes:
> 
>> On 01/24/11 18:47, Markus Armbruster wrote:
>>> Jes Sorensen <Jes.Sorensen@redhat.com> writes:
>>>>>>> qemu_toupper() - whats the problem?
>>>>> If a STRTOSZ_DEFSUFFIX_T? expands to a lower case character, its case
>>>>> will not match any input.
>>>>
>>>> Right, so one has to be careful when adding new suffix constants.
>>>
>>> Calls for a comment right next to the definition of the
>>> STRTOSZ_DEFSUFFIX_T*.
>>>
>>> I hate unstated restrictions that are hidden far away from the place
>>> where you can break them.
>>
>> Well I am fine with a comment in the code.
> 
> Such a comment improves it from "wrong" to merely "ugly".  I can live
> with that.

I realize that you view it as such, in other eyes it goes from hackish
to correct ... there is zero point in arguing over this, we can just
agree to disagree.

Jes

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [Qemu-devel] Re: [PATCH v4 0/4] strtosz() cleanups
  2011-01-25 11:52         ` Jes Sorensen
@ 2011-01-25 13:19           ` Markus Armbruster
  0 siblings, 0 replies; 22+ messages in thread
From: Markus Armbruster @ 2011-01-25 13:19 UTC (permalink / raw)
  To: Jes Sorensen; +Cc: Kevin Wolf, qemu-devel

Jes Sorensen <Jes.Sorensen@redhat.com> writes:

> On 01/25/11 11:14, Markus Armbruster wrote:
>> Jes Sorensen <Jes.Sorensen@redhat.com> writes:
>> 
>>> On 01/24/11 18:28, Stefan Weil wrote:
>>>> There was some discussion regarding this patch set.
>>>> I agree with Markus that part of the first patch
>>>> should be removed: don't change char to unsigned char.
>>>
>>> The unsigned char should definitely go in, leaving it as a signed char
>>> doesn't serve any purpose.
>> 
>> Leaving something as is doesn't need justification.  Changing it does.
>> The justification presented so far was "it is prettier to match the real
>> behavior of pure toupper()".  Which I don't buy.  But without commit
>> access, I'm not a buyer.
>
> Well that is just too bad. qemu_toupper() is a hack around the fact that
> people often forget to use the right type, it is not an excuse for using
> the wrong type in the code.

qemu_toupper() is designed to work correctly for any character argument,
be it signed or unsigned.

The fact that toupper() works only for unsigned character values is
irrelevant for qemu_toupper().

The fact that qemu_toupper()'s implementation uses toupper() is an
implementation detail.

^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2011-01-25 13:20 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-24 15:33 [Qemu-devel] [PATCH v4 0/4] strtosz() cleanups Jes.Sorensen
2011-01-24 15:33 ` [Qemu-devel] [PATCH 1/4] strtosz(): use unsigned char and switch to qemu_isspace() Jes.Sorensen
2011-01-24 16:10   ` Markus Armbruster
2011-01-24 16:11     ` Jes Sorensen
2011-01-24 16:40       ` Markus Armbruster
2011-01-24 15:33 ` [Qemu-devel] [PATCH 2/4] strtosz() use qemu_toupper() to simplify switch statement Jes.Sorensen
2011-01-24 15:33 ` [Qemu-devel] [PATCH 3/4] strtosz(): Fix name confusion in use of modf() Jes.Sorensen
2011-01-24 15:33 ` [Qemu-devel] [PATCH 4/4] strtosz(): Use suffix macros in switch() statement Jes.Sorensen
2011-01-24 16:08   ` Markus Armbruster
2011-01-24 16:10     ` Jes Sorensen
2011-01-24 16:39       ` Markus Armbruster
2011-01-24 16:41         ` Jes Sorensen
2011-01-24 17:47           ` Markus Armbruster
2011-01-25  9:19             ` Jes Sorensen
2011-01-25 10:17               ` Markus Armbruster
2011-01-25 11:54                 ` Jes Sorensen
2011-01-24 15:45 ` [Qemu-devel] Re: [PATCH v4 0/4] strtosz() cleanups Kevin Wolf
2011-01-24 17:28   ` Stefan Weil
2011-01-25  9:18     ` Jes Sorensen
2011-01-25 10:14       ` Markus Armbruster
2011-01-25 11:52         ` Jes Sorensen
2011-01-25 13:19           ` Markus Armbruster

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.