From 312258711416c5db2c497e4d4775fc37fa5199b4 Mon Sep 17 00:00:00 2001 From: Adithya Kumar Date: Wed, 4 Dec 2024 17:12:13 +0530 Subject: [PATCH] Fix a bug in unsafeAsForeignPtr --- core/src/Streamly/Internal/Data/Array/Type.hs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/core/src/Streamly/Internal/Data/Array/Type.hs b/core/src/Streamly/Internal/Data/Array/Type.hs index b5e6517903..b8460e4511 100644 --- a/core/src/Streamly/Internal/Data/Array/Type.hs +++ b/core/src/Streamly/Internal/Data/Array/Type.hs @@ -287,12 +287,14 @@ unsafePinnedAsPtr arr f = do {-# INLINE unsafeAsForeignPtr #-} unsafeAsForeignPtr :: MonadIO m => Array a -> (ForeignPtr a -> Int -> m b) -> m b -unsafeAsForeignPtr arr@Array{..} f = - unsafePinnedAsPtr arr finner +unsafeAsForeignPtr arr0 f = do + let marr = unsafeThaw arr0 + pinned <- liftIO $ MA.pin marr + MA.unsafeAsPtr pinned (finner (MA.arrContents pinned)) where - finner (Ptr addr#) i = + finner arrContents_ (Ptr addr#) i = let fptrContents = - PlainPtr (Unboxed.getMutByteArray# arrContents) + PlainPtr (Unboxed.getMutByteArray# arrContents_) fptr = ForeignPtr addr# fptrContents in f fptr i