Skip to content

Commit

Permalink
Make ioHasBufFS more general
Browse files Browse the repository at this point in the history
The function is now no longer constrained to `PrimBase m`, but any `m` for which
`PrimState m ~ PrimState IO`.
  • Loading branch information
jorisdral committed May 1, 2024
1 parent 3c5b49c commit 351dd51
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
4 changes: 2 additions & 2 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ repository cardano-haskell-packages

index-state:
-- Bump this if you need newer packages from Hackage
, hackage.haskell.org 2024-02-22T20:53:27Z
, hackage.haskell.org 2024-05-01T04:59:38Z
-- Bump this if you need newer packages from CHaP
, cardano-haskell-packages 2024-02-23T09:45:19Z
, cardano-haskell-packages 2024-04-30T19:46:33Z

packages:
fs-api
Expand Down
26 changes: 16 additions & 10 deletions fs-api/src/System/FS/IO.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}

-- | IO implementation of the 'HasFS' class
module System.FS.IO (
-- * IO implementation & monad
Expand All @@ -9,7 +12,7 @@ module System.FS.IO (
import Control.Concurrent.MVar
import qualified Control.Exception as E
import Control.Monad.IO.Class (MonadIO (..))
import Control.Monad.Primitive (PrimBase)
import Control.Monad.Primitive (PrimMonad (..))
import qualified Data.ByteString.Unsafe as BS
import Data.Primitive (withMutableByteArrayContents)
import qualified Data.Set as Set
Expand Down Expand Up @@ -103,19 +106,22 @@ _rethrowFsError mount fp action = do
HasBufFS
-------------------------------------------------------------------------------}

ioHasBufFS :: (MonadIO m, PrimBase m) => MountPoint -> HasBufFS m HandleIO
ioHasBufFS ::
(MonadIO m, PrimState IO ~ PrimState m)
=> MountPoint
-> HasBufFS m HandleIO
ioHasBufFS mount = HasBufFS {
hGetBufSome = \(Handle h fp) buf bufOff c ->
withMutableByteArrayContents buf $ \ptr -> liftIO $ rethrowFsError fp $
hGetBufSome = \(Handle h fp) buf bufOff c -> liftIO $ rethrowFsError fp $
withMutableByteArrayContents buf $ \ptr ->
F.readBuf h (ptr `Foreign.plusPtr` unBufferOffset bufOff) c
, hGetBufSomeAt = \(Handle h fp) buf bufOff c off ->
withMutableByteArrayContents buf $ \ptr -> liftIO $ rethrowFsError fp $
, hGetBufSomeAt = \(Handle h fp) buf bufOff c off -> liftIO $ rethrowFsError fp $
withMutableByteArrayContents buf $ \ptr ->
F.preadBuf h (ptr `Foreign.plusPtr` unBufferOffset bufOff) c (fromIntegral $ unAbsOffset off)
, hPutBufSome = \(Handle h fp) buf bufOff c ->
withMutableByteArrayContents buf $ \ptr -> liftIO $ rethrowFsError fp $
, hPutBufSome = \(Handle h fp) buf bufOff c -> liftIO $ rethrowFsError fp $
withMutableByteArrayContents buf $ \ptr ->
F.writeBuf h (ptr `Foreign.plusPtr` unBufferOffset bufOff) c
, hPutBufSomeAt = \(Handle h fp) buf bufOff c off ->
withMutableByteArrayContents buf $ \ptr -> liftIO $ rethrowFsError fp $
, hPutBufSomeAt = \(Handle h fp) buf bufOff c off -> liftIO $ rethrowFsError fp $
withMutableByteArrayContents buf $ \ptr ->
F.pwriteBuf h (ptr `Foreign.plusPtr` unBufferOffset bufOff) c (fromIntegral $ unAbsOffset off)
}
where
Expand Down

0 comments on commit 351dd51

Please sign in to comment.