Wall: remove some warnings
[mate.git] / Mate / GarbageAlloc.hs
1 {-# LANGUAGE ForeignFunctionInterface #-}
2 {-# LANGUAGE CPP #-}
3 #include "debug.h"
4 module Mate.GarbageAlloc(
5     mallocClassData,
6     mallocStringGC,
7     mallocObjectGC,
8     getHeapMemory,
9     printMemoryUsage,
10     printGCStats,
11     mallocObjectUnmanaged,
12     mallocStringUnmanaged)  where
13
14 import Foreign
15 import Foreign.C
16
17 import Mate.GC.Boehm
18
19 #ifdef DBG_STR
20 import Text.Printf
21 #endif
22 import Mate.Debug
23
24 -- unified place for allocating Memory
25 -- TODO: implement GC stuff ;-)
26
27 mallocClassData :: Int -> IO (Ptr a)
28 mallocClassData size = do
29   printfStr "mallocClassData: %d\n" size
30   mem <- mallocBytes size
31   addRootGC mem (plusPtr mem size)
32   return mem
33
34 mallocStringGC :: Int -> IO (Ptr a)
35 mallocStringGC size = do
36   printfStr "mallocString: %d\n" size
37   mallocBytesGC size
38
39 foreign export ccall mallocObjectGC :: Int -> IO CPtrdiff
40 mallocObjectGC :: Int -> IO CPtrdiff
41 mallocObjectGC size = do
42   ptr <- mallocBytesGC size
43   printfStr "mallocObject: %d\n" size
44   return $ fromIntegral $ ptrToIntPtr ptr
45
46 mallocObjectUnmanaged :: Int -> IO CPtrdiff
47 mallocObjectUnmanaged size = do
48   ptr <- mallocBytes size
49   printfStr "mallocObjectUnmanged: %d\n" size
50   return $ fromIntegral $ ptrToIntPtr ptr
51
52 mallocStringUnmanaged :: Int -> IO (Ptr a)
53 mallocStringUnmanaged size = do
54   printfStr "mallocStringUnamaged: %d\n" size
55   mallocBytes size
56
57
58 getHeapMemory :: IO Int
59 getHeapMemory = getHeapSizeGC
60
61 foreign export ccall printMemoryUsage :: IO ()
62 printMemoryUsage :: IO ()
63 printMemoryUsage = getHeapMemory >>= print
64
65 foreign export ccall printGCStats :: IO ()
66 printGCStats :: IO ()
67 printGCStats = putStrLn "Should print GC Stats"