I filed an issue about wctob's sign-extension bug[1].

- Kirill Makurin

[1] 
https://developercommunity.visualstudio.com/t/wctob-sign-extends-its-return-value/10971803
________________________________
From: Kirill Makurin <[email protected]>
Sent: Wednesday, September 24, 2025 8:08 AM
To: Pali Rohár <[email protected]>
Cc: mingw-w64-public <[email protected]>
Subject: Re: [Mingw-w64-public] [PATCH] crt: Remove duplicate files 
ucrt_btowc.c/ucrt_wctob.c and move btowc.c/wctob.c back to libmingwex

This looks good to me. I was recently thinking about btowc and wctob, and I 
think we should report sign-extension bug to Microsoft.

If they eventually fix sign-extension bug in UCRT, this will allow us to:

1. do not compile btowc/wctob for UCRT
2. implement btowc/wctob in terms of MultiByteToWideChar/WideCharToMultiByte as 
it was before

Using MultiByteToWideChar/WideCharToMultiByte should make btowc/wctob somewhat 
faster by removing extra logic hidden in mbrtowc/wcrtomb.

- Kirill Makurin
________________________________
From: Pali Rohár <[email protected]>
Sent: Wednesday, September 24, 2025 3:35 AM
To: [email protected] 
<[email protected]>
Cc: Martin Storsjö <[email protected]>; LIU Hao <[email protected]>; Kirill 
Makurin <[email protected]>
Subject: [PATCH] crt: Remove duplicate files ucrt_btowc.c/ucrt_wctob.c and move 
btowc.c/wctob.c back to libmingwex

Implementation of btowc.c and wctob.c is same for all CRTs except the
mbstate_t structure. Define __LARGE_MBSTATE_T for btowc.c and wctob.c in
the same way as it is used in mingw_pformat.c, mingw_sformat.c and
mingw_swformat.c files to make code compatible with all CRT libs.

This change allows to move btowc.c and wctob.c files back to libmingwex and
compile them only once, like it was before commit 9d00799905c3 ("crt:
always use replacements for btowc and wctob").
---
 mingw-w64-crt/Makefile.am       | 5 +----
 mingw-w64-crt/misc/btowc.c      | 3 +++
 mingw-w64-crt/misc/ucrt_btowc.c | 9 ---------
 mingw-w64-crt/misc/ucrt_wctob.c | 9 ---------
 mingw-w64-crt/misc/wctob.c      | 3 +++
 5 files changed, 7 insertions(+), 22 deletions(-)
 delete mode 100644 mingw-w64-crt/misc/ucrt_btowc.c
 delete mode 100644 mingw-w64-crt/misc/ucrt_wctob.c

diff --git a/mingw-w64-crt/Makefile.am b/mingw-w64-crt/Makefile.am
index afb8aa10ed73..d7e5867404ea 100644
--- a/mingw-w64-crt/Makefile.am
+++ b/mingw-w64-crt/Makefile.am
@@ -168,7 +168,6 @@ src_libws2_32=libsrc/ws2_32.c \
 # Files included in all libmsvcr*.a
 src_msvcrt_common=\
   misc/_onexit.c \
-  misc/btowc.c \
   misc/mbrlen.c \
   misc/mbrtowc.c \
   misc/mbsinit.c \
@@ -177,7 +176,6 @@ src_msvcrt_common=\
   misc/register_tls_atexit.c \
   misc/wcrtomb.c \
   misc/wcsrtombs.c \
-  misc/wctob.c \
   stdio/_getc_nolock.c \
   stdio/_getwc_nolock.c \
   stdio/_putc_nolock.c \
@@ -427,8 +425,6 @@ src_ucrtbase=\
   misc/_onexit.c \
   misc/output_format.c \
   misc/ucrt-access.c \
-  misc/ucrt_btowc.c \
-  misc/ucrt_wctob.c \
   stdio/ucrt___local_stdio_printf_options.c \
   stdio/ucrt___local_stdio_scanf_options.c \
   stdio/ucrt__scprintf.c \
@@ -1138,6 +1134,7 @@ src_libmingwex=\
   misc/wcstof.c \
   misc/wcstold.c \
   misc/wdirent.c         misc/winbs_uint64.c        misc/winbs_ulong.c      
misc/winbs_ushort.c    \
+  misc/btowc.c           misc/wctob.c \
   misc/wmemchr.c         misc/wmemcmp.c             misc/wmemcpy.c          
misc/wmemmove.c              misc/wmempcpy.c        \
   misc/wmemset.c         misc/mingw-access.c \
   misc/ftw32.c           misc/ftw32i64.c            misc/ftw64.c            
misc/ftw64i32.c \
diff --git a/mingw-w64-crt/misc/btowc.c b/mingw-w64-crt/misc/btowc.c
index 2029edc2c7f5..a707abcfae9d 100644
--- a/mingw-w64-crt/misc/btowc.c
+++ b/mingw-w64-crt/misc/btowc.c
@@ -3,6 +3,9 @@
  * This file is part of the mingw-w64 runtime package.
  * No warranty is given; refer to the file DISCLAIMER.PD within this package.
  */
+
+#define __LARGE_MBSTATE_T
+
 #ifndef WIN32_LEAN_AND_MEAN
 #define WIN32_LEAN_AND_MEAN
 #endif
diff --git a/mingw-w64-crt/misc/ucrt_btowc.c b/mingw-w64-crt/misc/ucrt_btowc.c
deleted file mode 100644
index 2424f6e90f1d..000000000000
--- a/mingw-w64-crt/misc/ucrt_btowc.c
+++ /dev/null
@@ -1,9 +0,0 @@
-/**
- * This file has no copyright assigned and is placed in the Public Domain.
- * This file is part of the mingw-w64 runtime package.
- * No warranty is given; refer to the file DISCLAIMER.PD within this package.
- */
-
-#undef __MSVCRT_VERSION__
-#define _UCRT
-#include "btowc.c"
diff --git a/mingw-w64-crt/misc/ucrt_wctob.c b/mingw-w64-crt/misc/ucrt_wctob.c
deleted file mode 100644
index 4e7a1ac9b7ba..000000000000
--- a/mingw-w64-crt/misc/ucrt_wctob.c
+++ /dev/null
@@ -1,9 +0,0 @@
-/**
- * This file has no copyright assigned and is placed in the Public Domain.
- * This file is part of the mingw-w64 runtime package.
- * No warranty is given; refer to the file DISCLAIMER.PD within this package.
- */
-
-#undef __MSVCRT_VERSION__
-#define _UCRT
-#include "wctob.c"
diff --git a/mingw-w64-crt/misc/wctob.c b/mingw-w64-crt/misc/wctob.c
index 57f6170bbfd2..df209be03686 100644
--- a/mingw-w64-crt/misc/wctob.c
+++ b/mingw-w64-crt/misc/wctob.c
@@ -3,6 +3,9 @@
  * This file is part of the mingw-w64 runtime package.
  * No warranty is given; refer to the file DISCLAIMER.PD within this package.
  */
+
+#define __LARGE_MBSTATE_T
+
 #ifndef WIN32_LEAN_AND_MEAN
 #define WIN32_LEAN_AND_MEAN
 #endif
--
2.20.1


_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to