W dniu 01.11.2018 o 14:16, JonY pisze:
> On 11/01/2018 01:52 AM, Mateusz wrote:
>> During discussion about inttypes I realized that we check (in header files) 
>> if
>> __USE_MINGW_ANSI_STDIO is active in non consistent way:
>> #if defined(__USE_MINGW_ANSI_STDIO) && ((__USE_MINGW_ANSI_STDIO + 0) != 0)
>> #elif defined(__USE_MINGW_ANSI_STDIO)
>> #if !defined (__USE_MINGW_ANSI_STDIO) || __USE_MINGW_ANSI_STDIO == 0
>>
>> Attached patch simplified checking if __USE_MINGW_ANSI_STDIO is active -- it
>> always define __USE_MINGW_ANSI_STDIO to 0 or 1 in _mingw.h so now it should 
>> be
>> simple:
>> #if __USE_MINGW_ANSI_STDIO /* active */
>> #if __USE_MINGW_ANSI_STDIO == 0 /* not active */
>>
>> Please review.
>>
>> Regards,
>> Mateusz
>>
> 
> 
> Patch looks good to me.

I've attached new version of this patch that works with current tip.

I've added patch 0002 that sets printf format attribute according to new logic 
in inttypes.h.

Regards,
Mateusz
From 7fc7776a0b8ee9489f226eca2bdaad15d22032f3 Mon Sep 17 00:00:00 2001
From: Mateusz <[email protected]>
Date: Fri, 2 Nov 2018 21:01:43 +0100
Subject: [PATCH 1/2] Always define __USE_MINGW_ANSI_STDIO as 0 or 1 in
 _mingw.h

We check state of __USE_MINGW_ANSI_STDIO in many places.
This patch checks all corner cases for __USE_MINGW_ANSI_STDIO
in one place in _mingw.h and then we have easy and consistent check
-- it is 0 or 1.

Signed-off-by: Mateusz Brzostek <[email protected]>
---
 mingw-w64-headers/crt/_mingw.h.in | 9 +++++++++
 mingw-w64-headers/crt/inttypes.h  | 2 +-
 mingw-w64-headers/crt/stdio.h     | 8 ++++----
 mingw-w64-headers/crt/stdlib.h    | 2 +-
 mingw-w64-headers/crt/wchar.h     | 6 +++---
 5 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/mingw-w64-headers/crt/_mingw.h.in 
b/mingw-w64-headers/crt/_mingw.h.in
index bbbd07d0..c6b9d760 100644
--- a/mingw-w64-headers/crt/_mingw.h.in
+++ b/mingw-w64-headers/crt/_mingw.h.in
@@ -428,6 +428,15 @@ typedef int __int128 __attribute__ ((__mode__ (TI)));
 #  define __USE_MINGW_ANSI_STDIO                       1
 #endif
 
+/* We are defining __USE_MINGW_ANSI_STDIO as 0 or 1 */
+#if !defined(__USE_MINGW_ANSI_STDIO)
+#define __USE_MINGW_ANSI_STDIO 0      /* was not defined so it should be 0 */
+#elif (__USE_MINGW_ANSI_STDIO + 0) != 0 || (1 - __USE_MINGW_ANSI_STDIO - 1) == 
2
+#define __USE_MINGW_ANSI_STDIO 1      /* was defined as nonzero or empty so it 
should be 1 */
+#else
+#define __USE_MINGW_ANSI_STDIO 0      /* was defined as (int)zero and 
non-empty so it should be 0 */
+#endif
+
 /* _dowildcard is an int that controls the globbing of the command line.
  * The MinGW32 (mingw.org) runtime calls it _CRT_glob, so we are adding
  * a compatibility definition here:  you can use either of _CRT_glob or
diff --git a/mingw-w64-headers/crt/inttypes.h b/mingw-w64-headers/crt/inttypes.h
index 500df7de..23dcd42c 100644
--- a/mingw-w64-headers/crt/inttypes.h
+++ b/mingw-w64-headers/crt/inttypes.h
@@ -29,7 +29,7 @@ typedef struct {
  * The non-standard I64 length specifier causes warning in GCC,
  * but understood by MS runtime functions.
  */
-#if __MSVCRT_VERSION__ >= 0x1400 || (defined(__USE_MINGW_ANSI_STDIO) && 
((__USE_MINGW_ANSI_STDIO + 0) != 0))
+#if __MSVCRT_VERSION__ >= 0x1400 || __USE_MINGW_ANSI_STDIO
 #define PRId64 "lld"
 #define PRIi64 "lli"
 #define PRIo64 "llo"
diff --git a/mingw-w64-headers/crt/stdio.h b/mingw-w64-headers/crt/stdio.h
index d0659238..e412b2d9 100644
--- a/mingw-w64-headers/crt/stdio.h
+++ b/mingw-w64-headers/crt/stdio.h
@@ -221,7 +221,7 @@ extern
 #if defined(__clang__)
 #define __MINGW_PRINTF_FORMAT printf
 #define __MINGW_SCANF_FORMAT  scanf
-#elif defined(__USE_MINGW_ANSI_STDIO)
+#elif __USE_MINGW_ANSI_STDIO
 #define __MINGW_PRINTF_FORMAT gnu_printf
 #define __MINGW_SCANF_FORMAT  gnu_scanf
 #else
@@ -735,7 +735,7 @@ int vsnprintf (char *__stream, size_t __n, const char 
*__format, __builtin_va_li
   _CRTIMP int __cdecl _vsnprintf(char * __restrict__ _Dest,size_t _Count,const 
char * __restrict__ _Format,va_list _Args) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
 #endif
 
-#if !defined (__USE_MINGW_ANSI_STDIO) || __USE_MINGW_ANSI_STDIO == 0
+#if __USE_MINGW_ANSI_STDIO == 0
 
 #if __MSVCRT_VERSION__ >= 0x1400
 #ifdef __GNUC__
@@ -1140,7 +1140,7 @@ int vsnwprintf (wchar_t *__stream, size_t __n, const 
wchar_t *__format, __builti
   }
   int __cdecl _vsnwprintf(wchar_t * __restrict__ _Dest,size_t _Count,const 
wchar_t * __restrict__ _Format,va_list _Args) 
__MINGW_ATTRIB_DEPRECATED_SEC_WARN;
 
-#if !defined (__USE_MINGW_ANSI_STDIO) || __USE_MINGW_ANSI_STDIO == 0
+#if __USE_MINGW_ANSI_STDIO == 0
   __mingw_ovr
   int snwprintf (wchar_t * __restrict__ s, size_t n, const wchar_t * 
__restrict__ format, ...)
   {
@@ -1190,7 +1190,7 @@ int vsnwprintf (wchar_t *__stream, size_t __n, const 
wchar_t *__format, __builti
 
 #ifndef __NO_ISOCEXT  /* externs in libmingwex.a */
 
-#if !defined (__USE_MINGW_ANSI_STDIO) || __USE_MINGW_ANSI_STDIO == 0
+#if __USE_MINGW_ANSI_STDIO == 0
 #pragma push_macro("snwprintf")
 #pragma push_macro("vsnwprintf")
 # undef snwprintf
diff --git a/mingw-w64-headers/crt/stdlib.h b/mingw-w64-headers/crt/stdlib.h
index 4d9c1d96..22b53b90 100644
--- a/mingw-w64-headers/crt/stdlib.h
+++ b/mingw-w64-headers/crt/stdlib.h
@@ -9,7 +9,7 @@
 #include <crtdefs.h>
 #include <limits.h>
 
-#if defined (__USE_MINGW_ANSI_STDIO) && ((__USE_MINGW_ANSI_STDIO + 0) != 0) && 
!defined (__USE_MINGW_STRTOX)
+#if __USE_MINGW_ANSI_STDIO && !defined (__USE_MINGW_STRTOX)
 #define __USE_MINGW_STRTOX 1
 #endif
 
diff --git a/mingw-w64-headers/crt/wchar.h b/mingw-w64-headers/crt/wchar.h
index 3b79a89e..53f556dd 100644
--- a/mingw-w64-headers/crt/wchar.h
+++ b/mingw-w64-headers/crt/wchar.h
@@ -8,7 +8,7 @@
 
 #include <crtdefs.h>
 
-#if defined (__USE_MINGW_ANSI_STDIO) && ((__USE_MINGW_ANSI_STDIO + 0) != 0) && 
!defined (__USE_MINGW_STRTOX)
+#if __USE_MINGW_ANSI_STDIO && !defined (__USE_MINGW_STRTOX)
 #define __USE_MINGW_STRTOX 1
 #endif
 
@@ -808,7 +808,7 @@ int vsnwprintf (wchar_t *__stream, size_t __n, const 
wchar_t *__format, __builti
     return __stdio_common_vswprintf(UCRTBASE_PRINTF_DEFAULT_WIDE | 
UCRTBASE_PRINTF_LEGACY_VSPRINTF_NULL_TERMINATION, _Dest, _Count, _Format, NULL, 
_Args);
   }
 
-#if !defined (__USE_MINGW_ANSI_STDIO) || __USE_MINGW_ANSI_STDIO == 0
+#if __USE_MINGW_ANSI_STDIO == 0
   __mingw_ovr
   int snwprintf (wchar_t * __restrict__ s, size_t n, const wchar_t * 
__restrict__ format, ...)
   {
@@ -836,7 +836,7 @@ int vsnwprintf (wchar_t *__stream, size_t __n, const 
wchar_t *__format, __builti
 
 #ifndef __NO_ISOCEXT  /* externs in libmingwex.a */
 
-#if !defined (__USE_MINGW_ANSI_STDIO) || __USE_MINGW_ANSI_STDIO == 0
+#if __USE_MINGW_ANSI_STDIO == 0
 #pragma push_macro("snwprintf")
 #pragma push_macro("vsnwprintf")
 # undef snwprintf
-- 
2.19.1.windows.1

From a62b85a05b62eaee357db9ada30f31882b830df4 Mon Sep 17 00:00:00 2001
From: Mateusz <[email protected]>
Date: Fri, 2 Nov 2018 21:07:04 +0100
Subject: [PATCH 2/2] stdio.h: set printf format attribute according to
 inttypes.h

Signed-off-by: Mateusz Brzostek <[email protected]>
---
 mingw-w64-headers/crt/stdio.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mingw-w64-headers/crt/stdio.h b/mingw-w64-headers/crt/stdio.h
index e412b2d9..c79d7054 100644
--- a/mingw-w64-headers/crt/stdio.h
+++ b/mingw-w64-headers/crt/stdio.h
@@ -221,7 +221,7 @@ extern
 #if defined(__clang__)
 #define __MINGW_PRINTF_FORMAT printf
 #define __MINGW_SCANF_FORMAT  scanf
-#elif __USE_MINGW_ANSI_STDIO
+#elif __MSVCRT_VERSION__ >= 0x1400 || __USE_MINGW_ANSI_STDIO
 #define __MINGW_PRINTF_FORMAT gnu_printf
 #define __MINGW_SCANF_FORMAT  gnu_scanf
 #else
-- 
2.19.1.windows.1

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

Reply via email to