on master help sign in
Add strict eval comments for fromBytes etc.
commita290e6e6ec234c4e25c5758356d336a313150e7b authorHarendra Kumar <harendra@composewell.com> dateTue 9 Jan 2024, 07:50 (3 years ago) parent8e66534
1 file changed+12
core/src/Streamly/Internal/Data/Array/Type.hs+12
core/src/Streamly/Internal/Data/Array/Type.hs+12
@@ -829,13 +829,19 @@ fromPureStream x = unsafePerformIO $ fmap (unsafeFreeze) (MA.fromPureStream x)
829829-- fromPureStream = runIdentity . D.fold (unsafeMakePure write)
830830-- fromPureStream = fromList . runIdentity . D.toList
831831
832+-- XXX This should be monadic.
833+
832834-- | Copy an immutable 'Ptr Word8' sequence into an array.
833835--
834836-- /Unsafe:/ The caller is responsible for safe addressing.
835837--
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.
836840fromPtrN :: Int -> Ptr Word8 -> Array Word8
837841fromPtrN n addr = unsafePerformIO $ fmap unsafeFreeze (MA.fromPtrN n addr)
838842
843+-- XXX This should be monadic.
844+
839845-- | Copy a null terminated immutable 'Addr#' Word8 sequence into an array.
840846--
841847-- /Unsafe:/ The caller is responsible for safe addressing.
@@ -846,9 +852,15 @@ fromPtrN n addr = unsafePerformIO $ fmap unsafeFreeze (MA.fromPtrN n addr)
846852-- >>> Array.toList $ Array.fromByteStr# "\1\2\3\0"#
847853-- [1,2,3]
848854--
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.
849857fromByteStr# :: Addr# -> Array Word8
850858fromByteStr# addr = unsafePerformIO $ fmap unsafeFreeze (MA.fromByteStr# addr)
851859
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.
852864fromByteStr :: Ptr Word8 -> Array Word8
853865fromByteStr (Ptr addr#) = fromByteStr# addr#
854866