Commit 6d6e8483 authored by Simon Marlow's avatar Simon Marlow
Browse files

add test for #1679

parent a159d2d3
{-# LANGUAGE ForeignFunctionInterface #-}
import System.Mem
import Foreign
import Control.Exception
-- Test for #1679. If there's a GC during a foreign call, the
-- interpreter could sometimes crash, because it was using the old
-- pointer to the byte code instructions, which has now moved. The
-- tricky bit is allocating enough so that the old instructions are
-- overwritten, hence performGC followed by sum [1..100000].
foreign import ccall "wrapper" mkF :: IO () -> IO (FunPtr (IO ()))
foreign import ccall "dynamic" call_F :: FunPtr (IO ()) -> IO ()
main = do
fun <- mkF (do performGC
print (sum [1..100000]))
call_F fun
putStrLn "ok"
......@@ -102,3 +102,6 @@ test('ffi018', only_ways(['ghci']), compile_and_run, ['ffi018_ghci_c.o'])
test('ffi019', normal, compile_and_run, [''])
# This one originally failed only GHCi, but doesn't hurt to test all ways.
test('1679', normal, compile_and_run, [''])
Supports Markdown
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