on master help sign in
Add strict eval comments for fromBytes etc.
a290e6eHarendra Kumar
core/src/Streamly/Internal/Data/Array/Type.hs+12
@@ -829,13 +829,19 @@ fromPureStream x = unsafePerformIO $ fmap (unsafeFreeze) (MA.fromPureStream x)
829-- fromPureStream = runIdentity . D.fold (unsafeMakePure write)
829-- fromPureStream = runIdentity . D.fold (unsafeMakePure write)
830-- fromPureStream = fromList . runIdentity . D.toList
830-- fromPureStream = fromList . runIdentity . D.toList
831
831
832+-- XXX This should be monadic.
833+
832-- | Copy an immutable 'Ptr Word8' sequence into an array.
834-- | Copy an immutable 'Ptr Word8' sequence into an array.
833--
835--
834-- /Unsafe:/ The caller is responsible for safe addressing.
836-- /Unsafe:/ The caller is responsible for safe addressing.
835--
837--
838+-- Note that this should be evaluated strictly to ensure that we do not hold
839+-- the reference to the pointer in a lazy thunk.
836fromPtrN :: Int -> Ptr Word8 -> Array Word8
840fromPtrN :: Int -> Ptr Word8 -> Array Word8
837fromPtrN n addr = unsafePerformIO $ fmap unsafeFreeze (MA.fromPtrN n addr)
841fromPtrN n addr = unsafePerformIO $ fmap unsafeFreeze (MA.fromPtrN n addr)
838
842
843+-- XXX This should be monadic.
844+
839-- | Copy a null terminated immutable 'Addr#' Word8 sequence into an array.
845-- | Copy a null terminated immutable 'Addr#' Word8 sequence into an array.
840--
846--
841-- /Unsafe:/ The caller is responsible for safe addressing.
847-- /Unsafe:/ The caller is responsible for safe addressing.
@@ -846,9 +852,15 @@ fromPtrN n addr = unsafePerformIO $ fmap unsafeFreeze (MA.fromPtrN n addr)
846-- >>> Array.toList $ Array.fromByteStr# "\1\2\3\0"#
852-- >>> Array.toList $ Array.fromByteStr# "\1\2\3\0"#
847-- [1,2,3]
853-- [1,2,3]
848--
854--
855+-- Note that this should be evaluated strictly to ensure that we do not hold
856+-- the reference to the pointer in a lazy thunk.
849fromByteStr# :: Addr# -> Array Word8
857fromByteStr# :: Addr# -> Array Word8
850fromByteStr# addr = unsafePerformIO $ fmap unsafeFreeze (MA.fromByteStr# addr)
858fromByteStr# addr = unsafePerformIO $ fmap unsafeFreeze (MA.fromByteStr# addr)
851
859
860+-- XXX This should be monadic.
861+
862+-- | Note that this should be evaluated strictly to ensure that we do not hold
863+-- the reference to the pointer in a lazy thunk.
852fromByteStr :: Ptr Word8 -> Array Word8
864fromByteStr :: Ptr Word8 -> Array Word8
853fromByteStr (Ptr addr#) = fromByteStr# addr#
865fromByteStr (Ptr addr#) = fromByteStr# addr#
854
866