on master help sign in
Merge pull request #3111 from colin-adams/calloc
3398f1cNiklas Larsson
libs/contrib/CFFI/Memory.idr+5−1
@@ -19,6 +19,10 @@ implicit toPtr : CPtr -> Ptr
19toPtr (CPt p 0) = p
19toPtr (CPt p 0) = p
20toPtr (CPt p o) = prim__ptrOffset p o
20toPtr (CPt p o) = prim__ptrOffset p o
21
21
22+||| Import of calloc from the C standard library.
23+calloc : Int -> Int -> IO Ptr
24+calloc nmemb size = foreign FFI_C "calloc" (Int -> Int -> IO Ptr) nmemb size
25+
22||| Import of malloc from the C standard library.
26||| Import of malloc from the C standard library.
23malloc : Int -> IO Ptr
27malloc : Int -> IO Ptr
24malloc size = foreign FFI_C "malloc" (Int -> IO Ptr) size
28malloc size = foreign FFI_C "malloc" (Int -> IO Ptr) size
@@ -29,7 +33,7 @@ mfree ptr = foreign FFI_C "free" (Ptr -> IO ()) ptr
29
33
30||| Allocate enough memory to hold an instance of a C typr
34||| Allocate enough memory to hold an instance of a C typr
31alloc : Composite -> IO CPtr
35alloc : Composite -> IO CPtr
32−alloc t = return $ CPt !(malloc (sizeOf t)) 0
36+alloc t = return $ CPt !(calloc 1 (sizeOf t)) 0
33
37
34||| Free memory allocated with alloc
38||| Free memory allocated with alloc
35free : CPtr -> IO ()
39free : CPtr -> IO ()