You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
withForeignPtr :: ForeignPtr a -> (Ptr a -> IO b) -> IO b is a key utility for consuming ForeignPtrs safely. It is expectably common when consuming ByteStrings.
It and its related utilities use the primops
But withForeignPtr is stuck in IO, preventing its use in ST contexts.
(This is probably due to the relevant primops being stuck in the RealWorld until #152 , implemented in GHC 9.8.)
These would be defined in ghc-internal at GHC.Internal.ForeignPtr, together with their IO versions.
My draft implementation below is boring, copied from the existing IO versions with ST swapped in.
withForeignPtrST::ForeignPtra-> (Ptra->STsb) ->STsb
withForeignPtrST fo@(ForeignPtr _ r) f =ST$\s ->case f (unsafeForeignPtrToPtr fo) ofST action#-> keepAlive# r s action#touchForeignPtrST::ForeignPtra->STs()
touchForeignPtrST (ForeignPtr _ r) = touchST r
-- not exportedtouchST::ForeignPtrContents->STs()
touchST r =ST$\s ->case touch# r s of s' -> (# s', ()#)
No breaking changes.
The text was updated successfully, but these errors were encountered:
withForeignPtr :: ForeignPtr a -> (Ptr a -> IO b) -> IO b
is a key utility for consumingForeignPtr
s safely. It is expectably common when consumingByteString
s.It and its related utilities use the primops
But
withForeignPtr
is stuck inIO
, preventing its use inST
contexts.(This is probably due to the relevant primops being stuck in the
RealWorld
until #152 , implemented in GHC 9.8.)I propose the following new functions:
These would be defined in
ghc-internal
atGHC.Internal.ForeignPtr
, together with theirIO
versions.My draft implementation below is boring, copied from the existing
IO
versions withST
swapped in.No breaking changes.
The text was updated successfully, but these errors were encountered: