Re: [PATCH] newlib/libc/ctype: Bypass _jp2uc/_uc2jp if _MB_CAPABLE is not set

Corinna Vinschen <[email protected]> Tue, 20 Jan 2026 10:40:01 +0100
Newsgroups gmane.comp.lib.newlib
Message-ID <[email protected]>
Hi Andrew,

On Jan 19 12:03, [email protected] wrote:
> From: Andrew Oates <[email protected]>
> 
> Currently, if an application uses towctrans or towctrans_l with a newlib
> compiled without _MB_CAPABLE, it will fail to link due to _jp2uc/_uc2jp
> being undefined.  This extends the cygwin behavior to all
> non-_MB_CAPABLE builds.

I don't think this is the right thing to do.  Check with other wide-char
functions calling _jp2uc_l, for instance, iswprint_l().  The functions
fall back to the equivalent functions for singlebyte charsets.

Since there's no `toctrans' function, we have to call toupper/tolower
from here.  We can also exlude building the touupper/toulower functions
in the same file, which reduces the footprint of the file for not
_MB_CAPABLE systems.

So I'd propose the following patch instead:


From cb7f1ad1061c8cc55d2ff4b659bbff3395809d90 Mon Sep 17 00:00:00 2001
From: Corinna Vinschen <[email protected]>
Date: Tue, 20 Jan 2026 10:35:20 +0100
Subject: [PATCH] towctrans_l: handle not _MB_CAPABLE targets

towctrans_l neglected to special case systems for which newlib has
been built without _MB_CAPABLE.  Add that code equivalent to other
wide-char functions, calling the singlebyte functions toupper/tolower.
---
 newlib/libc/ctype/towctrans_l.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/newlib/libc/ctype/towctrans_l.c b/newlib/libc/ctype/towctrans_l.c
index b829266a49cd..e94d6f492c8c 100644
--- a/newlib/libc/ctype/towctrans_l.c
+++ b/newlib/libc/ctype/towctrans_l.c
@@ -1,10 +1,13 @@
 /* Modified (m) 2017 Thomas Wolff: revise Unicode and locale/wchar handling */
 #include <_ansi.h>
+#include <ctype.h>
 #include <wctype.h>
 #include <stdint.h>
 //#include <errno.h>
 #include "local.h"
 
+#ifdef _MB_CAPABLE
+
 /*
    struct caseconv_entry describes the case conversion behaviour
    of a range of Unicode characters.
@@ -139,9 +142,12 @@ touupper (wint_t c)
   return c;
 }
 
+#endif /* _MB_CAPABLE */
+
 wint_t
 towctrans_l (wint_t c, wctrans_t w, struct __locale_t *locale)
 {
+#ifdef _MB_CAPABLE
   wint_t u = _jp2uc_l (c, locale);
   wint_t res;
   if (w == WCT_TOLOWER)
@@ -159,4 +165,14 @@ towctrans_l (wint_t c, wctrans_t w, struct __locale_t *locale)
     return _uc2jp_l (res, locale);
   else
     return c;
+#else
+  if (c < (wint_t)0x100)
+    {
+      if (w == WCT_TOLOWER)
+	return tolower (c);
+      if (w == WCT_TOUPPER)
+	return toupper (c);
+    }
+  return c;
+#endif /* _MB_CAPABLE */
 }
-- 
2.52.0