summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Pickering <matthewtpickering@gmail.com>2021-11-04 18:18:30 +0000
committerMatthew Pickering <matthewtpickering@gmail.com>2021-11-04 18:22:23 +0000
commita4545d9fcfbc568472a26ffa03df5a85c2a47718 (patch)
tree466506d7e44278d4f1e4cc77d1f532d18f405958
parenta7e1be3d84d2b7d0515f909175cdfa5dcf0dc55c (diff)
downloadhaskell-wip/t7388.tar.gz
Allow CApi FFI calls in GHCiwip/t7388
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
-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 e056dadc2b..e7d4df472d 100644
--- a/compiler/GHC/StgToByteCode.hs
+++ b/compiler/GHC/StgToByteCode.hs
@@ -1393,6 +1393,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"
@@ -1935,7 +1936,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 80f3eb8f02..4db3ba2f7b 100755
--- a/testsuite/tests/ghci/scripts/all.T
+++ b/testsuite/tests/ghci/scripts/all.T
@@ -346,3 +346,4 @@ test('T20019', normal, ghci_script, ['T20019.script'])
test('T20101', normal, ghci_script, ['T20101.script'])
test('T20206', normal, ghci_script, ['T20206.script'])
test('T20217', normal, ghci_script, ['T20217.script'])
+test('T7388', normal, ghci_script, ['T7388.script'])