From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oa1-x2f.google.com (mail-oa1-x2f.google.com [IPv6:2001:4860:4864:20::2f]) by sourceware.org (Postfix) with ESMTPS id F23693834E23 for ; Wed, 14 Dec 2022 14:38:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org F23693834E23 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-oa1-x2f.google.com with SMTP id 586e51a60fabf-14455716674so16826186fac.7 for ; Wed, 14 Dec 2022 06:38:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:in-reply-to:organization:from:references :to:content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=Zn4eIhz5dIu3GozBQSCjGAr0C/fCn/DHGyJvO3EJuiE=; b=ptVG+Enukq9uBoS24nCgaqHB8JPZJ941/OzqSx6kTb4Gdg3TOEaFlrjEo9FlyDaQdO 7VgxoQVaw+D4LV8N5S6CkTNUW9Gok2Wd5fUNtg94bQoBt/ggkgGkLTNGwzRsN9CF5L+q rY8sYaZs//XZ7ArQAkhW5D8b+DXapyRtXH5d2QBgT0KMHPcNa3DgOza9q0Q5+f4pbVqs nNhEeqC5z38RTVV5S57vC8wc5rTE3oTsTMozM5CnlCqyZF/F/eZv3gFteKr+c03q2l0e bkUuZCWCKPSfGRGdxfmhFyWQSaX+JJdz/JhuIus2biRWlBr1DdzTr/bqaROUzbO+gDO5 tI9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:organization:from:references :to:content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Zn4eIhz5dIu3GozBQSCjGAr0C/fCn/DHGyJvO3EJuiE=; b=MPAkcPZJT5hSCWqjkXSCffYgMFmdZq9FyZOwfYkyeODVqPN8uLn74p1GLLUDHZyyUQ dgjFR1gTkobr0WYaTLBPSTsuFoxG6i7pNxH9udkTuKUwkgf846sA4exyfS7oH8A7AwE8 e/gMVaXY495uIN62oQWSsoFVEbBT6zaRnKscdxnHMkFI1Kw9KTi8IciHXNbSVr7KHBIg MypjWU1g6Do7AkPWat3HRRltWVPwTYhc5mzvUVqGI8lY/xpRK6ZvMgNI4wWwLPb3GZOt v2/dvRblu7AxhFfphyWpPa9xnxwcfBMR5/Mbv7BgxQWAAVnnUdpnc9UB8cFzCBzjg04v 6log== X-Gm-Message-State: ANoB5plLurvvspi5mByKU0M65EbMp3lwx54VafyeZKizbxZE0C2CKCup vzI5uCrPw7rQIiaGNtHGj7lUAC1qRJ6T5gnrZII= X-Google-Smtp-Source: AA0mqf5jAUL5GYlEkvl33wgVzchr1m6q3Xa9JqsOxwVbFNL3CcWXJpYbGR2hm1R9m33apAmF+EoYmw== X-Received: by 2002:a05:6871:4098:b0:144:4bf1:a6f3 with SMTP id kz24-20020a056871409800b001444bf1a6f3mr14728466oab.8.1671028710525; Wed, 14 Dec 2022 06:38:30 -0800 (PST) Received: from ?IPV6:2804:1b3:a7c2:f05e:98ce:57c2:5097:ae83? ([2804:1b3:a7c2:f05e:98ce:57c2:5097:ae83]) by smtp.gmail.com with ESMTPSA id e22-20020a544f16000000b0035aa617156bsm5672060oiy.17.2022.12.14.06.38.28 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 14 Dec 2022 06:38:29 -0800 (PST) Message-ID: Date: Wed, 14 Dec 2022 11:38:27 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.5.1 Subject: Re: [PATCH v5 04/11] stdio-common: Add __translated_number_width Content-Language: en-US To: libc-alpha@sourceware.org, Florian Weimer References: <8566149e25485ca6e0cafa0c3e7366d3f7efe532.1670858473.git.fweimer@redhat.com> From: Adhemerval Zanella Netto Organization: Linaro In-Reply-To: <8566149e25485ca6e0cafa0c3e7366d3f7efe532.1670858473.git.fweimer@redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 12/12/22 12:23, Florian Weimer via Libc-alpha wrote: > This function will be used to compute the width of a number > after i18n digit translation. LGTM, thanks. Reviewed-by: Adhemerval Zanella > --- > include/printf.h | 13 +++++++- > stdio-common/Makefile | 1 + > stdio-common/translated_number_width.c | 42 ++++++++++++++++++++++++++ > 3 files changed, 55 insertions(+), 1 deletion(-) > create mode 100644 stdio-common/translated_number_width.c > > diff --git a/include/printf.h b/include/printf.h > index 8f064149d3..5127a45f9b 100644 > --- a/include/printf.h > +++ b/include/printf.h > @@ -53,7 +53,18 @@ int __wprintf_function_invoke (void *, printf_function callback, > > #include > > -/* Now define the internal interfaces. */ > +/* Returns the width (as for printf, in bytes) of the converted ASCII > + number in the characters in the range [FIRST, LAST). The range > + must only contain ASCII digits. The caller is responsible for > + avoiding overflow. > + > + This function is used during non-wide digit translation. Wide > + digit translate produces one wide character per ASCII digit, > + so the width is simply LAST - FIRST. */ > +int __translated_number_width (locale_t loc, > + const char *first, const char *last) > + attribute_hidden; > + > extern int __printf_fphex (FILE *, const struct printf_info *, > const void *const *) attribute_hidden; > extern int __printf_fp (FILE *, const struct printf_info *, Ok. > diff --git a/stdio-common/Makefile b/stdio-common/Makefile > index 6e6da091b1..3e0c574ca5 100644 > --- a/stdio-common/Makefile > +++ b/stdio-common/Makefile > @@ -85,6 +85,7 @@ routines := \ > tmpfile64 \ > tmpnam \ > tmpnam_r \ > + translated_number_width \ > vfprintf \ > vfprintf-internal \ > vfscanf \ Ok. > diff --git a/stdio-common/translated_number_width.c b/stdio-common/translated_number_width.c > new file mode 100644 > index 0000000000..f42d5968a1 > --- /dev/null > +++ b/stdio-common/translated_number_width.c > @@ -0,0 +1,42 @@ > +/* Compute the printf width of a sequence of ASCII digits. > + Copyright (C) 2022 Free Software Foundation, Inc. > + This file is part of the GNU C Library. > + > + The GNU C Library is free software; you can redistribute it and/or > + modify it under the terms of the GNU Lesser General Public > + License as published by the Free Software Foundation; either > + version 2.1 of the License, or (at your option) any later version. > + > + The GNU C Library is distributed in the hope that it will be useful, > + but WITHOUT ANY WARRANTY; without even the implied warranty of > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > + Lesser General Public License for more details. > + > + You should have received a copy of the GNU Lesser General Public > + License along with the GNU C Library; if not, see > + . */ > + > +#include > +#include > +#include > +#include > + > +int > +__translated_number_width (locale_t loc, const char *first, const char *last) > +{ > + struct lc_ctype_data *ctype = loc->__locales[LC_CTYPE]->private; > + > + if (ctype->outdigit_bytes_all_equal > 0) > + return (last - first) * ctype->outdigit_bytes_all_equal; > + else > + { > + /* Digits have varying length, so the fast path cannot be used. */ > + int digits = 0; > + for (const char *p = first; p < last; ++p) > + { > + assert ('0' <= *p && *p <= '9'); > + digits += ctype->outdigit_bytes[*p - '0']; > + } > + return digits; > + } > +} Ok.