Skip to content

Commit

Permalink
feat(journal): add smaller failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
symbiont-stevan-andjelkovic committed Jan 13, 2022
1 parent d61e7a2 commit dc98b39
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
8 changes: 8 additions & 0 deletions src/journal/src/Journal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -307,3 +307,11 @@ tj = do
putStrLn ("read bytestring: '" ++ BSChar8.unpack bs ++ "'")
dumpMetadata (jMetadata jour)
return ()

tbc :: IO ()
tbc = do
bb <- allocate 16
bc <- newBufferClaim bb 0 16
putBS bc "helloooooooooooo"
bs <- getByteStringAt bb 0 5
putStrLn (BSChar8.unpack bs)
5 changes: 3 additions & 2 deletions src/journal/src/Journal/Internal/BufferClaim.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ import Foreign.Ptr (Ptr)

import Journal.Internal.ByteBufferPtr
import Journal.Types
import Journal.Internal.Utils

------------------------------------------------------------------------

newtype BufferClaim = BufferClaim ByteBuffer

newBufferClaim :: ByteBuffer -> TermOffset -> Int -> IO BufferClaim
newBufferClaim src offset len = BufferClaim <$>
wrapPart src (fromIntegral offset) len
newBufferClaim src (TermOffset offset) len = BufferClaim <$>
wrapPart src (int322Int offset) len

putBS :: BufferClaim -> ByteString -> IO ()
putBS (BufferClaim bb) bs = putByteString bb bs
Expand Down
8 changes: 4 additions & 4 deletions src/journal/src/Journal/Internal/ByteBufferPtr.hs
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,10 @@ invariant bb = do
------------------------------------------------------------------------
-- * Create

-- allocate :: Int -> IO ByteBuffer
-- allocate capa@(I# capa#) = IO $ \s ->
-- case newPinnedByteArray# capa# s of
-- (# s', mba# #) -> unIO (newByteBuffer mba# (Capacity capa) (Limit capa) 0 Nothing) s'
allocate :: Int -> IO ByteBuffer
allocate size = do
fptr <- mallocForeignPtrBytes size
newByteBuffer fptr (Capacity size) (Limit size) 0 Nothing

allocateAligned :: Int -> Int -> IO ByteBuffer
allocateAligned size align = do
Expand Down

0 comments on commit dc98b39

Please sign in to comment.