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:34:50 +0000
commitde3ed8407ce3cf63fa41a9d2fe09a8e14c7b53d0 (patch)
tree0436cd2fb2ca572ed48d7f3d3e17b9d04b7fe56d
parent7f4e6944282fe9207f19c3fcfa57f277f0e9fbf4 (diff)
downloadocaml-de3ed8407ce3cf63fa41a9d2fe09a8e14c7b53d0.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--Changes6
-rw-r--r--byterun/caml/config.h13
-rw-r--r--config/Makefile.mingw6
-rw-r--r--config/Makefile.mingw646
4 files changed, 25 insertions, 6 deletions
diff --git a/Changes b/Changes
index 3587d44b78..1d61b45bd3 100644
--- a/Changes
+++ b/Changes
@@ -1,3 +1,9 @@
+Working 4.02.x branch
+---------------------
+
+- #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.02.3:
-------------
diff --git a/byterun/caml/config.h b/byterun/caml/config.h
index 6f608364d6..702c3f9c2f 100644
--- a/byterun/caml/config.h
+++ b/byterun/caml/config.h
@@ -25,6 +25,19 @@
#include "compatibility.h"
#endif
+/* Disable the mingw-w64 *printf shims */
+#ifdef __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
+
/* Types for 32-bit integers, 64-bit integers,
native integers (as wide as a pointer type) */
diff --git a/config/Makefile.mingw b/config/Makefile.mingw
index 5b4658f71b..98f62b6a40 100644
--- a/config/Makefile.mingw
+++ b/config/Makefile.mingw
@@ -93,13 +93,13 @@ GRAPHLIB=win32graph
BYTECC=$(TOOLPREF)gcc
### Additional compile-time options for $(BYTECC). (For static linking.)
-BYTECCCOMPOPTS=-O -mms-bitfields -Wall -Wno-unused
+BYTECCCOMPOPTS=-D__USE_MINGW_ANSI_STDIO=0 -O -mms-bitfields -Wall -Wno-unused
### Additional link-time options for $(BYTECC). (For static linking.)
BYTECCLINKOPTS=
### Additional compile-time options for $(BYTECC). (For building a DLL.)
-DLLCCCOMPOPTS=-O -mms-bitfields -Wall -Wno-unused -DCAML_DLL
+DLLCCCOMPOPTS=-D__USE_MINGW_ANSI_STDIO=0 -O -mms-bitfields -Wall -Wno-unused -DCAML_DLL
### Libraries needed
BYTECCLIBS=-lws2_32
@@ -146,7 +146,7 @@ SYSTEM=mingw
NATIVECC=$(BYTECC)
### Additional compile-time options for $(NATIVECC).
-NATIVECCCOMPOPTS=-O -mms-bitfields -Wall -Wno-unused
+NATIVECCCOMPOPTS=-D__USE_MINGW_ANSI_STDIO=0 -O -mms-bitfields -Wall -Wno-unused
### Additional link-time options for $(NATIVECC)
NATIVECCLINKOPTS=
diff --git a/config/Makefile.mingw64 b/config/Makefile.mingw64
index 19a9b94376..f1c21b0e80 100644
--- a/config/Makefile.mingw64
+++ b/config/Makefile.mingw64
@@ -93,13 +93,13 @@ GRAPHLIB=win32graph
BYTECC=$(TOOLPREF)gcc
### Additional compile-time options for $(BYTECC). (For static linking.)
-BYTECCCOMPOPTS=-O -mms-bitfields -Wall -Wno-unused
+BYTECCCOMPOPTS=-D__USE_MINGW_ANSI_STDIO=0 -O -mms-bitfields -Wall -Wno-unused
### Additional link-time options for $(BYTECC). (For static linking.)
BYTECCLINKOPTS=
### Additional compile-time options for $(BYTECC). (For building a DLL.)
-DLLCCCOMPOPTS=-O -mms-bitfields -Wall -Wno-unused -DCAML_DLL
+DLLCCCOMPOPTS=-D__USE_MINGW_ANSI_STDIO=0 -O -mms-bitfields -Wall -Wno-unused -DCAML_DLL
### Libraries needed
BYTECCLIBS=-lws2_32
@@ -146,7 +146,7 @@ SYSTEM=mingw64
NATIVECC=$(BYTECC)
### Additional compile-time options for $(NATIVECC).
-NATIVECCCOMPOPTS=-O -mms-bitfields -Wall -Wno-unused
+NATIVECCCOMPOPTS=-D__USE_MINGW_ANSI_STDIO=0 -O -mms-bitfields -Wall -Wno-unused
### Additional link-time options for $(NATIVECC)
NATIVECCLINKOPTS=