From d95bc90db44a12ac85e71d570735410eb27f6e30 Mon Sep 17 00:00:00 2001 From: simonmar Date: Thu, 21 Apr 2005 09:40:41 +0000 Subject: [PATCH] [project @ 2005-04-21 09:40:41 by simonmar] Add unsafeForeignPtrToStorableArray --- Data/Array/Storable.hs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Data/Array/Storable.hs b/Data/Array/Storable.hs index d336e34..e5ea0be 100644 --- a/Data/Array/Storable.hs +++ b/Data/Array/Storable.hs @@ -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 @@ -82,3 +84,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) -- 1.7.10.4