From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ot1-x32f.google.com (mail-ot1-x32f.google.com [IPv6:2607:f8b0:4864:20::32f]) by sourceware.org (Postfix) with ESMTPS id AC9103856DC4 for ; Fri, 20 May 2022 14:16:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org AC9103856DC4 Received: by mail-ot1-x32f.google.com with SMTP id e11-20020a9d6e0b000000b0060afcbafa80so331otr.3 for ; Fri, 20 May 2022 07:16:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:references:from:in-reply-to :content-transfer-encoding; bh=wcf9Pxp48t2A9MZY2E7zuR8zQupaixoYbV0xbjKDQ4k=; b=ZelbTo45mNHiKG30TTl/W5fRNf7jTXST5Pq4wnGf2/N+nfPZYz+aSO5bR0THooksny exGMwNAQ4jMTC7RxWKwns2KxrCqM1GZzXU6/wHLWH8+AWqcELgrf4cTbiphx/VYMRt25 GPEfTgH1FjBuukXPFlh+EvRH4v06/7u5CdPkFcZMeC5+MrPqb/hO/W7cJ1U8i3CALmq9 KMKdcjQ3VnxZnJM/kShugaV9NrkvhiN+kqfbtmsCwPrTv//ET409NjjNROfEcFRAV7Xn Ze2dFtkEa4hX8suTbfBTVfHw7qy9TFar8setE9sV1vlIldHeVvV365gj53lxQ0cWLdRJ 9GPw== X-Gm-Message-State: AOAM531L+FYP62waEtrsSJe4DfDsFqjfbiZYeKDJzzXLHbmbTLyWxSfm YoAP49oR3+Kpn27IbbZeCEE2Vz49Qgr+1g== X-Google-Smtp-Source: ABdhPJyr2E0fB4hN66pXEgGxNOVma97IQFAqYd2r+Y+LETGac3xp39CyqrfsJpMst2Ga0uO+bGnLbQ== X-Received: by 2002:a05:6830:118d:b0:606:aac7:e044 with SMTP id u13-20020a056830118d00b00606aac7e044mr3952714otq.280.1653056171595; Fri, 20 May 2022 07:16:11 -0700 (PDT) Received: from ?IPV6:2804:431:c7cb:cdd6:1223:d9e4:2076:bfdf? ([2804:431:c7cb:cdd6:1223:d9e4:2076:bfdf]) by smtp.gmail.com with ESMTPSA id j30-20020a4ad2de000000b0035f627ac898sm1097054oos.10.2022.05.20.07.16.09 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 20 May 2022 07:16:10 -0700 (PDT) Message-ID: <4e110602-b0a9-1fe6-d640-5cca1cca76ec@linaro.org> Date: Fri, 20 May 2022 11:16:08 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.0 Subject: Re: [PATCH 06/26] vfprintf: Consolidate some multibyte/wide character processing Content-Language: en-US To: Florian Weimer , libc-alpha@sourceware.org References: From: Adhemerval Zanella In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 20 May 2022 14:16:29 -0000 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 > --- > 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 */ > }