Commit 26632047 authored by Simon Marlow's avatar Simon Marlow

add test for an illegal C finalizer callback

parent bd690192
......@@ -137,3 +137,5 @@ test('fptrfail01', [ compose(omit_ways(['ghci']), exit_code(1)),
test('2917a', normal, compile_and_run, [''])
test('ffi020', exit_code(1), compile_and_run, [''])
import Foreign
import Data.Word
import Control.Monad
import System.Mem
main = do
let finalize p = do
putStrLn ("finalize: " ++ show p)
free p
allocToForeignPtr finalize (mallocBytes 4096)
forever performGC
allocToForeignPtr :: (Ptr a -> IO ()) -- finalizer
-> IO (Ptr a) -- allocate
-> IO (ForeignPtr a)
allocToForeignPtr fin alloc = do
done <- asFinalizer fin
newForeignPtr done =<< alloc
asFinalizer :: (Ptr a -> IO ()) -> IO (FinalizerPtr a)
asFinalizer = mkFinalizer
foreign import ccall "wrapper"
mkFinalizer :: (Ptr a -> IO ())
-> IO (FinalizerPtr a)
ffi020: error: a C finalizer called back into Haskell.
This was previously allowed, but is disallowed in GHC 6.10.2 and later.
To create finalizers that may call back into Haskll, use
Foreign.Concurrent.newForeignPtr instead of Foreign.newForeignPtr.
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