Skip to content

Commit

Permalink
Fix a bug in unsafeAsForeignPtr
Browse files Browse the repository at this point in the history
  • Loading branch information
adithyaov committed Dec 5, 2024
1 parent 0421974 commit 3122587
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions core/src/Streamly/Internal/Data/Array/Type.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 3122587

Please sign in to comment.