Remove Control.Parallel*, now in package parallel
[haskell-directory.git] / Data / Array / Storable.hs
index d336e34..a4aa7dd 100644 (file)
@@ -6,7 +6,7 @@
 -- 
 -- Maintainer  :  libraries@haskell.org
 -- Stability   :  experimental
--- Portability :  non-portable
+-- Portability :  non-portable (uses Data.Array.MArray)
 --
 -- A storable array is an IO-mutable array which stores its
 -- contents in a contiguous memory block living in the C
@@ -34,7 +34,9 @@ module Data.Array.Storable (
     -- * Accessing the pointer to the array contents
     withStorableArray, -- :: StorableArray i e -> (Ptr e -> IO a) -> IO a
     
-    touchStorableArray -- :: StorableArray i e -> IO ()
+    touchStorableArray, -- :: StorableArray i e -> IO ()
+
+    unsafeForeignPtrToStorableArray
     )
     where
 
@@ -47,10 +49,8 @@ import Foreign hiding (newArray)
 -- |The array type
 data StorableArray i e = StorableArray !i !i !(ForeignPtr e)
 
-instance HasBounds StorableArray where
-    bounds (StorableArray l u _) = (l,u)
-
 instance Storable e => MArray StorableArray e IO where
+    getBounds (StorableArray l u _) = return (l,u)
 
     newArray (l,u) init = do
         fp <- mallocForeignPtrArray size
@@ -82,3 +82,11 @@ withStorableArray (StorableArray _ _ fp) f = withForeignPtr fp f
 -- so the array is not freed too early.
 touchStorableArray :: StorableArray i e -> IO ()
 touchStorableArray (StorableArray _ _ fp) = touchForeignPtr fp
+
+-- |Construct a 'StorableArray' from an arbitrary 'ForeignPtr'.  It is
+-- the caller's responsibility to ensure that the 'ForeignPtr' points to
+-- an area of memory sufficient for the specified bounds.
+unsafeForeignPtrToStorableArray 
+   :: ForeignPtr e -> (i,i) -> IO (StorableArray i e)
+unsafeForeignPtrToStorableArray p (l,u) =
+   return (StorableArray l u p)