summaryrefslogtreecommitdiff
path: root/testsuite/tests/rts/KeepCafsMain.hs
blob: 2f6ad5a4f98d871da6ed90337c0ea8fc1c00bf4e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
module Main (main) where

import Foreign
import GHCi.ObjLink
import System.Mem
import System.Exit

foreign import ccall "dynamic"
  callGetX :: FunPtr (IO Int) -> IO Int

main :: IO ()
main = do
  initObjLinker DontRetainCAFs
  let
    loadAndCall obj = do
      loadObj obj
      resolveObjs
      r <- lookupSymbol "getX"
      case r of
        Nothing -> die "cannot find getX"
        Just ptr -> callGetX (castPtrToFunPtr ptr) >>= print
      unloadObj obj
      performGC
  loadAndCall "KeepCafs1.o"
  loadAndCall "KeepCafs2.o"