wcwidth: adjust manpage input (Re: [PATCH] fix wcwidth to work with gcc 16 sign extension)
| Message ID | f8a83c65-1971-44ab-a51c-14d09d89c8ee@towo.net |
|---|---|
| State | New |
| Headers |
Return-Path: <newlib-bounces~patchwork=sourceware.org@sourceware.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AB4D84C31851 for <patchwork@sourceware.org>; Sat, 6 Jun 2026 08:40:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AB4D84C31851 Authentication-Results: sourceware.org; dkim=fail reason="signature verification failed" (2048-bit key, unprotected) header.d=towo.net header.i=towo@towo.net header.a=rsa-sha256 header.s=s1-ionos header.b=bSXwTi6L X-Original-To: newlib@sourceware.org Delivered-To: newlib@sourceware.org Received: from mout.kundenserver.de (mout.kundenserver.de [217.72.192.74]) by sourceware.org (Postfix) with ESMTPS id ECAFE4BA23C8 for <newlib@sourceware.org>; Sat, 6 Jun 2026 08:40:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org ECAFE4BA23C8 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=towo.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=towo.net ARC-Filter: OpenARC Filter v1.0.0 sourceware.org ECAFE4BA23C8 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=217.72.192.74 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1780735212; cv=none; b=uHxlO8WrnAjmwSXr8DoHFSDkrjEN8mPVi0HOsMkNuRHleT2JU++8CTeFInIqhGpxYM81/rfXAy3Pf2h/QG5ACD7K+sgB18rRSuASvy9Np2gXblzhfpG6ceAU1gOpMKYsBLjx8gLLtS1ajnH+w2UMujOJ0EB+SBXdBElGdO9r6V4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1780735212; c=relaxed/simple; bh=mYFrsh6fL/oPwZueOroadGJMeR2ZY+ATo3uTAUiguqs=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=MbbJsBsdWd/4dzaJCWesl5yGn1BOoDfvUdZN0HanEELY6kRUI3MKJgHeVKGmGF35Rxj485Uzn9YaNVcHT0riAb0rtL5dPptnqNpW2aV0AaVNrz+TInp4aYDQXAN58ju15v/dnmVVwq0IBr7FBgQkZUQ4R0ALZnSY1dbP5nSZd1E= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=towo.net header.i=towo@towo.net header.a=rsa-sha256 header.s=s1-ionos header.b=bSXwTi6L DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ECAFE4BA23C8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=towo.net; s=s1-ionos; t=1780735210; x=1781340010; i=towo@towo.net; bh=a+wwBXV2HWTA8VUM/5H9/tmBV6S9VKcrwaHKcGNf7yo=; h=X-UI-Sender-Class:Content-Type:Message-ID:Date:MIME-Version: Subject:To:Cc:References:From:In-Reply-To:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=bSXwTi6Ljochd4lsVYozVc9DspTaRGxAUFOf4dpoOY7vCeIF3BFUBarQY6oGWTGX YIYawRF0rjHfAfYTpK2IkXifpBP0DHOrKlwFu6eZ+bemqRSGGlhUib0Q+H1qfp7te b2YRAdtYsUWSIGURFcw42aeK2QXOCq2Sh/uuSO/fQELWtqYQHVmnJdJKQ2vxft3FH Z3SWyROLfNP1qBFlZVIaBcxxY7Mt1xFnNUpnm5X7+9D/YwDwe9lJfk6RQLnUS1tcv /aHglfFhLneIUFj75OZtLizZPmccvypYrMpD1R8jv938hnZYKw9ZPTb9hIcGAmpf0 BVJyOq2N0P3xmKt/EQ== X-UI-Sender-Class: 55c96926-9e95-11ee-ae09-1f7a4046a0f6 Received: from client.hidden.invalid by mrelayeu.kundenserver.de (mreue109 [212.227.15.183]) with ESMTPSA (Nemesis) id 1MTRIg-1whplm20Me-00J3BW; Sat, 06 Jun 2026 10:40:10 +0200 Content-Type: multipart/mixed; boundary="------------kRlK0sa0rOyuJb6xdSKfnYLe" Message-ID: <f8a83c65-1971-44ab-a51c-14d09d89c8ee@towo.net> Date: Sat, 6 Jun 2026 10:40:11 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH] wcwidth: adjust manpage input (Re: [PATCH] fix wcwidth to work with gcc 16 sign extension) To: Jeff Johnston <jjohnstn@redhat.com> Cc: newlib@sourceware.org References: <93dc6225-0cd9-4ce0-b042-3ab88249fb7f@towo.net> <91e5dcbd-0675-4aab-9697-32d71d6d0db2@SystematicSW.ab.ca> <3e90a627-569a-4849-9bf8-424493380308@towo.net> <20260531205733.1b25941ba52273f854c9f8d6@nifty.ne.jp> <f0d3d076-ae16-4346-91e3-cae5476c3697@towo.net> <49097df7-bf9a-4710-8e5a-74765d839791@towo.net> <CAOox84tjVMc+tfbR1E1fLoEf+pgKrPxJUGFbsTSh9jSYQUDBJw@mail.gmail.com> From: Thomas Wolff <towo@towo.net> Autocrypt: addr=towo@towo.net; keydata= xsDNBGNaf3QBDACVevqudcTSevLThXKQPU1QpaDxtGuYjtwmr7i9wXxVGih4Y4oxOJN4PYlu KBX9IVAI4651dA+xYtXuyIkWOPZWyyzkGKavQOn3Q7dk09oj7bh2IwOndpxXXde337D408EQ bQEGbMHr9lOWhSAideowzgCeFIvGTf2AovbPh97HpexJn1/HCRiRAhTNlrkS1DByUgCAeEMK fEr6aGM/Ou29MT+eTnQwOIZTnl9Z9LxM2FtqqMH3MycC7I2OoW3XXhuL8BPQdyJUjWa0/J11 Oo5jFkRXtWenIns6jGn18oW72jnDmo9jXwwS+iZWAV6Y51nhD7jSC+3xs9ORmPCdtHUSpTr1 zh67UueUJ3DUUNVuA25Hn/9EJMJ2L60BGUEr88NEB6pcZhmcwdkurAQeYT6t+frzBz2ctsoN BoxP/Xc02yd+z7hXWRRMrJW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00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, HTML_MESSAGE, KAM_SHORT, RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP, URIBL_BLOCKED shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: newlib@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Newlib mailing list <newlib.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/newlib>, <mailto:newlib-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/newlib/> List-Post: <mailto:newlib@sourceware.org> List-Help: <mailto:newlib-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/newlib>, <mailto:newlib-request@sourceware.org?subject=subscribe> Errors-To: newlib-bounces~patchwork=sourceware.org@sourceware.org |
| Series |
wcwidth: adjust manpage input (Re: [PATCH] fix wcwidth to work with gcc 16 sign extension)
|
|
Commit Message
Thomas Wolff
June 6, 2026, 8:40 a.m. UTC
amending my code patch... sorry I didn't include this right away Am 04.06.2026 um 17:33 schrieb Jeff Johnston: > Patch applied. Thanks. > > -- Jeff J. > > On Tue, Jun 2, 2026 at 8:43 PM Thomas Wolff <towo@towo.net> wrote: > > As discussed in the cygwin thread, I withdraw my previous patch and > provide the attached one to fix wcwidth for gcc 16. > Thomas > > Am 01.06.2026 um 18:02 schrieb Thomas Wolff: > > > > Am 31.05.2026 um 13:57 schrieb Takashi Yano: > >> Hi Thomas, > >> > >> On Sun, 31 May 2026 10:06:12 +0200 > >> Thomas Wolff wrote: > >>> Hi Brian, > >>> > >>> Am 31.05.2026 um 05:50 schrieb Brian Inglis via Cygwin: > >>>> On 2026-05-28 22:58, Thomas Wolff wrote: > >>>>> to make it compliant with newlib and the manual page; > >>>>> fixes cases of wrong width calculation: > >>>>> https://cygwin.com/pipermail/cygwin/2026-April/259597.html > >>>>> as mentioned in > >>>>> https://cygwin.com/pipermail/cygwin/2026-May/259734.html > >>>>> as described in > >>>>> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125451#c14 > >>>>> attachment: > >>>> 0001-wchar.h-tweak-wcwidth-prototype-parameter-wchar_t-wi.patch > >>>> > >>>> The existing wcwidth declaration in > newlib/libc/include/wchar.h agrees > >>>> with > >>>> POSIX 8 SUS V5. > >>>> > >>>> It is the man doc, definition, and implementation in > >>>> newlib/libc/string/wcwidth.c which need changed to match the > >>>> specification and return codes in: > >>>> > >>>> > https://pubs.opengroup.org/onlinepubs/9799919799/functions/wcwidth.html > > >>>> > >>> Your argument overlooks one significant deviation: in POSIX, > wchar_t > >>> has > >>> 32 bits, in cygwin only 16. > >>> So to make wcwidth work for *all* Unicode character code > points, the 32 > >>> bit version must be used. > >>> I tested positively that this fixes the broken test case with > gcc 16 I > >>> had reported to the cygwin list. > >> However, newlib is not used only by Cygwin, so I think newlib > itself > >> should > >> follow POSIX. Shouldn't we have our own wcwidth() > implementation for > >> Cygwin? > >> > >> On second thought, since a 16‑bit wchar_t needs to be converted > to a > >> 32‑bit > >> Unicode code point especially for surrogate pair, we cannot use > >> wcwidth in > >> the same way as Linux does. I wonder what the correct approach > would be. > > I don't there is a "correct" approach as POSIX probably did not > > consider this problem. > > But I just responded to a cute idea on the cygwin mailing list, > which > > was unfeasible but I modified it with a proposal to return width > 1 for > > a high surrogate, remember it, and then return 1 or 0 for the low > > surrogate, respectively. > From b082f9a3108b5c7628a359aa7a636960457e3366 Mon Sep 17 00:00:00 2001 From: Thomas Wolff <towo@towo.net> Date: Sat, 6 Jun 2026 00:00:00 +0000 Subject: [PATCH] wcwidth: adjust manpage source to parameter width patch --- newlib/libc/string/wcwidth.c | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-)
Comments
Patch applied. -- Jeff J. On Sat, Jun 6, 2026 at 4:40 AM Thomas Wolff <towo@towo.net> wrote: > amending my code patch... sorry I didn't include this right away > > Am 04.06.2026 um 17:33 schrieb Jeff Johnston: > > Patch applied. Thanks. > > -- Jeff J. > > On Tue, Jun 2, 2026 at 8:43 PM Thomas Wolff <towo@towo.net> wrote: > >> As discussed in the cygwin thread, I withdraw my previous patch and >> provide the attached one to fix wcwidth for gcc 16. >> Thomas >> >> Am 01.06.2026 um 18:02 schrieb Thomas Wolff: >> > >> > Am 31.05.2026 um 13:57 schrieb Takashi Yano: >> >> Hi Thomas, >> >> >> >> On Sun, 31 May 2026 10:06:12 +0200 >> >> Thomas Wolff wrote: >> >>> Hi Brian, >> >>> >> >>> Am 31.05.2026 um 05:50 schrieb Brian Inglis via Cygwin: >> >>>> On 2026-05-28 22:58, Thomas Wolff wrote: >> >>>>> to make it compliant with newlib and the manual page; >> >>>>> fixes cases of wrong width calculation: >> >>>>> https://cygwin.com/pipermail/cygwin/2026-April/259597.html >> >>>>> as mentioned in >> >>>>> https://cygwin.com/pipermail/cygwin/2026-May/259734.html >> >>>>> as described in >> >>>>> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125451#c14 >> >>>>> attachment: >> >>>> 0001-wchar.h-tweak-wcwidth-prototype-parameter-wchar_t-wi.patch >> >>>> >> >>>> The existing wcwidth declaration in newlib/libc/include/wchar.h >> agrees >> >>>> with >> >>>> POSIX 8 SUS V5. >> >>>> >> >>>> It is the man doc, definition, and implementation in >> >>>> newlib/libc/string/wcwidth.c which need changed to match the >> >>>> specification and return codes in: >> >>>> >> >>>> >> https://pubs.opengroup.org/onlinepubs/9799919799/functions/wcwidth.html >> >>>> >> >>> Your argument overlooks one significant deviation: in POSIX, wchar_t >> >>> has >> >>> 32 bits, in cygwin only 16. >> >>> So to make wcwidth work for *all* Unicode character code points, the >> 32 >> >>> bit version must be used. >> >>> I tested positively that this fixes the broken test case with gcc 16 I >> >>> had reported to the cygwin list. >> >> However, newlib is not used only by Cygwin, so I think newlib itself >> >> should >> >> follow POSIX. Shouldn't we have our own wcwidth() implementation for >> >> Cygwin? >> >> >> >> On second thought, since a 16‑bit wchar_t needs to be converted to a >> >> 32‑bit >> >> Unicode code point especially for surrogate pair, we cannot use >> >> wcwidth in >> >> the same way as Linux does. I wonder what the correct approach would >> be. >> > I don't there is a "correct" approach as POSIX probably did not >> > consider this problem. >> > But I just responded to a cute idea on the cygwin mailing list, which >> > was unfeasible but I modified it with a proposal to return width 1 for >> > a high surrogate, remember it, and then return 1 or 0 for the low >> > surrogate, respectively. >> > >
Patch applied. Thanks. -- Jeff J. On Wed, Jun 10, 2026 at 10:16 AM Jon Turney <jon.turney@dronecode.org.uk> wrote: > On 08/06/2026 22:26, Jeff Johnston wrote: > > Patch applied. > 'make info' chokes on this. > > > MAKEINFO ../../../src/newlib/libc/libc.info > > wcwidth.def:34: misplaced { > > wcwidth.def:36: misplaced } > > wcwidth.def:38: misplaced { > > wcwidth.def:40: misplaced } > > wcwidth.def:44: misplaced { > > wcwidth.def:48: misplaced { > > wcwidth.def:48: misplaced } > > wcwidth.def:49: misplaced } > > I think this is because makedoc does not correctly escape '{' or '}' for > texinfo, outside of a fixed-width font section (which makedoc expects to > be marked-up with '.' or '|'at the start of lines -- see courierize in > makedoc.c) > > That's definitely a shortcoming in makedoc, but since this *is* a code > example, courierize-ing it seems appropriate. > > Patch attached. >
On 10/06/2026 17:44, Jeff Johnston wrote: > Patch applied. Thanks. > > -- Jeff J. > > On Wed, Jun 10, 2026 at 10:16 AM Jon Turney <jon.turney@dronecode.org.uk> > wrote: > >> On 08/06/2026 22:26, Jeff Johnston wrote: >>> Patch applied. >> 'make info' chokes on this. >> >>> MAKEINFO ../../../src/newlib/libc/libc.info >>> wcwidth.def:34: misplaced { >>> wcwidth.def:36: misplaced } >>> wcwidth.def:38: misplaced { >>> wcwidth.def:40: misplaced } >>> wcwidth.def:44: misplaced { >>> wcwidth.def:48: misplaced { >>> wcwidth.def:48: misplaced } >>> wcwidth.def:49: misplaced } >> >> I think this is because makedoc does not correctly escape '{' or '}' for >> texinfo, outside of a fixed-width font section (which makedoc expects to >> be marked-up with '.' or '|'at the start of lines -- see courierize in >> makedoc.c) >> >> That's definitely a shortcoming in makedoc, but since this *is* a code >> example, courierize-ing it seems appropriate. >> >> Patch attached. >> Huh, even now I don't think this is quite what the original patch intended. > +EXAMPLE > + An application function to determine the width of a 21-bit > + Unicode character may look like this: "EXAMPLE" is defined as a command in doc.str, but there are no existing uses of it. It's different to e.g. DESCRIPTION, RETURNS, PORTABILITY etc. in that it doesn't emit a subheading "EXAMPLE", which I imagine is what was expected here. (If you look at the currently generated info page for wcwidth, this example is part of the "RETURNS" subsection at the moment, which doesn't seem right.) I'll send another patch.
diff --git a/newlib/libc/string/wcwidth.c b/newlib/libc/string/wcwidth.c index dfcaa6c21..93cc3e829 100644 --- a/newlib/libc/string/wcwidth.c +++ b/newlib/libc/string/wcwidth.c @@ -7,15 +7,17 @@ INDEX SYNOPSIS #include <wchar.h> - int wcwidth(const wint_t <[wc]>); + int wcwidth(const wchar_t <[wc]>); DESCRIPTION The <<wcwidth>> function shall determine the number of column positions required for the wide character <[wc]>. The application shall ensure that the value of <[wc]> is a character representable - as a wint_t (combining Unicode surrogate pairs into single 21-bit - Unicode code points), and is a wide-character code corresponding to a + as a wchar_t, and is a wide-character code corresponding to a valid character in the current locale. + Note that for a Unicode character outside the 16-bit range, + the application must split it into Unicode surrogates + and use the <<wcswidth>> function instead. RETURNS The <<wcwidth>> function shall either return 0 (if <[wc]> is a null @@ -23,6 +25,30 @@ RETURNS be occupied by the wide-character code <[wc]>, or return -1 (if <[wc]> does not correspond to a printable wide-character code). +EXAMPLE + An application function to determine the width of a 21-bit + Unicode character may look like this: + + typedef unsigned int uchar_t; + // determine high and low surrogates of Unicode character + wchar_t hisurr(uchar_t xc) + { + return 0xD800 | (((xc - 0x10000) >> 10) & 0x3FF); + } + wchar_t losurr(uchar_t xc) + { + return 0xDC00 | (xc & 0x3FF); + } + + // determine width of 21-bit Unicode character + int ucwidth(uchar_t uc) + { + if (uc < 0x10000) + return wcwidth(uc); + else + return wcswidth((wchar_t[]){hisurr(uc), losurr(uc)}, 2); + } + PORTABILITY <<wcwidth>> has been introduced in the Single UNIX Specification Volume 2. <<wcwidth>> has been marked as an extension in the Single UNIX Specification Volume 3. @@ -165,6 +191,8 @@ bisearch(wint_t ucs, const struct interval *table, int max) int __wcwidth (const wint_t ucs) +// unlike wcwidth, the parameter type of __wcwidth must be 32 bits wide +// in order to support wcswidth { #ifdef _MB_CAPABLE /* sorted list of non-overlapping intervals of East Asian Ambiguous chars */