diff options
author | David Allsopp <david.allsopp@metastack.com> | 2020-11-27 09:29:35 +0000 |
---|---|---|
committer | David Allsopp <david.allsopp@metastack.com> | 2020-11-27 14:26:07 +0000 |
commit | cf8a959cbefbd8dbfe9ee31039dc4d68961d7970 (patch) | |
tree | b1de2eee5246c6ab6a7e0545b29926d76f9c1bdc | |
parent | 5b8390bdb25b1a1a6330cbdd5803871790fba11c (diff) | |
download | ocaml-cf8a959cbefbd8dbfe9ee31039dc4d68961d7970.tar.gz |
Define __USE_MINGW_ANSI_STDIO=0 for mingw-w64 (#9939)
The latest mingw-w64 _mingw.h header now automatically sets __USE_MINGW_ANSI_STDIO=1 for C99 and later. mingw-w64 always defines snprintf but the inline definition when __USE_MINGW_ANSI_STDIO=0 temporarily #undef's any snprintf macro so works in harmony with ours. The other case does not do this so we get declaration errors.
Fixes: #9938 .
(cherry picked from commit a03b6035ebe4682950018e0e1337bab18771fd81)
-rw-r--r-- | Changes | 9 | ||||
-rwxr-xr-x | configure | 2 | ||||
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | runtime/caml/config.h | 13 |
4 files changed, 24 insertions, 2 deletions
@@ -1,3 +1,12 @@ +Working version +--------------- + +### Build system: + +- #9938, #9939: Define __USE_MINGW_ANSI_STDIO=0 for the mingw-w64 ports to + prevent their C99-compliant snprintf conflicting with ours. + (David Allsopp, report by Michael Soegtrop, review by Xavier Leroy) + OCaml 4.10.1 (20 August 2020) ----------------------------- @@ -12491,7 +12491,7 @@ case $host in #( internal_cflags="-Wno-unused $gcc_warnings" # TODO: see whether the code can be fixed to avoid -Wno-unused common_cflags="-O -mms-bitfields" - internal_cppflags='-DUNICODE -D_UNICODE' + internal_cppflags='-D__USE_MINGW_ANSI_STDIO=0 -DUNICODE -D_UNICODE' internal_cppflags="$internal_cppflags -DWINDOWS_UNICODE=" internal_cppflags="${internal_cppflags}\$(WINDOWS_UNICODE)" ;; #( *) : diff --git a/configure.ac b/configure.ac index f0987d0aa8..05e9934b1e 100644 --- a/configure.ac +++ b/configure.ac @@ -552,7 +552,7 @@ AS_CASE([$host], [internal_cflags="-Wno-unused $gcc_warnings" # TODO: see whether the code can be fixed to avoid -Wno-unused common_cflags="-O -mms-bitfields" - internal_cppflags='-DUNICODE -D_UNICODE' + internal_cppflags='-D__USE_MINGW_ANSI_STDIO=0 -DUNICODE -D_UNICODE' internal_cppflags="$internal_cppflags -DWINDOWS_UNICODE=" internal_cppflags="${internal_cppflags}\$(WINDOWS_UNICODE)"], [AS_CASE([$ocaml_cv_cc_vendor], diff --git a/runtime/caml/config.h b/runtime/caml/config.h index d1f93bb9c8..03ea4ad9db 100644 --- a/runtime/caml/config.h +++ b/runtime/caml/config.h @@ -59,6 +59,19 @@ #include <stdint.h> #endif +/* Disable the mingw-w64 *printf shims */ +#if defined(CAML_INTERNALS) && defined(__MINGW32__) + /* Headers may have already included <_mingw.h>, so #undef if necessary. */ + #ifdef __USE_MINGW_ANSI_STDIO + #undef __USE_MINGW_ANSI_STDIO + #endif + /* <stdio.h> must either be #include'd before this header or + __USE_MINGW_ANSI_STDIO needs to be 0 when <stdio.h> is processed. The final + effect will be the same - stdio.h will define snprintf and misc.h will make + snprintf a macro (referring to caml_snprintf). */ + #define __USE_MINGW_ANSI_STDIO 0 +#endif + #if defined(__MINGW32__) || (defined(_MSC_VER) && _MSC_VER < 1800) #define ARCH_SIZET_PRINTF_FORMAT "I" #else |