summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/users_guide/exts/ffi.rst15
-rw-r--r--testsuite/tests/rts/T5423.hs2
-rw-r--r--testsuite/tests/rts/T5423.stdout2
-rw-r--r--testsuite/tests/rts/T5423_c.c28
-rw-r--r--testsuite/tests/rts/T5423_cmm.cmm3
5 files changed, 47 insertions, 3 deletions
diff --git a/docs/users_guide/exts/ffi.rst b/docs/users_guide/exts/ffi.rst
index 1d40017293..e4a91944ef 100644
--- a/docs/users_guide/exts/ffi.rst
+++ b/docs/users_guide/exts/ffi.rst
@@ -83,6 +83,21 @@ For more details on the implementation see the Paper:
Last known to be accessible `here
<https://www.microsoft.com/en-us/research/wp-content/uploads/2004/09/conc-ffi.pdf>`_.
+Varargs not supported by ``ccall`` calling convention
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Note that functions requiring varargs arguments are unsupported by the ``ccall``
+calling convention. Foreign imports needing to call such functions should rather
+use the ``capi`` convention, giving an explicit signature for the needed
+call-pattern. For instance, one could write: ::
+
+ foreign import "capi" "printf"
+ my_printf :: Ptr CChar -> CInt -> IO ()
+
+ printInt :: CInt -> IO ()
+ printInt n = my_printf "printed number %d" n
+
+
.. _ffi-ghcexts:
GHC extensions to the FFI Chapter
diff --git a/testsuite/tests/rts/T5423.hs b/testsuite/tests/rts/T5423.hs
index cda87048d7..f8be97cd6e 100644
--- a/testsuite/tests/rts/T5423.hs
+++ b/testsuite/tests/rts/T5423.hs
@@ -1,3 +1,5 @@
+-- | Verify that @foreign import prim@ calls with more than 10 arguments
+-- are lowered correctly.
{-# LANGUAGE MagicHash, GHCForeignImportPrim, UnliftedFFITypes #-}
diff --git a/testsuite/tests/rts/T5423.stdout b/testsuite/tests/rts/T5423.stdout
index fc92992860..43d0fd4348 100644
--- a/testsuite/tests/rts/T5423.stdout
+++ b/testsuite/tests/rts/T5423.stdout
@@ -1,2 +1,2 @@
-111 112 113 114 115 116 117 118 119 120
+111 112 113 114 115 116 117 118 119 120
120
diff --git a/testsuite/tests/rts/T5423_c.c b/testsuite/tests/rts/T5423_c.c
index efc9c845f5..eddba8741c 100644
--- a/testsuite/tests/rts/T5423_c.c
+++ b/testsuite/tests/rts/T5423_c.c
@@ -1,6 +1,34 @@
+#include <Rts.h>
#include <stdio.h>
void flush_stdout(void)
{
fflush(stdout);
}
+
+void print_it(
+ StgWord r1,
+ StgWord r2,
+ StgWord r3,
+ StgWord r4,
+ StgWord r5,
+ StgWord r6,
+ StgWord r7,
+ StgWord r8,
+ StgWord r9,
+ StgWord r10
+ )
+{
+ printf("%" FMT_Word
+ " %" FMT_Word
+ " %" FMT_Word
+ " %" FMT_Word
+ " %" FMT_Word
+ " %" FMT_Word
+ " %" FMT_Word
+ " %" FMT_Word
+ " %" FMT_Word
+ " %" FMT_Word "\n",
+ r1, r2, r3, r4, r5,
+ r6, r7, r8, r9, r10);
+}
diff --git a/testsuite/tests/rts/T5423_cmm.cmm b/testsuite/tests/rts/T5423_cmm.cmm
index 9be0e152e5..5faa9de0cf 100644
--- a/testsuite/tests/rts/T5423_cmm.cmm
+++ b/testsuite/tests/rts/T5423_cmm.cmm
@@ -10,7 +10,6 @@ test (W_ r1,
W_ r9,
W_ r10)
{
- foreign "C" printf("%d %d %d %d %d %d %d %d %d %d\n",
- r1, r2, r3, r4, r5, r6, r7, r8, r9, r10);
+ foreign "C" print_it(r1, r2, r3, r4, r5, r6, r7, r8, r9, r10);
return (r10);
}