packages feed

network-byte-order 0.1.3.0 → 0.1.4.0

raw patch · 2 files changed

+39/−40 lines, 2 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

Network/ByteOrder.hs view
@@ -69,6 +69,7 @@   ) where  import Control.Exception (bracket, throwIO, Exception)+import Control.Monad (when) import Data.Bits (shiftR, shiftL, (.&.), (.|.)) import Data.ByteString.Internal (ByteString(..), create, memcpy, ByteString(..), unsafeCreate) import Data.ByteString.Short (ShortByteString)@@ -378,11 +379,9 @@ write8 WriteBuffer{..} w = do     ptr <- readIORef offset     let ptr' = ptr `plusPtr` 1-    if ptr' > limit then-        throwIO BufferOverrun-      else do-        poke ptr w-        writeIORef offset ptr'+    when (ptr' > limit) $ throwIO BufferOverrun+    poke ptr w+    writeIORef offset ptr'  {-# INLINE write16 #-} -- | Write two bytes and ff one byte.@@ -394,11 +393,9 @@ write16 WriteBuffer{..} w = do     ptr <- readIORef offset     let ptr' = ptr `plusPtr` 2-    if ptr' > limit then-        throwIO BufferOverrun-      else do-        poke16 w ptr 0-        writeIORef offset ptr'+    when (ptr' > limit) $ throwIO BufferOverrun+    poke16 w ptr 0+    writeIORef offset ptr'  {-# INLINE write24 #-} -- | Write three bytes and ff one byte.@@ -410,11 +407,9 @@ write24 WriteBuffer{..} w = do     ptr <- readIORef offset     let ptr' = ptr `plusPtr` 3-    if ptr' > limit then-        throwIO BufferOverrun-      else do-        poke24 w ptr 0-        writeIORef offset ptr'+    when (ptr' > limit) $ throwIO BufferOverrun+    poke24 w ptr 0+    writeIORef offset ptr'  {-# INLINE write32 #-} -- | Write four bytes and ff one byte.@@ -426,11 +421,9 @@ write32 WriteBuffer{..} w = do     ptr <- readIORef offset     let ptr' = ptr `plusPtr` 4-    if ptr' > limit then-        throwIO BufferOverrun-      else do-        poke32 w ptr 0-        writeIORef offset ptr'+    when (ptr' > limit) $ throwIO BufferOverrun+    poke32 w ptr 0+    writeIORef offset ptr'  {-# INLINE write64 #-} -- | Write four bytes and ff one byte.@@ -439,11 +432,9 @@ write64 WriteBuffer{..} w = do     ptr <- readIORef offset     let ptr' = ptr `plusPtr` 8-    if ptr' > limit then-        throwIO BufferOverrun-      else do-        poke64 w ptr 0-        writeIORef offset ptr'+    when (ptr' > limit) $ throwIO BufferOverrun+    poke64 w ptr 0+    writeIORef offset ptr'  {-# INLINE shiftLastN #-} -- | Shifting the N-bytes area just before the current pointer (the 3rd argument).@@ -462,9 +453,8 @@ shiftLastN WriteBuffer{..} i len = do     ptr <- readIORef offset     let ptr' = ptr `plusPtr` i-    if ptr' >= limit then-        throwIO BufferOverrun-      else if i < 0 then do+    when (ptr' >= limit) $ throwIO BufferOverrun+    if i < 0 then do         let src = ptr `plusPtr` negate len             dst = src `plusPtr` i         shiftLeft dst src len@@ -498,11 +488,9 @@     let src = ptr `plusPtr` off     dst <- readIORef offset     let dst' = dst `plusPtr` len-    if dst' > limit then-        throwIO BufferOverrun-      else do-        memcpy dst src len-        writeIORef offset dst'+    when (dst' > limit) $ throwIO BufferOverrun+    memcpy dst src len+    writeIORef offset dst'  -- | Copy the content of 'ShortByteString' and ff its length. --   If buffer overrun occurs, 'BufferOverrun' is thrown.@@ -514,11 +502,9 @@     dst <- readIORef offset     let len = Short.length sbs     let dst' = dst `plusPtr` len-    if dst' > limit then-        throwIO BufferOverrun-      else do-        Short.copyToPtr sbs 0 dst len-        writeIORef offset dst'+    when (dst' > limit) $ throwIO BufferOverrun+    Short.copyToPtr sbs 0 dst len+    writeIORef offset dst'  -- | Copy the area from 'start' to the current pointer to 'ByteString'. toByteString :: WriteBuffer -> IO ByteString@@ -580,8 +566,10 @@     {-# INLINE read8 #-}     read8 WriteBuffer{..} = do         ptr <- readIORef offset+        let ptr' = ptr `plusPtr` 1+        when (ptr' > limit) $ throwIO BufferOverrun         w <- peek ptr-        writeIORef offset $ ptr `plusPtr` 1+        writeIORef offset ptr'         return w     {-# INLINE readInt8 #-}     readInt8 WriteBuffer{..} = do@@ -658,6 +646,7 @@ extractByteString rbuf len   | len == 0 = return mempty   | len >  0 = do+    checkR rbuf len     bs <- withCurrentOffSet rbuf $ \src ->         create len $ \dst -> memcpy dst src len     ff rbuf len@@ -679,6 +668,7 @@ extractShortByteString rbuf len   | len == 0 = return mempty   | len >  0 = do+    checkR rbuf len     sbs <- withCurrentOffSet rbuf $ \src -> Short.createFromPtr src len     ff rbuf len     return sbs@@ -693,6 +683,7 @@ -- 1 read16 :: Readable a => a -> IO Word16 read16 rbuf = do+    checkR rbuf 2     w16 <- withCurrentOffSet rbuf (`peek16` 0)     ff rbuf 2     return w16@@ -703,6 +694,7 @@ -- 258 read24 :: Readable a => a -> IO Word32 read24 rbuf = do+    checkR rbuf 3     w24 <- withCurrentOffSet rbuf (`peek24` 0)     ff rbuf 3     return w24@@ -713,6 +705,7 @@ -- 66051 read32 :: Readable a => a -> IO Word32 read32 rbuf = do+    checkR rbuf 4     w32 <- withCurrentOffSet rbuf (`peek32` 0)     ff rbuf 4     return w32@@ -720,9 +713,15 @@ -- | Reading four bytes as 'Word64' and ff four bytes. read64 :: Readable a => a -> IO Word64 read64 rbuf = do+    checkR rbuf 8     w64 <- withCurrentOffSet rbuf (`peek64` 0)     ff rbuf 8     return w64++checkR :: Readable a => a -> Int -> IO ()+checkR rbuf siz = do+    left <- remainingSize rbuf+    when (left < siz) $ throwIO BufferOverrun  -- | Buffer overrun exception. data BufferOverrun = BufferOverrun -- ^ The buffer size is not enough
network-byte-order.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/  name:                network-byte-order-version:             0.1.3.0+version:             0.1.4.0 synopsis:            Network byte order utilities description:         Peek and poke functions for network byte order. license:             BSD3