xmms2-client-glib 0.0.6.0 → 0.0.7.0
raw patch · 2 files changed
+53/−35 lines, 2 filesdep ~xmms2-client
Dependency ranges changed: xmms2-client
Files
- C2HS.hs +50/−32
- xmms2-client-glib.cabal +3/−3
C2HS.hs view
@@ -40,7 +40,7 @@ module Foreign, -- * Re-export the C language component of the FFI- module CForeign,+ module Foreign.C, -- * Composite marshalling functions withCStringLenIntConv, peekCStringLenIntConv, withIntConv, withFloatConv,@@ -58,12 +58,9 @@ import Foreign- hiding (Word)- -- Should also hide the Foreign.Marshal.Pool exports in- -- compilers that export them-import CForeign+import Foreign.C -import Monad (when, liftM)+import Monad (liftM) -- Composite marshalling functions@@ -71,28 +68,52 @@ -- Strings with explicit length ---withCStringLenIntConv s f = withCStringLen s $ \(p, n) -> f (p, cIntConv n)-peekCStringLenIntConv (s, n) = peekCStringLen (s, cIntConv n)+withCStringLenIntConv :: Num n => String -> ((CString, n) -> IO a) -> IO a+withCStringLenIntConv s f = withCStringLen s $ \(p, n) -> f (p, fromIntegral n) +peekCStringLenIntConv :: Integral n => (CString, n) -> IO String+peekCStringLenIntConv (s, n) = peekCStringLen (s, fromIntegral n)+ -- Marshalling of numerals -- withIntConv :: (Storable b, Integral a, Integral b) - => a -> (Ptr b -> IO c) -> IO c-withIntConv = with . cIntConv+ => a -> (Ptr b -> IO c) -> IO c+withIntConv = with . fromIntegral withFloatConv :: (Storable b, RealFloat a, RealFloat b) - => a -> (Ptr b -> IO c) -> IO c-withFloatConv = with . cFloatConv+ => a -> (Ptr b -> IO c) -> IO c+withFloatConv = with . realToFrac peekIntConv :: (Storable a, Integral a, Integral b) - => Ptr a -> IO b-peekIntConv = liftM cIntConv . peek+ => Ptr a -> IO b+peekIntConv = liftM fromIntegral . peek peekFloatConv :: (Storable a, RealFloat a, RealFloat b) - => Ptr a -> IO b-peekFloatConv = liftM cFloatConv . peek+ => Ptr a -> IO b+peekFloatConv = liftM realToFrac . peek ++-- Everything else below is deprecated.+-- These functions are not used by code generated by c2hs.++{-# DEPRECATED withBool "The C2HS module will soon stop providing unnecessary\nutility functions. Please use standard FFI library functions instead." #-}+{-# DEPRECATED peekBool "The C2HS module will soon stop providing unnecessary\nutility functions. Please use standard FFI library functions instead." #-}+{-# DEPRECATED withEnum "The C2HS module will soon stop providing unnecessary\nutility functions. Please use standard FFI library functions instead." #-}+{-# DEPRECATED peekEnum "The C2HS module will soon stop providing unnecessary\nutility functions. Please use standard FFI library functions instead." #-}+{-# DEPRECATED nothingIf "The C2HS module will soon stop providing unnecessary\nutility functions. Please use standard FFI library functions instead." #-}+{-# DEPRECATED nothingIfNull "The C2HS module will soon stop providing unnecessary\nutility functions. Please use standard FFI library functions instead." #-}+{-# DEPRECATED combineBitMasks "The C2HS module will soon stop providing unnecessary\nutility functions. Please use standard FFI library functions instead." #-}+{-# DEPRECATED containsBitMask "The C2HS module will soon stop providing unnecessary\nutility functions. Please use standard FFI library functions instead." #-}+{-# DEPRECATED extractBitMasks "The C2HS module will soon stop providing unnecessary\nutility functions. Please use standard FFI library functions instead." #-}+{-# DEPRECATED cIntConv "The C2HS module will soon stop providing unnecessary\nutility functions. Please use standard FFI library functions instead." #-}+{-# DEPRECATED cFloatConv "The C2HS module will soon stop providing unnecessary\nutility functions. Please use standard FFI library functions instead." #-}+{-# DEPRECATED cFromBool "The C2HS module will soon stop providing unnecessary\nutility functions. Please use standard FFI library functions instead." #-}+{-# DEPRECATED cToBool "The C2HS module will soon stop providing unnecessary\nutility functions. Please use standard FFI library functions instead." #-}+{-# DEPRECATED cToEnum "The C2HS module will soon stop providing unnecessary\nutility functions. Please use standard FFI library functions instead." #-}+{-# DEPRECATED cFromEnum "The C2HS module will soon stop providing unnecessary\nutility functions. Please use standard FFI library functions instead." #-}++ -- Passing Booleans by reference -- @@ -116,20 +137,22 @@ -- Storing of 'Maybe' values -- ------------------------- +--TODO: kill off this orphan instance!+ instance Storable a => Storable (Maybe a) where sizeOf _ = sizeOf (undefined :: Ptr ()) alignment _ = alignment (undefined :: Ptr ()) peek p = do- ptr <- peek (castPtr p)- if ptr == nullPtr- then return Nothing- else liftM Just $ peek ptr+ ptr <- peek (castPtr p)+ if ptr == nullPtr+ then return Nothing+ else liftM Just $ peek ptr poke p v = do- ptr <- case v of- Nothing -> return nullPtr- Just v' -> new v'+ ptr <- case v of+ Nothing -> return nullPtr+ Just v' -> new v' poke (castPtr p) ptr @@ -167,8 +190,8 @@ -- containsBitMask :: (Bits a, Enum b) => a -> b -> Bool bits `containsBitMask` bm = let bm' = fromIntegral . fromEnum $ bm- in- bm' .&. bits == bm'+ in+ bm' .&. bits == bm' -- |Given a bit pattern, yield all bit masks that it contains. --@@ -193,11 +216,6 @@ -- cFloatConv :: (RealFloat a, RealFloat b) => a -> b cFloatConv = realToFrac--- As this conversion by default goes via `Rational', it can be very slow...-{-# RULES - "cFloatConv/Float->Float" forall (x::Float). cFloatConv x = x;- "cFloatConv/Double->Double" forall (x::Double). cFloatConv x = x- #-} -- |Obtain C value from Haskell 'Bool'. --@@ -212,9 +230,9 @@ -- |Convert a C enumeration to Haskell. -- cToEnum :: (Integral i, Enum e) => i -> e-cToEnum = toEnum . cIntConv+cToEnum = toEnum . fromIntegral -- |Convert a Haskell enumeration to C. -- cFromEnum :: (Enum e, Integral i) => e -> i-cFromEnum = cIntConv . fromEnum+cFromEnum = fromIntegral . fromEnum
xmms2-client-glib.cabal view
@@ -1,5 +1,5 @@ name: xmms2-client-glib-version: 0.0.6.0+version: 0.0.7.0 author: Oleg Belozeorov maintainer: Oleg Belozeorov <upwawet@gmail.com>@@ -30,7 +30,7 @@ library exposed-modules: XMMS2.Client.Glib other-modules: C2HS- build-depends: base >= 4 && < 5, haskell98, xmms2-client == 0.0.6.0+ build-depends: base >= 4 && < 5, haskell98, xmms2-client == 0.0.7.0 build-tools: c2hs hs-source-dirs: ., src extensions: ForeignFunctionInterface@@ -45,4 +45,4 @@ type: git location: git://github.com/upwawet/xmms2hs.git subdir: client-glib- tag: v0.0.6.0+ tag: v0.0.7.0