--
Best regards,
Liu Hao
From 72250905c3c1e0e63f8b31140657d8e5aae17543 Mon Sep 17 00:00:00 2001
From: Liu Hao <[email protected]>
Date: Mon, 14 Jun 2021 11:54:29 +0800
Subject: [PATCH] headers/locale: Make result of `localeconv()` accord to GCC's
 `-funsigned-char` option

This enables the old behavior when `-funsigned-char` is specified.

The `selectany` attribute is assumed to be supported since GCC 4.2, and
probably by Clang as well.

This test program should print 127 when `char` is signed and 255 when it
is unsigned:

  #include <stdio.h>
  #include <locale.h>

  int main(void)
    {
      struct lconv* lc = localeconv();
      printf("frac_digits = %d\n", lc->frac_digits);
    }

Reference: https://sourceforge.net/p/mingw-w64/mailman/message/37300502/
Reference: https://gcc.gnu.org/onlinedocs/gcc-4.2.4/gcc/Variable-Attributes.html
Signed-off-by: Liu Hao <[email protected]>
---
 mingw-w64-headers/crt/_mingw_mac.h | 2 ++
 mingw-w64-headers/crt/locale.h     | 6 ++++++
 2 files changed, 8 insertions(+)

diff --git a/mingw-w64-headers/crt/_mingw_mac.h 
b/mingw-w64-headers/crt/_mingw_mac.h
index ca7c89740..ee44fc30c 100644
--- a/mingw-w64-headers/crt/_mingw_mac.h
+++ b/mingw-w64-headers/crt/_mingw_mac.h
@@ -301,6 +301,8 @@
 #  define __mingw_attribute_artificial
 #endif
 
+#define __MINGW_SELECTANY  __attribute__((__selectany__))
+
 #if _FORTIFY_SOURCE > 0 && __OPTIMIZE__ > 0 && __MINGW_GNUC_PREREQ(4, 1)
 #  if _FORTIFY_SOURCE > 1
 #    define __MINGW_FORTIFY_LEVEL 2
diff --git a/mingw-w64-headers/crt/locale.h b/mingw-w64-headers/crt/locale.h
index 6b1893b36..d997200cc 100644
--- a/mingw-w64-headers/crt/locale.h
+++ b/mingw-w64-headers/crt/locale.h
@@ -103,6 +103,12 @@ extern "C" {
   _CRTIMP wchar_t *__cdecl _wsetlocale(int _Category,const wchar_t *_Locale);
 #endif
 
+#ifdef __CHAR_UNSIGNED__
+/* Pull in the constructor from 'charmax.c'.  */
+extern int mingw_initcharmax;
+__MINGW_SELECTANY int* __mingw_reference_charmax = &mingw_initcharmax;
+#endif
+
 #ifdef __cplusplus
 }
 #endif
-- 
2.32.0

Attachment: OpenPGP_signature
Description: OpenPGP digital signature

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

Reply via email to