summaryrefslogtreecommitdiff
path: root/testsuite/tests/ffi/should_run/ffi016.hs
diff options
context:
space:
mode:
Diffstat (limited to 'testsuite/tests/ffi/should_run/ffi016.hs')
-rw-r--r--testsuite/tests/ffi/should_run/ffi016.hs28
1 files changed, 28 insertions, 0 deletions
diff --git a/testsuite/tests/ffi/should_run/ffi016.hs b/testsuite/tests/ffi/should_run/ffi016.hs
new file mode 100644
index 0000000000..0be6f31d7a
--- /dev/null
+++ b/testsuite/tests/ffi/should_run/ffi016.hs
@@ -0,0 +1,28 @@
+-- Tests Foreign.Concurrent finalizers
+
+import Text.Printf
+import Foreign.Concurrent as Conc
+import Foreign
+import GHC.TopHandler
+import Control.Concurrent
+import Data.List
+import System.Mem
+
+-- This finalizer calls back into Haskell, so we can't use
+-- the ordinary newForeignPtr.
+foreign export ccall fin :: Ptr Int -> Ptr Int -> IO ()
+foreign import ccall "fin" finptr :: Ptr Int -> Ptr Int -> IO ()
+
+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 <- Conc.newForeignPtr a (finptr env a)
+ performGC
+ threadDelay 100000