Re: [Mingw-w64-public] [PATCH 1/2] headers: Hide UTF-16 and UTF-32 functions from libmsvcrt

2023-04-27 Thread JonY via Mingw-w64-public

On 4/27/23 14:49, LIU Hao wrote:
Basing on some discussion on IRC, I have spit this into two patches. The 
actual removal of these functions will be postponed after this release.




Looks like there was a miscommunication, when I said to hide it from 
UCRT, I was agreeing with you.


I prefer removing it as well if there is no correct implementation 
rather than lull further users from assuming it is working (or link 
tests passing since the symbol is present).


The earlier version of the patch looks good to me, no need to split it, 
I prefer the next release also include the removal.





___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


[Mingw-w64-public] [PATCH 1/2] headers: Hide UTF-16 and UTF-32 functions from libmsvcrt

2023-04-27 Thread LIU Hao
Basing on some discussion on IRC, I have spit this into two patches. The actual removal of these 
functions will be postponed after this release.



--
Best regards,
LIU Hao
From cb01a7df771e7a48d3246cc772674c470a92ff3f Mon Sep 17 00:00:00 2001
From: LIU Hao 
Date: Thu, 27 Apr 2023 22:35:22 +0800
Subject: [PATCH 1/2] headers: Hide UTF-16 and UTF-32 functions from libmsvcrt

While these are standard C11 functions, Microsoft docs say they operate
on strings in UTF-8, instead of strings in the encoding determined by the
current locale. The MSVCRT `mbstate_t`, being an `int`, is too small for
implementations of these functions.

This commit ensures these functions are only declared for UCRT; when
targeting MSVCRT only the typedefs are available. Those incorrect
implementations will be removed in the future.

Reference: 
https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/c16rtomb-c32rtomb1?view=msvc-170
Signed-off-by: LIU Hao 
---
 mingw-w64-headers/crt/uchar.h | 4 
 1 file changed, 4 insertions(+)

diff --git a/mingw-w64-headers/crt/uchar.h b/mingw-w64-headers/crt/uchar.h
index 019f2694f..7c32e7025 100644
--- a/mingw-w64-headers/crt/uchar.h
+++ b/mingw-w64-headers/crt/uchar.h
@@ -47,6 +47,8 @@ typedef uint_least32_t char32_t;
 extern "C" {
 #endif
 
+#ifdef _UCRT
+
 size_t mbrtoc16 (char16_t *__restrict__ pc16,
 const char *__restrict__ s,
 size_t n,
@@ -65,6 +67,8 @@ size_t c32rtomb (char *__restrict__ s,
 char32_t c32,
 mbstate_t *__restrict__ ps);
 
+#endif  /* _UCRT */
+
 #ifdef __cplusplus
 }
 #endif
-- 
2.40.1

From 84dded03b548786ac65acec873ee36d26133dd20 Mon Sep 17 00:00:00 2001
From: LIU Hao 
Date: Thu, 27 Apr 2023 22:45:45 +0800
Subject: [PATCH 2/2] crt: Remove incorrect implementations of UTF-16 and
 UTF-32 functions

As described in cb01a7df771e7a48d3246cc772674c470a92ff3f.

Signed-off-by: LIU Hao 
---
 mingw-w64-crt/Makefile.am   |  4 --
 mingw-w64-crt/misc/uchar_c16rtomb.c | 32 -
 mingw-w64-crt/misc/uchar_c32rtomb.c | 59 ---
 mingw-w64-crt/misc/uchar_mbrtoc16.c | 33 -
 mingw-w64-crt/misc/uchar_mbrtoc32.c | 72 -
 5 files changed, 200 deletions(-)
 delete mode 100644 mingw-w64-crt/misc/uchar_c16rtomb.c
 delete mode 100644 mingw-w64-crt/misc/uchar_c32rtomb.c
 delete mode 100644 mingw-w64-crt/misc/uchar_mbrtoc16.c
 delete mode 100644 mingw-w64-crt/misc/uchar_mbrtoc32.c

diff --git a/mingw-w64-crt/Makefile.am b/mingw-w64-crt/Makefile.am
index 3cf7203e9..0454ecec3 100644
--- a/mingw-w64-crt/Makefile.am
+++ b/mingw-w64-crt/Makefile.am
@@ -174,10 +174,6 @@ src_msvcrt_common=\
   misc/mbsinit.c \
   misc/onexit_table.c \
   misc/register_tls_atexit.c \
-  misc/uchar_c16rtomb.c \
-  misc/uchar_c32rtomb.c \
-  misc/uchar_mbrtoc16.c \
-  misc/uchar_mbrtoc32.c \
   misc/wcrtomb.c \
   stdio/_getc_nolock.c \
   stdio/_getwc_nolock.c \
diff --git a/mingw-w64-crt/misc/uchar_c16rtomb.c 
b/mingw-w64-crt/misc/uchar_c16rtomb.c
deleted file mode 100644
index 94a2aaad0..0
--- a/mingw-w64-crt/misc/uchar_c16rtomb.c
+++ /dev/null
@@ -1,32 +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.
- */
-/* ISO C1x Unicode utilities
- * Based on ISO/IEC SC22/WG14 9899 TR 19769 (SC22 N1326)
- *
- *  THIS SOFTWARE IS NOT COPYRIGHTED
- *
- *  This source code is offered for use in the public domain. You may
- *  use, modify or distribute it freely.
- *
- *  This code is distributed in the hope that it will be useful but
- *  WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
- *  DISCLAIMED. This includes but is not limited to warranties of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- *  Date: 2011-09-27
- */
-
-#include 
-#include 
-
-size_t c16rtomb (char *__restrict__ s,
-char16_t c16,
-mbstate_t *__restrict__ state)
-{
-/* wchar_t should compatible to char16_t on Windows */
-return wcrtomb(s, c16, state);
-}
-
diff --git a/mingw-w64-crt/misc/uchar_c32rtomb.c 
b/mingw-w64-crt/misc/uchar_c32rtomb.c
deleted file mode 100644
index d05e6326f..0
--- a/mingw-w64-crt/misc/uchar_c32rtomb.c
+++ /dev/null
@@ -1,59 +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.
- */
-/* ISO C1x Unicode utilities
- * Based on ISO/IEC SC22/WG14 9899 TR 19769 (SC22 N1326)
- *
- *  THIS SOFTWARE IS NOT COPYRIGHTED
- *
- *  This source code is offered for use in the public domain. You may
- *  use, modify or distribute it freely.
- *
- *  This code is distributed in the hope that it will be useful but
- *  WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY