[07/26] __printf_fphex always uses LC_NUMERIC

Message ID e40e6ba3aeb00e060989eb241ae02df25558ab3b.1647544751.git.fweimer@redhat.com
State Committed
Headers
Series vfprintf rework to remove vtables |

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent

Commit Message

Florian Weimer March 17, 2022, 7:29 p.m. UTC
  There is no hexadecimal currency printing.  strfmon uses
__printf_fp_l exclusively.
---
 stdio-common/printf_fphex.c | 26 +++++++-------------------
 1 file changed, 7 insertions(+), 19 deletions(-)
  

Comments

Adhemerval Zanella May 20, 2022, 2:21 p.m. UTC | #1
On 17/03/2022 16:29, Florian Weimer via Libc-alpha wrote:
> There is no hexadecimal currency printing.  strfmon uses
> __printf_fp_l exclusively.

LGTM, some comments below.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>

> ---
>  stdio-common/printf_fphex.c | 26 +++++++-------------------
>  1 file changed, 7 insertions(+), 19 deletions(-)
> 
> diff --git a/stdio-common/printf_fphex.c b/stdio-common/printf_fphex.c
> index 3dbbefd972..df11b4a166 100644
> --- a/stdio-common/printf_fphex.c
> +++ b/stdio-common/printf_fphex.c
> @@ -103,9 +103,13 @@ __printf_fphex (FILE *fp,
>      }
>    fpnum;
>  
> -  /* Locale-dependent representation of decimal point.	*/
> -  const char *decimal;
> -  wchar_t decimalwc;
> +  /* Locale-dependent representation of decimal point. Hexadecimal
> +     formatting always using LC_NUMERIC (disregarding info->extra).  */
> +  const char *decimal = _NL_CURRENT (LC_NUMERIC, DECIMAL_POINT);
> +  wchar_t decimalwc = _NL_CURRENT_WORD (LC_NUMERIC, _NL_NUMERIC_DECIMAL_POINT_WC);

Line too long.

> +
> +  /* The decimal point character must never be zero.  */
> +  assert (*decimal != '\0' && decimalwc != L'\0');
>  

Should we assert for info->extra == 0 ?

>    /* "NaN" or "Inf" for the special cases.  */
>    const char *special = NULL;
> @@ -147,22 +151,6 @@ __printf_fphex (FILE *fp,
>    /* Nonzero if this is output on a wide character stream.  */
>    int wide = info->wide;
>  
> -
> -  /* Figure out the decimal point character.  */
> -  if (info->extra == 0)
> -    {
> -      decimal = _NL_CURRENT (LC_NUMERIC, DECIMAL_POINT);
> -      decimalwc = _NL_CURRENT_WORD (LC_NUMERIC, _NL_NUMERIC_DECIMAL_POINT_WC);
> -    }
> -  else
> -    {
> -      decimal = _NL_CURRENT (LC_MONETARY, MON_DECIMAL_POINT);
> -      decimalwc = _NL_CURRENT_WORD (LC_MONETARY,
> -				    _NL_MONETARY_DECIMAL_POINT_WC);
> -    }
> -  /* The decimal point character must never be zero.  */
> -  assert (*decimal != '\0' && decimalwc != L'\0');
> -
>  #define PRINTF_FPHEX_FETCH(FLOAT, VAR)					\
>    {									\
>      (VAR) = *(const FLOAT *) args[0];					\
  
Florian Weimer May 23, 2022, 6:55 a.m. UTC | #2
* Adhemerval Zanella:

> On 17/03/2022 16:29, Florian Weimer via Libc-alpha wrote:
>> There is no hexadecimal currency printing.  strfmon uses
>> __printf_fp_l exclusively.
>
> LGTM, some comments below.
>
> Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
>
>> ---
>>  stdio-common/printf_fphex.c | 26 +++++++-------------------
>>  1 file changed, 7 insertions(+), 19 deletions(-)
>> 
>> diff --git a/stdio-common/printf_fphex.c b/stdio-common/printf_fphex.c
>> index 3dbbefd972..df11b4a166 100644
>> --- a/stdio-common/printf_fphex.c
>> +++ b/stdio-common/printf_fphex.c
>> @@ -103,9 +103,13 @@ __printf_fphex (FILE *fp,
>>      }
>>    fpnum;
>>  
>> -  /* Locale-dependent representation of decimal point.	*/
>> -  const char *decimal;
>> -  wchar_t decimalwc;
>> +  /* Locale-dependent representation of decimal point. Hexadecimal
>> +     formatting always using LC_NUMERIC (disregarding info->extra).  */
>> +  const char *decimal = _NL_CURRENT (LC_NUMERIC, DECIMAL_POINT);
>> +  wchar_t decimalwc = _NL_CURRENT_WORD (LC_NUMERIC, _NL_NUMERIC_DECIMAL_POINT_WC);
>
> Line too long.

Fixed.

>> +  /* The decimal point character must never be zero.  */
>> +  assert (*decimal != '\0' && decimalwc != L'\0');
>>  
>
> Should we assert for info->extra == 0 ?

I added:

  /* This function always uses LC_NUMERIC.  */
  assert (info->extra == 0);

Thanks,
Florian
  

Patch

diff --git a/stdio-common/printf_fphex.c b/stdio-common/printf_fphex.c
index 3dbbefd972..df11b4a166 100644
--- a/stdio-common/printf_fphex.c
+++ b/stdio-common/printf_fphex.c
@@ -103,9 +103,13 @@  __printf_fphex (FILE *fp,
     }
   fpnum;
 
-  /* Locale-dependent representation of decimal point.	*/
-  const char *decimal;
-  wchar_t decimalwc;
+  /* Locale-dependent representation of decimal point. Hexadecimal
+     formatting always using LC_NUMERIC (disregarding info->extra).  */
+  const char *decimal = _NL_CURRENT (LC_NUMERIC, DECIMAL_POINT);
+  wchar_t decimalwc = _NL_CURRENT_WORD (LC_NUMERIC, _NL_NUMERIC_DECIMAL_POINT_WC);
+
+  /* The decimal point character must never be zero.  */
+  assert (*decimal != '\0' && decimalwc != L'\0');
 
   /* "NaN" or "Inf" for the special cases.  */
   const char *special = NULL;
@@ -147,22 +151,6 @@  __printf_fphex (FILE *fp,
   /* Nonzero if this is output on a wide character stream.  */
   int wide = info->wide;
 
-
-  /* Figure out the decimal point character.  */
-  if (info->extra == 0)
-    {
-      decimal = _NL_CURRENT (LC_NUMERIC, DECIMAL_POINT);
-      decimalwc = _NL_CURRENT_WORD (LC_NUMERIC, _NL_NUMERIC_DECIMAL_POINT_WC);
-    }
-  else
-    {
-      decimal = _NL_CURRENT (LC_MONETARY, MON_DECIMAL_POINT);
-      decimalwc = _NL_CURRENT_WORD (LC_MONETARY,
-				    _NL_MONETARY_DECIMAL_POINT_WC);
-    }
-  /* The decimal point character must never be zero.  */
-  assert (*decimal != '\0' && decimalwc != L'\0');
-
 #define PRINTF_FPHEX_FETCH(FLOAT, VAR)					\
   {									\
     (VAR) = *(const FLOAT *) args[0];					\