Ticket #1357: fpenv.hs

File fpenv.hs, 527 bytes (added by Frederik, 7 years ago)
Line 
1{-# OPTIONS_GHC -ffi #-}
2module Main where
3
4import Foreign.ForeignPtr
5import Foreign.Ptr
6import Foreign.Marshal.Alloc
7import System.Posix.Unistd
8
9--newForeignPtrEnv :: FinalizerEnvPtr env a -> Ptr env -> Ptr a -> IO (ForeignPtr a)
10
11foreign import ccall "null.h fin_test" finalizerTest :: FunPtr (Ptr a -> Ptr a -> IO ())
12
13main = do
14  x <- mallocBytes 5
15  xFP <- newForeignPtrEnv finalizerTest (nullPtr `plusPtr` 135) x
16  putStrLn $ "(x,xFP)="++show(x,xFP)
17  putStrLn $ "stuff="++show(sum $ take (10^6) [1..])
18  putStrLn "done"