From add85cc2a3ec0bda810dca2a35264308ffaab069 Mon Sep 17 00:00:00 2001 From: Herbert Valerio Riedel Date: Mon, 16 Oct 2017 19:02:01 +0200 Subject: 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 --- testsuite/tests/ffi/should_run/T9274.hs | 24 ++++++++++++++++++++++++ testsuite/tests/ffi/should_run/T9274.stdout | 1 + testsuite/tests/ffi/should_run/all.T | 2 ++ 3 files changed, 27 insertions(+) create mode 100644 testsuite/tests/ffi/should_run/T9274.hs create mode 100644 testsuite/tests/ffi/should_run/T9274.stdout (limited to 'testsuite/tests/ffi/should_run') 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'), -- cgit v1.2.1