Commit 162d1061 authored by Simon Marlow's avatar Simon Marlow

add test for ForeignPtrEnv

parent 821aa1fd
...@@ -88,3 +88,5 @@ test('ffi014', only_ways(['threaded']), compile_and_run, ['ffi014_cbits.c']) ...@@ -88,3 +88,5 @@ test('ffi014', only_ways(['threaded']), compile_and_run, ['ffi014_cbits.c'])
# GHCi can't handle the separate C file (ToDo: fix this somehow) # GHCi can't handle the separate C file (ToDo: fix this somehow)
test('ffi015', omit_ways(['ghci']), compile_and_run, ['ffi015_cbits.c']) test('ffi015', omit_ways(['ghci']), compile_and_run, ['ffi015_cbits.c'])
test('ffi016', normal, compile_and_run, [''])
-- Tests ForeignPtrEnv finalizers
import Text.Printf
import Foreign.ForeignPtr
import Foreign
import GHC.TopHandler
import Control.Concurrent
foreign export ccall fin :: Ptr Int -> Ptr Int -> IO ()
foreign import ccall "&fin" finptr :: FinalizerEnvPtr Int Int
fin :: Ptr Int -> Ptr Int -> IO ()
fin envp ap = runIO $ do
env <- peek envp
a <- peek ap
printf "%d %d\n" env a
return ()
main = do
a <- new (55 :: Int)
env <- new (66 :: Int)
fp <- newForeignPtrEnv finptr env a
sum [1..1000000] `seq` 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