Skip to content

Commit

Permalink
Fix build on GHC-7.8.2
Browse files Browse the repository at this point in the history
  • Loading branch information
basvandijk committed May 23, 2014
1 parent e142229 commit 4dccb2d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 29 deletions.
32 changes: 22 additions & 10 deletions System/USB/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,33 +31,33 @@ import Foreign.C.Types ( CUChar, CInt, CUInt )
import Foreign.C.String ( CStringLen )
import Foreign.Marshal.Alloc ( alloca )
import Foreign.Marshal.Array ( allocaArray )
import Foreign.Storable ( Storable, peek, peekElemOff )
import Foreign.Storable ( peek, peekElemOff )
import Foreign.Ptr ( Ptr, castPtr, plusPtr, nullPtr )
import Foreign.ForeignPtr ( ForeignPtr, withForeignPtr, touchForeignPtr )
import Control.Exception ( Exception, throwIO, bracket, bracket_, onException, assert )
import Control.Monad ( Monad, (=<<), return, when )
import Control.Monad ( (=<<), return, when )
import Control.Arrow ( (&&&) )
import Data.Function ( ($), on )
import Data.Data ( Data )
import Data.Typeable ( Typeable )
import Data.Maybe ( Maybe(Nothing, Just), maybe, fromMaybe )
import Data.List ( lookup, map, (++) )
import Data.List ( lookup, (++) )
import Data.Int ( Int )
import Data.Word ( Word8, Word16 )
import Data.Eq ( Eq, (==) )
import Data.Ord ( Ord, (<), (>) )
import Data.Bool ( Bool(False, True), not, otherwise )
import Data.Bits ( Bits, (.|.), setBit, testBit, shiftL )
import Data.Bits ( Bits, (.|.), setBit, testBit, shiftL, shiftR )
import System.IO ( IO )
import System.IO.Unsafe ( unsafePerformIO )
import Text.Show ( Show, show )
import Text.Read ( Read )
import Text.Printf ( printf )

#if MIN_VERSION_base(4,2,0)
import Data.Functor ( Functor, fmap, (<$>) )
import Data.Functor ( fmap, (<$>) )
#else
import Control.Monad ( Functor, fmap )
import Control.Monad ( fmap )
import Control.Applicative ( (<$>) )
#endif

Expand Down Expand Up @@ -89,7 +89,7 @@ import Bindings.Libusb

-- from usb (this package):
import Utils ( bits, between, genToEnum, genFromEnum, peekVector, mapPeekArray
, allocaPeek, ifM, decodeBCD, uncons
, allocaPeek, ifM, uncons
)

--------------------------------------------------------------------------------
Expand Down Expand Up @@ -117,6 +117,9 @@ import System.Event
( FdKey
, registerFd, unregisterFd
, registerTimeout, unregisterTimeout
#if MIN_VERSION_base(4,7,0)
, getSystemTimerManager
#endif
)

-- from containers:
Expand Down Expand Up @@ -296,18 +299,24 @@ newCtx' handleError = do
-- appropriate Wait function:
r c'libusb_pollfds_handle_timeouts ctxPtr

#if MIN_VERSION_base(4,7,0)
timerMgr <- getSystemTimerManager
#else
let timerMgr = evtMgr
#endif

let wait Wait
!wait | r 0 = manualTimeout
| otherwise = \_ autoTimeout

manualTimeout timeout lock transPtr
| timeout noTimeout = autoTimeout lock transPtr
| otherwise = do
tk registerTimeout evtMgr (timeout * 1000) handleEvents
tk registerTimeout timerMgr (timeout * 1000) handleEvents
acquire lock
`onException`
(uninterruptibleMask_ $ do
unregisterTimeout evtMgr tk
unregisterTimeout timerMgr tk
_err c'libusb_cancel_transfer transPtr
acquire lock)

Expand Down Expand Up @@ -1206,7 +1215,10 @@ convertDeviceDesc d = DeviceDesc
unmarshalReleaseNumber Word16 ReleaseNumber
unmarshalReleaseNumber abcd = (a, b, c, d)
where
[a, b, c, d] = map fromIntegral $ decodeBCD 4 abcd
a = fromIntegral $ abcd `shiftR` 12
b = fromIntegral $ (abcd `shiftL` 4) `shiftR` 12
c = fromIntegral $ (abcd `shiftL` 8) `shiftR` 12
d = fromIntegral $ (abcd `shiftL` 12) `shiftR` 12

-- | Unmarshal an 8bit word to a string descriptor index. 0 denotes that a
-- string descriptor is not available and unmarshals to 'Nothing'.
Expand Down
18 changes: 2 additions & 16 deletions Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ import Foreign.Storable ( Storable, peek, sizeOf )
import Foreign.Marshal.Alloc ( alloca )
import Foreign.Marshal.Utils ( copyBytes )
import Data.Bool ( Bool, otherwise )
import Data.Ord ( Ord, (>) )
import Data.Bits ( Bits, shiftL, shiftR, bitSize, (.&.) )
import Data.Ord ( Ord )
import Data.Bits ( Bits, shiftL, shiftR, (.&.) )
import Data.Int ( Int )
import Data.Maybe ( Maybe(Nothing, Just) )
import System.IO ( IO )
Expand Down Expand Up @@ -100,20 +100,6 @@ allocaPeek f = alloca $ \ptr → f ptr >> peek ptr
ifM Monad m m Bool m α m α m α
ifM cM tM eM = cM >>= \c if c then tM else eM

{-| @decodeBCD bitsInDigit bcd@ decodes the Binary Coded Decimal @bcd@ to a list
of its encoded digits. @bitsInDigit@, which is usually 4, is the number of bits
used to encode a single digit. See:
<http://en.wikipedia.org/wiki/Binary-coded_decimal>
-}
decodeBCD Bits α Int α [α]
decodeBCD bitsInDigit abcd = go 0
where
shftR = bitSize abcd - bitsInDigit

go !shftL | shftL > shftR = []
| otherwise = let !d = (abcd `shiftL` shftL) `shiftR` shftR
in d : go (shftL + bitsInDigit)

uncons Vector α Maybe (α, Vector α)
uncons v | V.null v = Nothing
| otherwise = Just (V.unsafeHead v, V.unsafeTail v)
6 changes: 3 additions & 3 deletions usb.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: usb
version: 1.2
version: 1.2.0.1
cabal-version: >=1.6
build-type: Custom
license: BSD3
Expand Down Expand Up @@ -63,11 +63,11 @@ source-repository head
Library
GHC-Options: -Wall

build-depends: base >= 4 && < 4.7
build-depends: base >= 4 && < 4.8
, base-unicode-symbols >= 0.1.1 && < 0.3
, bindings-libusb >= 1.4.4 && < 1.5
, bytestring >= 0.9 && < 0.11
, text >= 0.5 && < 0.12
, text >= 0.5 && < 1.2
, vector >= 0.5 && < 0.11

exposed-modules: System.USB
Expand Down

0 comments on commit 4dccb2d

Please sign in to comment.