carray 0.1.6.2 → 0.1.6.3
raw patch · 2 files changed
+13/−8 lines, 2 filesdep ~basePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base
API changes (from Hackage documentation)
Files
- carray.cabal +2/−2
- src/Data/Array/CArray/Base.hs +11/−6
carray.cabal view
@@ -1,5 +1,5 @@ name: carray-version: 0.1.6.2+version: 0.1.6.3 synopsis: A C-compatible array library. description: A C-compatible array library.@@ -21,7 +21,7 @@ Makefile source-repository this- tag: 0.1.6.2+ tag: 0.1.6.3 type: darcs location: http://hub.darcs.net/thielema/carray/
src/Data/Array/CArray/Base.hs view
@@ -60,11 +60,12 @@ import qualified Data.ByteString.Internal as S import Data.Binary (Binary, get, put) -import System.IO.Unsafe (unsafePerformIO)+import System.IO.Unsafe (unsafePerformIO, unsafeDupablePerformIO) import Foreign.Storable (Storable, sizeOf, alignment, peek, peekElemOff, pokeElemOff) import Foreign.ForeignPtr (ForeignPtr, withForeignPtr, castForeignPtr, touchForeignPtr)+import Foreign.ForeignPtr.Unsafe (unsafeForeignPtrToPtr) import Foreign.Marshal.Array (copyArray, withArray) import Foreign.Ptr (plusPtr, alignPtr, castPtr) @@ -167,10 +168,14 @@ go dummy (l,u) | safe = Just (CArray l u n fp) | otherwise = Nothing where n = rangeSize (l,u)- !((ForeignPtr addr contents), off, len) = S.toForeignPtr bs- !p@(Ptr addr') = Ptr addr `plusPtr` off- fp = ForeignPtr addr' contents+ !(fp0, off, len) = S.toForeignPtr bs+ fp = mapPtr (flip plusPtr off) fp0+ p = unsafeForeignPtrToPtr fp safe = sizeOf dummy * n <= len && p == p `alignPtr` alignment dummy+ mapPtr :: (Ptr a -> Ptr b) -> ForeignPtr a -> ForeignPtr b+ mapPtr f (ForeignPtr addr contents) =+ case f $ Ptr addr of+ Ptr addr' -> ForeignPtr addr' contents copy :: (Ix i, Storable e) => CArray i e -> IO (CArray i e) copy ain@(CArray l u n _) =@@ -217,7 +222,7 @@ {-# NOINLINE unsafeArray #-} unsafeArray lu ies = unsafePerformIO $ unsafeArrayCArray lu ies (zeroElem (undefined :: e)) {-# INLINE unsafeAt #-}- unsafeAt (CArray _ _ _ fp) i = S.inlinePerformIO $+ unsafeAt (CArray _ _ _ fp) i = unsafeDupablePerformIO $ withForeignPtr fp $ \a -> peekElemOff a i {-# NOINLINE unsafeReplace #-} unsafeReplace arr ies = unsafePerformIO $ unsafeReplaceCArray arr ies@@ -416,7 +421,7 @@ -- transparency! {-# INLINE mapCArrayInPlace #-} mapCArrayInPlace :: (Ix i, Storable e) => (e -> e) -> CArray i e -> CArray i e-mapCArrayInPlace f a = S.inlinePerformIO $ do+mapCArrayInPlace f a = unsafeDupablePerformIO $ do withCArray a $ \p -> forM_ [0 .. size a - 1] $ \i -> peekElemOff p i >>= pokeElemOff p i . f