Commit 0e6382af authored by Simon Marlow's avatar Simon Marlow

add a test for foreign import '&foo' with GHCi

parent 64911328
......@@ -142,3 +142,5 @@ test('2917a', normal, compile_and_run, [''])
test('ffi020', [ omit_ways(['profc','profasm','profthreaded']),
exit_code(1) ], compile_and_run, [''])
test('ffi021', normal, compile_and_run, [''])
{-# LANGUAGE ForeignFunctionInterface #-}
import Foreign
import Foreign.C
-- test for calling functions by importing them by address and then
-- using dynamic calls. In 6.10 and earlier, GHCi rejected the
-- foreign import '&foo' declarations, for no apparently good reason.
type Malloc = CSize -> IO (Ptr ())
type Write = CInt -> Ptr CChar -> CSize -> IO CSize
foreign import ccall unsafe "&malloc" pmalloc:: FunPtr Malloc
foreign import ccall unsafe "dynamic" callMalloc :: FunPtr Malloc -> Malloc
foreign import ccall unsafe "&write" pwrite:: FunPtr Write
foreign import ccall unsafe "dynamic" callWrite :: FunPtr Write -> Write
main = do
p <- callMalloc pmalloc 32
free p
withCStringLen "hello\n" $ \(p,len) -> callWrite pwrite 1 p (fromIntegral len)
return ()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment