public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
To: Florian Weimer <fweimer@redhat.com>, libc-alpha@sourceware.org
Subject: Re: [PATCH 06/26] vfprintf: Consolidate some multibyte/wide character processing
Date: Fri, 20 May 2022 11:16:08 -0300	[thread overview]
Message-ID: <4e110602-b0a9-1fe6-d640-5cca1cca76ec@linaro.org> (raw)
In-Reply-To: <c3452ce7f9301b9b12e97bf35f5d8eaff0e0c39e.1647544751.git.fweimer@redhat.com>



On 17/03/2022 16:28, Florian Weimer via Libc-alpha wrote:
> form_character and form_string processing a sufficiently similar
> that the logic can be shared.

LGTM, thanks.

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

> ---
>  stdio-common/vfprintf-process-arg.c | 130 +++++++++-------------------
>  1 file changed, 43 insertions(+), 87 deletions(-)
> 
> diff --git a/stdio-common/vfprintf-process-arg.c b/stdio-common/vfprintf-process-arg.c
> index a28afce7de..4fe369e111 100644
> --- a/stdio-common/vfprintf-process-arg.c
> +++ b/stdio-common/vfprintf-process-arg.c
> @@ -335,29 +335,20 @@ LABEL (form_strerror):
>        goto LABEL (print_string);
>      }
>  
> -#ifdef COMPILE_WPRINTF
>  LABEL (form_character):
>    /* Character.  */
>    if (is_long)
>      goto LABEL (form_wcharacter);
>    --width;  /* Account for the character itself.  */
>    if (!left)
> -    PAD (L' ');
> +    PAD (L_(' '));
> +#ifdef COMPILE_WPRINTF
>    outchar (__btowc ((unsigned char) process_arg_int ())); /* Promoted. */
> +#else
> +  outchar ((unsigned char) process_arg_int ()); /* Promoted.  */
> +#endif
>    if (left)
> -    PAD (L' ');
> -  break;
> -
> -LABEL (form_wcharacter):
> -  {
> -    /* Wide character.  */
> -    --width;
> -    if (!left)
> -      PAD (L' ');
> -    outchar (process_arg_wchar_t ());
> -    if (left)
> -      PAD (L' ');
> -  }
> +    PAD (L_(' '));
>    break;
>  
>  LABEL (form_string):
> @@ -366,8 +357,11 @@ LABEL (form_string):
>  
>      /* The string argument could in fact be `char *' or `wchar_t *'.
>         But this should not make a difference here.  */
> +#ifdef COMPILE_WPRINTF
>      string = (CHAR_T *) process_arg_wstring ();
> -
> +#else
> +    string = (CHAR_T *) process_arg_string ();
> +#endif
>      /* Entry point for printing other strings.  */
>      LABEL (print_string):
>  
> @@ -387,21 +381,39 @@ LABEL (form_string):
>        }
>      else if (!is_long && spec != L_('S'))
>        {
> +#ifdef COMPILE_WPRINTF
>          done = outstring_converted_wide_string
>            (s, (const char *) string, prec, width, left, done);
>          if (done < 0)
>            goto all_done;
>          /* The padding has already been written.  */
>          break;
> +#else
> +        if (prec != -1)
> +          /* Search for the end of the string, but don't search past
> +             the length (in bytes) specified by the precision.  */
> +          len = __strnlen (string, prec);
> +        else
> +          len = strlen (string);
> +#endif
>        }
>      else
>        {
> +#ifdef COMPILE_WPRINTF
>          if (prec != -1)
>            /* Search for the end of the string, but don't search past
>               the length specified by the precision.  */
>            len = __wcsnlen (string, prec);
>          else
>            len = __wcslen (string);
> +#else
> +        done = outstring_converted_wide_string
> +          (s, (const wchar_t *) string, prec, width, left, done);
> +        if (done < 0)
> +          goto all_done;
> +        /* The padding has already been written.  */
> +        break;
> +#endif
>        }
>  
>      if ((width -= len) < 0)
> @@ -411,25 +423,27 @@ LABEL (form_string):
>        }
>  
>      if (!left)
> -      PAD (L' ');
> +      PAD (L_(' '));
>      outstring (string, len);
>      if (left)
> -      PAD (L' ');
> +      PAD (L_(' '));
>    }
>    break;
> -#else /* !COMPILE_WPRINTF */
> -LABEL (form_character):
> -  /* Character.  */
> -  if (is_long)
> -    goto LABEL (form_wcharacter);
> -  --width;  /* Account for the character itself.  */
> -  if (!left)
> -    PAD (' ');
> -  outchar ((unsigned char) process_arg_int ()); /* Promoted.  */
> -  if (left)
> -    PAD (' ');
> +
> +#ifdef COMPILE_WPRINTF
> +LABEL (form_wcharacter):
> +  {
> +    /* Wide character.  */
> +    --width;
> +    if (!left)
> +      PAD (L' ');
> +    outchar (process_arg_wchar_t ());
> +    if (left)
> +      PAD (L' ');
> +  }
>    break;
>  
> +#else /* !COMPILE_WPRINTF */
>  LABEL (form_wcharacter):
>    {
>      /* Wide character.  */
> @@ -453,63 +467,5 @@ LABEL (form_wcharacter):
>        PAD (' ');
>    }
>    break;
> -
> -LABEL (form_string):
> -  {
> -    size_t len;
> -
> -    /* The string argument could in fact be `char *' or `wchar_t *'.
> -       But this should not make a difference here.  */
> -    string = (char *) process_arg_string ();
> -
> -    /* Entry point for printing other strings.  */
> -    LABEL (print_string):
> -
> -    if (string == NULL)
> -      {
> -        /* Write "(null)" if there's space.  */
> -        if (prec == -1 || prec >= (int) sizeof (null) - 1)
> -          {
> -            string = (char *) null;
> -            len = sizeof (null) - 1;
> -          }
> -        else
> -          {
> -            string = (char *) "";
> -            len = 0;
> -          }
> -      }
> -    else if (!is_long && spec != L_('S'))
> -      {
> -        if (prec != -1)
> -          /* Search for the end of the string, but don't search past
> -             the length (in bytes) specified by the precision.  */
> -          len = __strnlen (string, prec);
> -        else
> -          len = strlen (string);
> -      }
> -    else
> -      {
> -        done = outstring_converted_wide_string
> -          (s, (const wchar_t *) string, prec, width, left, done);
> -        if (done < 0)
> -          goto all_done;
> -        /* The padding has already been written.  */
> -        break;
> -      }
> -
> -    if ((width -= len) < 0)
> -      {
> -        outstring (string, len);
> -        break;
> -      }
> -
> -    if (!left)
> -      PAD (' ');
> -    outstring (string, len);
> -    if (left)
> -      PAD (' ');
> -  }
> -  break;
>  #endif /* !COMPILE_WPRINTF */
>  }

  reply	other threads:[~2022-05-20 14:16 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-17 19:28 [PATCH 00/26] vfprintf rework to remove vtables Florian Weimer
2022-03-17 19:28 ` [PATCH 01/26] libio: Convert tst_swprintf to the test framework Florian Weimer
2022-03-18 17:40   ` Adhemerval Zanella
2022-03-17 19:28 ` [PATCH 02/26] libio: Flush-only _IO_str_overflow must not return EOF (bug 28949) Florian Weimer
2022-03-18 18:11   ` Adhemerval Zanella
2022-03-17 19:28 ` [PATCH 03/26] stdio-common: Add wide stream coverage to tst-vfprintf-user-type Florian Weimer
2022-03-18 18:30   ` Adhemerval Zanella
2022-03-18 19:19     ` Florian Weimer
2022-03-17 19:28 ` [PATCH 04/26] stdio-common: Add tst-printf-width-i18n to cover numeric field width Florian Weimer
2022-05-20 13:22   ` Adhemerval Zanella
2022-05-20 13:33     ` Adhemerval Zanella
2022-05-23  6:39       ` Florian Weimer
2022-03-17 19:28 ` [PATCH 05/26] vfprintf: Move argument processing into vfprintf-process-arg.c Florian Weimer
2022-05-20 13:28   ` Adhemerval Zanella
2022-03-17 19:28 ` [PATCH 06/26] vfprintf: Consolidate some multibyte/wide character processing Florian Weimer
2022-05-20 14:16   ` Adhemerval Zanella [this message]
2022-03-17 19:29 ` [PATCH 07/26] __printf_fphex always uses LC_NUMERIC Florian Weimer
2022-05-20 14:21   ` Adhemerval Zanella
2022-05-23  6:55     ` Florian Weimer
2022-03-17 19:29 ` [PATCH 08/26] stdio-common: Add tst-memstream-string for open_memstream overflow Florian Weimer
2022-05-20 17:44   ` Adhemerval Zanella
2022-05-23  7:03     ` Florian Weimer
2022-03-17 19:29 ` [PATCH 09/26] stdio-common: Add printf specifier registry to <printf.h> Florian Weimer
2022-05-20 17:49   ` Adhemerval Zanella
2022-03-17 19:30 ` [PATCH 10/26] stdio-common: Move union printf_arg int <printf.h> Florian Weimer
2022-05-20 17:51   ` Adhemerval Zanella
2022-03-17 19:30 ` [PATCH 11/26] stdio-common: Simplify printf_unknown interface in vfprintf-internal.c Florian Weimer
2022-05-20 18:07   ` Adhemerval Zanella
2022-03-17 19:30 ` [PATCH 12/26] locale: Call _nl_unload_locale from _nl_archive_subfreeres Florian Weimer
2022-05-20 18:09   ` Adhemerval Zanella
2022-05-23  7:14     ` Florian Weimer
2022-03-17 19:30 ` [PATCH 13/26] locale: Remove cleanup function pointer from struct __localedata Florian Weimer
2022-05-20 18:16   ` Adhemerval Zanella
2022-03-17 19:30 ` [PATCH 14/26] locale: Remove private union from struct __locale_data Florian Weimer
2022-05-20 18:22   ` Adhemerval Zanella
2022-03-17 19:30 ` [PATCH 15/26] locale: Add more cached data to LC_CTYPE Florian Weimer
2022-05-20 18:29   ` Adhemerval Zanella
2022-05-23  7:20     ` Florian Weimer
2022-03-17 19:31 ` [PATCH 16/26] locale: Implement struct grouping_iterator Florian Weimer
2022-03-17 19:31 ` [PATCH 17/26] stdio-common: Introduce buffers for implementing printf Florian Weimer
2022-03-17 19:31 ` [PATCH 18/26] stdio-common: Add __printf_function_invoke Florian Weimer
2022-03-17 19:31 ` [PATCH 19/26] stdio-common: Add __translated_number_width Florian Weimer
2022-03-17 19:31 ` [PATCH 20/26] stdio-common: Convert vfprintf and related functions to buffers Florian Weimer
2022-03-17 19:31 ` [PATCH 21/26] stdio-common: Add lock optimization to vfprintf and vfwprintf Florian Weimer
2022-03-17 19:31 ` [PATCH 22/26] libio: Convert __vsprintf_internal to buffers Florian Weimer
2022-03-17 19:31 ` [PATCH 23/26] libio: Convert __vasprintf_internal " Florian Weimer
2022-03-17 19:31 ` [PATCH 24/26] libio: Convert __vdprintf_internal " Florian Weimer
2022-03-17 19:32 ` [PATCH 25/26] libio: Convert __obstack_vprintf_internal to buffers (bug 27124) Florian Weimer
2022-03-17 19:32 ` [PATCH 26/26] libio: Convert __vswprintf_internal to buffers (bug 27857) Florian Weimer

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=4e110602-b0a9-1fe6-d640-5cca1cca76ec@linaro.org \
    --to=adhemerval.zanella@linaro.org \
    --cc=fweimer@redhat.com \
    --cc=libc-alpha@sourceware.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).