summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Pickering <matthewtpickering@gmail.com>2021-11-04 18:18:30 +0000
committerZubin Duggal <zubin.duggal@gmail.com>2022-07-26 16:28:48 +0530
commit42841ac39a0c85bf91e07f368725c4a2c6ac5dc3 (patch)
tree0d4618540bd51fc0c5160453049d6dbe6e2841ee
parentb51d0ead134c56f15eefe088dec3d79e1806045a (diff)
downloadhaskell-42841ac39a0c85bf91e07f368725c4a2c6ac5dc3.tar.gz
Allow CApi FFI calls in GHCi
At some point in the past this started working. I noticed this when working on multiple home units and couldn't load GHC's dependencies into the interpreter. Fixes #7388 (cherry picked from commit be3750a5a3cbc59a7b84f1f7603f308aee1cc80b)
-rw-r--r--compiler/GHC/StgToByteCode.hs3
-rw-r--r--testsuite/tests/ghci/scripts/T7388.hs6
-rw-r--r--testsuite/tests/ghci/scripts/T7388.script2
-rw-r--r--testsuite/tests/ghci/scripts/T7388.stdout1
-rwxr-xr-xtestsuite/tests/ghci/scripts/all.T1
5 files changed, 12 insertions, 1 deletions
diff --git a/compiler/GHC/StgToByteCode.hs b/compiler/GHC/StgToByteCode.hs
index 805362785a..486ea83b64 100644
--- a/compiler/GHC/StgToByteCode.hs
+++ b/compiler/GHC/StgToByteCode.hs
@@ -1567,6 +1567,7 @@ generateCCall d0 s p (CCallSpec target cconv safety) result_ty args_r_to_l
conv = case cconv of
CCallConv -> FFICCall
+ CApiConv -> FFICCall
StdCallConv -> FFIStdCall
_ -> panic "GHC.StgToByteCode: unexpected calling convention"
@@ -2109,7 +2110,7 @@ isSupportedCConv (CCallSpec _ cconv _) = case cconv of
StdCallConv -> True -- convention to ensure that a warning
PrimCallConv -> False -- is triggered when a new one is added
JavaScriptCallConv -> False
- CApiConv -> False
+ CApiConv -> True
-- See bug #10462
unsupportedCConvException :: a
diff --git a/testsuite/tests/ghci/scripts/T7388.hs b/testsuite/tests/ghci/scripts/T7388.hs
new file mode 100644
index 0000000000..91ca1c7268
--- /dev/null
+++ b/testsuite/tests/ghci/scripts/T7388.hs
@@ -0,0 +1,6 @@
+{-# LANGUAGE CApiFFI #-}
+module T7388 where
+
+import Foreign.C
+
+foreign import capi "stdio.h printf" printfb :: CString -> CInt -> IO ()
diff --git a/testsuite/tests/ghci/scripts/T7388.script b/testsuite/tests/ghci/scripts/T7388.script
new file mode 100644
index 0000000000..7f02d86453
--- /dev/null
+++ b/testsuite/tests/ghci/scripts/T7388.script
@@ -0,0 +1,2 @@
+:l T7388
+withCString "I am a working CApi FFI call\n" $ \str -> printfb str 0
diff --git a/testsuite/tests/ghci/scripts/T7388.stdout b/testsuite/tests/ghci/scripts/T7388.stdout
new file mode 100644
index 0000000000..b9ac187b44
--- /dev/null
+++ b/testsuite/tests/ghci/scripts/T7388.stdout
@@ -0,0 +1 @@
+I am a working CApi FFI call
diff --git a/testsuite/tests/ghci/scripts/all.T b/testsuite/tests/ghci/scripts/all.T
index d279da8bae..dc0c619026 100755
--- a/testsuite/tests/ghci/scripts/all.T
+++ b/testsuite/tests/ghci/scripts/all.T
@@ -341,3 +341,4 @@ test('T19650',
ghci_script,
['T19650.script'])
test('T20974', normal, ghci_script, ['T20974.script'])
+test('T7388', normal, ghci_script, ['T7388.script'])