nativeMaschine: s/unsigned int/ptrdiff_t/g
[mate.git] / Mate / GarbageAlloc.hs
1 {-# LANGUAGE ForeignFunctionInterface #-}
2 {-# LANGUAGE CPP #-}
3 #include "debug.h"
4 module Mate.GarbageAlloc where
5
6 import Foreign
7 import Foreign.C
8
9 #ifdef DEBUG
10 import Text.Printf
11 #endif
12 import Mate.Debug
13
14 -- unified place for allocating Memory
15 -- TODO: implement GC stuff ;-)
16
17 mallocClassData :: Int -> IO (Ptr a)
18 mallocClassData size = do
19   printfStr "mallocClassData: %d\n" size
20   mallocBytes size
21
22 mallocString :: Int -> IO (Ptr a)
23 mallocString size = do
24   printfStr "mallocString: %d\n" size
25   mallocBytes size
26
27 foreign export ccall mallocObject :: Int -> IO CPtrdiff
28 mallocObject :: Int -> IO CPtrdiff
29 mallocObject size = do
30   ptr <- mallocBytes size
31   printfStr "mallocObject: %d\n" size
32   return $ fromIntegral $ ptrToIntPtr ptr