1 {-# OPTIONS -fno-implicit-prelude #-}
2 -----------------------------------------------------------------------------
4 -- Module : Foreign.ForeignPtr
5 -- Copyright : (c) The University of Glasgow 2001
6 -- License : BSD-style (see the file libraries/base/LICENSE)
8 -- Maintainer : ffi@haskell.org
9 -- Stability : provisional
10 -- Portability : portable
12 -- The 'ForeignPtr' type and operations. This module is part of the
13 -- Foreign Function Interface (FFI) and will usually be imported via
14 -- the "Foreign" module.
16 -----------------------------------------------------------------------------
18 module Foreign.ForeignPtr
20 -- * Finalised data pointers
23 , addForeignPtrFinalizer
31 , mallocForeignPtrBytes
32 , mallocForeignPtrArray
33 , mallocForeignPtrArray0
42 , addForeignPtrFinalizer
50 #ifdef __GLASGOW_HASKELL__
55 import Hugs.ForeignPtr
59 import Foreign.Storable ( Storable(sizeOf) )
62 #ifdef __GLASGOW_HASKELL__
66 import GHC.Err ( undefined )
70 mallocForeignPtrArray :: Storable a => Int -> IO (ForeignPtr a)
71 mallocForeignPtrArray = doMalloc undefined
73 doMalloc :: Storable a => a -> Int -> IO (ForeignPtr a)
74 doMalloc dummy size = mallocForeignPtrBytes (size * sizeOf dummy)
76 mallocForeignPtrArray0 :: Storable a => Int -> IO (ForeignPtr a)
77 mallocForeignPtrArray0 size = mallocForeignPtrArray (size + 1)