summaryrefslogtreecommitdiff
path: root/testsuite/tests/ffi
diff options
context:
space:
mode:
authorRyan Scott <ryan.gl.scott@gmail.com>2022-09-11 13:08:37 -0400
committerMarge Bot <ben+marge-bot@smart-cactus.org>2022-09-12 13:29:41 -0400
commit3a815f30bcba5672085e823aeef90863253b0b1a (patch)
tree24a05e2a5283a93d86e0e88014ff3980a457a30c /testsuite/tests/ffi
parenta5f9c35f5831ef5108e87813a96eac62803852ab (diff)
downloadhaskell-3a815f30bcba5672085e823aeef90863253b0b1a.tar.gz
Windows: Always define _UCRT when compiling C code
As seen in #22159, this is required to ensure correct behavior when MinGW-w64 headers are in the `C_INCLUDE_PATH`. Fixes #22159.
Diffstat (limited to 'testsuite/tests/ffi')
-rw-r--r--testsuite/tests/ffi/should_run/Makefile7
-rw-r--r--testsuite/tests/ffi/should_run/T22159.hs23
-rw-r--r--testsuite/tests/ffi/should_run/T22159.stdout1
-rw-r--r--testsuite/tests/ffi/should_run/T22159_c.c6
-rw-r--r--testsuite/tests/ffi/should_run/all.T5
5 files changed, 42 insertions, 0 deletions
diff --git a/testsuite/tests/ffi/should_run/Makefile b/testsuite/tests/ffi/should_run/Makefile
index cd264113c7..03177f4e8a 100644
--- a/testsuite/tests/ffi/should_run/Makefile
+++ b/testsuite/tests/ffi/should_run/Makefile
@@ -49,3 +49,10 @@ T15933:
'$(TEST_HC)' $(TEST_HC_OPTS) -c T15933.hs
'$(TEST_HC)' $(TEST_HC_OPTS) T15933_c.o T15933.o -o T15933
./T15933
+
+.PHONY: T22159
+T22159:
+ C_INCLUDE_PATH=/mingw64/include '$(TEST_HC)' $(TEST_HC_OPTS) -c T22159.hs
+ C_INCLUDE_PATH=/mingw64/include '$(TEST_HC)' $(TEST_HC_OPTS) -c T22159_c.c
+ C_INCLUDE_PATH=/mingw64/include '$(TEST_HC)' $(TEST_HC_OPTS) T22159.o T22159_c.o -o T22159
+ ./T22159
diff --git a/testsuite/tests/ffi/should_run/T22159.hs b/testsuite/tests/ffi/should_run/T22159.hs
new file mode 100644
index 0000000000..24e9511d3b
--- /dev/null
+++ b/testsuite/tests/ffi/should_run/T22159.hs
@@ -0,0 +1,23 @@
+{-# LANGUAGE CPP #-}
+module Main (main) where
+
+#if defined(i386_HOST_ARCH)
+# define WINDOWS_CCONV stdcall
+#elif defined(x86_64_HOST_ARCH)
+# define WINDOWS_CCONV ccall
+#else
+# error Unknown mingw32 arch
+#endif
+
+import Foreign.C.String (peekCWString)
+import Foreign.C.Types (CWchar)
+import Foreign.Marshal.Alloc (allocaBytes)
+import Foreign.Ptr (Ptr)
+
+foreign import WINDOWS_CCONV "hello" c_hello :: Ptr CWchar -> IO ()
+
+main :: IO ()
+main = allocaBytes 12 $ \buf -> do
+ c_hello buf
+ str <- peekCWString buf
+ putStrLn str
diff --git a/testsuite/tests/ffi/should_run/T22159.stdout b/testsuite/tests/ffi/should_run/T22159.stdout
new file mode 100644
index 0000000000..ce01362503
--- /dev/null
+++ b/testsuite/tests/ffi/should_run/T22159.stdout
@@ -0,0 +1 @@
+hello
diff --git a/testsuite/tests/ffi/should_run/T22159_c.c b/testsuite/tests/ffi/should_run/T22159_c.c
new file mode 100644
index 0000000000..0f0c5df5a0
--- /dev/null
+++ b/testsuite/tests/ffi/should_run/T22159_c.c
@@ -0,0 +1,6 @@
+#include <stdio.h>
+#include <wchar.h>
+
+void hello(wchar_t *buf) {
+ swprintf_s(buf, 12, L"hello");
+}
diff --git a/testsuite/tests/ffi/should_run/all.T b/testsuite/tests/ffi/should_run/all.T
index b6d0a8e1c3..79783c4776 100644
--- a/testsuite/tests/ffi/should_run/all.T
+++ b/testsuite/tests/ffi/should_run/all.T
@@ -229,3 +229,8 @@ test('T19237', normal, compile_and_run, ['T19237_c.c'])
test('T21305', omit_ways(['ghci']), multi_compile_and_run,
['T21305', [('T21305_cmm.cmm', '')], ''])
+
+test('T22159',
+ [unless(opsys('mingw32'), skip),
+ extra_files(['T22159_c.c'])],
+ makefile_test, ['T22159'])