summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Allsopp <david.allsopp@metastack.com>2020-11-27 09:29:35 +0000
committerDavid Allsopp <david.allsopp@metastack.com>2020-11-27 16:22:22 +0000
commit49e63a406b9f410ccddc48c7aac1e21e25f26b32 (patch)
treeec5d8ec198092722290e028937ead6643c23a01c
parent12ef11225a5242f41bac8b47e5e1f6b578fd6f33 (diff)
downloadocaml-49e63a406b9f410ccddc48c7aac1e21e25f26b32.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--Changes4
-rw-r--r--byterun/caml/config.h13
-rw-r--r--config/Makefile.mingw2
-rw-r--r--config/Makefile.mingw642
4 files changed, 19 insertions, 2 deletions
diff --git a/Changes b/Changes
index 941d5bbf27..6caf2435c8 100644
--- a/Changes
+++ b/Changes
@@ -4,6 +4,10 @@ OCaml 4.07 maintenance branch
- #9383: Don't assume that AWKPATH includes .
(David Allsopp, report by Ian Zimmerman)
+- #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.07.1 (4 October 2018)
-----------------------------
diff --git a/byterun/caml/config.h b/byterun/caml/config.h
index 0dba12adcd..d0db4097da 100644
--- a/byterun/caml/config.h
+++ b/byterun/caml/config.h
@@ -35,6 +35,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
+
#ifndef ARCH_SIZET_PRINTF_FORMAT
#define ARCH_SIZET_PRINTF_FORMAT "z"
#endif
diff --git a/config/Makefile.mingw b/config/Makefile.mingw
index 3f1eb9b42e..f6a578afa8 100644
--- a/config/Makefile.mingw
+++ b/config/Makefile.mingw
@@ -116,7 +116,7 @@ CC=$(TOOLPREF)gcc
CFLAGS=-O -mms-bitfields -Wall -Wno-unused -fno-tree-vrp
# -fno-tree-vrp is here to try to work around the Skylake/Kaby lake bug,
# and only works on GCC 4.2 and later.
-CPPFLAGS=-DCAML_NAME_SPACE -DUNICODE -D_UNICODE -DWINDOWS_UNICODE=$(WINDOWS_UNICODE)
+CPPFLAGS=-DCAML_NAME_SPACE -D__USE_MINGW_ANSI_STDIO=0 -DUNICODE -D_UNICODE -DWINDOWS_UNICODE=$(WINDOWS_UNICODE)
OCAMLC_CFLAGS=-O -mms-bitfields
BYTECCDBGCOMPOPTS=-g
diff --git a/config/Makefile.mingw64 b/config/Makefile.mingw64
index df605a9f5a..5dc5799c0f 100644
--- a/config/Makefile.mingw64
+++ b/config/Makefile.mingw64
@@ -116,7 +116,7 @@ CC=$(TOOLPREF)gcc
CFLAGS=-O -mms-bitfields -Wall -Wno-unused -fno-tree-vrp
# -fno-tree-vrp is here to try to work around the Skylake/Kaby lake bug,
# and only works on GCC 4.2 and later.
-CPPFLAGS=-DCAML_NAME_SPACE -DUNICODE -D_UNICODE -DWINDOWS_UNICODE=$(WINDOWS_UNICODE)
+CPPFLAGS=-DCAML_NAME_SPACE -D__USE_MINGW_ANSI_STDIO=0 -DUNICODE -D_UNICODE -DWINDOWS_UNICODE=$(WINDOWS_UNICODE)
OCAMLC_CFLAGS=-O -mms-bitfields
BYTECCDBGCOMPOPTS=-g