summaryrefslogtreecommitdiff
path: root/testsuite/tests/ffi
diff options
context:
space:
mode:
authorHerbert Valerio Riedel <hvr@gnu.org>2017-10-16 19:02:01 +0200
committerHerbert Valerio Riedel <hvr@gnu.org>2017-10-16 19:03:11 +0200
commitadd85cc2a3ec0bda810dca2a35264308ffaab069 (patch)
tree13e46f3397433eaa689e58737a928db659c23010 /testsuite/tests/ffi
parent6aa6a86b836efaabcb471894d0b549a2e56703e6 (diff)
downloadhaskell-add85cc2a3ec0bda810dca2a35264308ffaab069.tar.gz
Fix panic for `ByteArray#` arguments in CApiFFI foreign imports
Declarations such as foreign import capi unsafe "string.h strlen" c_strlen_capi :: ByteArray# -> IO CSize foreign import capi unsafe "string.h memset" c_memset_capi :: MutableByteArray# s -> CInt -> CSize -> IO () would cause GHC to panic because the CApiFFI c-wrapper generator didn't know what C type to use for `(Mutable)ByteArray#` types (unlike the `ccall` codepath). This addresses #9274 Reviewed By: bgamari Differential Revision: https://phabricator.haskell.org/D4092
Diffstat (limited to 'testsuite/tests/ffi')
-rw-r--r--testsuite/tests/ffi/should_run/T9274.hs24
-rw-r--r--testsuite/tests/ffi/should_run/T9274.stdout1
-rw-r--r--testsuite/tests/ffi/should_run/all.T2
3 files changed, 27 insertions, 0 deletions
diff --git a/testsuite/tests/ffi/should_run/T9274.hs b/testsuite/tests/ffi/should_run/T9274.hs
new file mode 100644
index 0000000000..814deff093
--- /dev/null
+++ b/testsuite/tests/ffi/should_run/T9274.hs
@@ -0,0 +1,24 @@
+{-# LANGUAGE BangPatterns #-}
+{-# LANGUAGE CApiFFI #-}
+{-# LANGUAGE MagicHash #-}
+{-# LANGUAGE OverloadedStrings #-}
+{-# LANGUAGE UnliftedFFITypes #-}
+
+module Main where
+
+import qualified Data.ByteString.Short.Internal as SBS
+import Foreign.C.Types
+import GHC.Exts
+
+foreign import capi unsafe "string.h strlen"
+ c_strlen_capi :: ByteArray# -> IO CSize
+
+foreign import capi unsafe "string.h memset"
+ c_memset_capi :: MutableByteArray# s -> CInt -> CSize -> IO ()
+
+main :: IO ()
+main = do
+ n <- c_strlen_capi ba#
+ print (n == 13)
+ where
+ !(SBS.SBS ba#) = "Hello FFI!!!!\NUL"
diff --git a/testsuite/tests/ffi/should_run/T9274.stdout b/testsuite/tests/ffi/should_run/T9274.stdout
new file mode 100644
index 0000000000..0ca95142bb
--- /dev/null
+++ b/testsuite/tests/ffi/should_run/T9274.stdout
@@ -0,0 +1 @@
+True
diff --git a/testsuite/tests/ffi/should_run/all.T b/testsuite/tests/ffi/should_run/all.T
index 1bb58c5e49..fd0af7ebc3 100644
--- a/testsuite/tests/ffi/should_run/all.T
+++ b/testsuite/tests/ffi/should_run/all.T
@@ -174,6 +174,8 @@ test('T4012', [expect_broken_for(7388, ['ghci'])], multimod_compile_and_run,
test('T8083', [omit_ways(['ghci'])], compile_and_run, ['T8083_c.c'])
+test('T9274', [omit_ways(['ghci'])], compile_and_run, [''])
+
test('ffi023', [ omit_ways(['ghci']),
extra_clean(['ffi023_c.o']),
extra_run_opts('1000 4'),