qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 14/24] util/cutils: New qemu_strtosz_metric()


From: Markus Armbruster
Subject: Re: [Qemu-devel] [PATCH 14/24] util/cutils: New qemu_strtosz_metric()
Date: Sat, 18 Feb 2017 11:08:38 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux)

Eric Blake <address@hidden> writes:

> On 02/14/2017 04:26 AM, Markus Armbruster wrote:
>> To parse numbers with metric suffixes, we use
>> 
>>     qemu_strtosz_suffix_unit(nptr, &eptr, QEMU_STRTOSZ_DEFSUFFIX_B, 1000)
>> 
>> Capture this in a new function for legibility:
>> 
>>     qemu_strtosz_metric(nptr, &eptr)
>> 
>> Replace test_qemu_strtosz_suffix_unit() by test_qemu_strtosz_metric().
>> 
>> Rename qemu_strtosz_suffix_unit() to do_strtosz() and give it internal
>> linkage.
>
> I don't know if you do this later, but coreutils (via gnulib) has a nice
> convention that:
>
> 1k   => 1024
> 1kB  => 1000
> 1kiB => 1024
>
> where the suffix can be used to express metric or power-of-two, letting
> the user choose which scale they want rather than hard-coding the scale.

Could be done for the calls that currently pass 1024, because the
existing one-character suffixes keep their meaning there.  Would be an
incompatible change for the calls that pass 1000.  There's just one
outside of tests, and it's a frequency value, i.e. 'k' makes sense, but
'kB' and 'kiB' do not.

>  But implementing that is beyond this scope of this particular patch.

Indeed.

>> Signed-off-by: Markus Armbruster <address@hidden>
>> ---
>
>> @@ -251,7 +251,7 @@ fail:
>>  int64_t qemu_strtosz_suffix(const char *nptr, char **end,
>>                              const char default_suffix)
>>  {
>> -    return qemu_strtosz_suffix_unit(nptr, end, default_suffix, 1024);
>> +    return do_strtosz(nptr, end, default_suffix, 1024);
>>  }
>>  
>>  int64_t qemu_strtosz(const char *nptr, char **end)
>> @@ -259,6 +259,11 @@ int64_t qemu_strtosz(const char *nptr, char **end)
>>      return qemu_strtosz_suffix(nptr, end, QEMU_STRTOSZ_DEFSUFFIX_MB);
>
> Do you also want to convert this one to do_strtosz() to avoid
> double-forwarding?

See next patch :)

> Either way,
>
> Reviewed-by: Eric Blake <address@hidden>

Thanks!



reply via email to

[Prev in Thread] Current Thread [Next in Thread]