haskell-gi 0.22.5 → 0.22.6
raw patch · 4 files changed
+31/−4 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- ChangeLog.md +4/−0
- haskell-gi.cabal +1/−1
- lib/Data/GI/CodeGen/CodeGen.hs +11/−2
- lib/Data/GI/CodeGen/EnumFlags.hs +15/−1
ChangeLog.md view
@@ -1,3 +1,7 @@+### 0.22.6+++ Fix generated IsX typeclasses for non-GObject interfaces.+ ### 0.22.5 + Add support for inheriting overloading info.
haskell-gi.cabal view
@@ -1,5 +1,5 @@ name: haskell-gi-version: 0.22.5+version: 0.22.6 synopsis: Generate Haskell bindings for GObject Introspection capable libraries description: Generate Haskell bindings for GObject Introspection capable libraries. This includes most notably Gtk+, but many other libraries in the GObject ecosystem provide introspection data too.
lib/Data/GI/CodeGen/CodeGen.hs view
@@ -381,8 +381,17 @@ writeHaddock DocBeforeSymbol ("Type class for types which implement `" <> name' <> "`.") - bline $ "class ManagedPtrNewtype a => " <> cls <> " a"- line $ "instance " <> cls <> " " <> name'+ -- Create the IsX constraint. We cannot simply say+ --+ -- > type IsX o = (ManagedPtrNewtype o, O.IsDescendantOf X o)+ --+ -- since we sometimes need to refer to @IsX@ itself, without+ -- applying it. We instead use the trick of creating a class with+ -- a universal instance.+ let constraints = "(ManagedPtrNewtype o, O.IsDescendantOf " <> name' <> " o)"+ bline $ "class " <> constraints <> " => " <> cls <> " o"+ bline $ "instance " <> constraints <> " => " <> cls <> " o"+ genWrappedPtr n (ifAllocationInfo iface) 0 when (not . null . ifProperties $ iface) $ group $ do
lib/Data/GI/CodeGen/EnumFlags.hs view
@@ -7,6 +7,7 @@ import Control.Monad (when, forM_) import Data.Monoid ((<>)) import Data.Text (Text)+import qualified Data.Set as S import Foreign.C (CUInt) import Foreign.Storable (sizeOf)@@ -18,6 +19,19 @@ import Data.GI.CodeGen.SymbolNaming (upperName) import Data.GI.CodeGen.Util (tshow) +-- | Given a list of named enum members, filter out those that have+-- the same value as a previous entry in the list.+dropDuplicated :: [(Text, EnumerationMember)] -> [(Text, EnumerationMember)]+dropDuplicated namedMembers = go namedMembers enumMemberValue S.empty+ where go :: Ord c => [(a, b)] -> (b->c) -> S.Set c -> [(a, b)]+ go [] _ _ = []+ go ((n, m) : rest) f seen =+ if S.member (f m) seen+ -- already seen, discard+ then go rest f seen+ else (n,m) : go rest f (S.insert (f m) seen)++ genEnumOrFlags :: HaddockSection -> Name -> Enumeration -> ExcCodeGen () genEnumOrFlags docSection n@(Name ns name) e = do -- Conversion functions expect enums and flags to map to CUInt,@@ -61,7 +75,7 @@ line $ "fromEnum (Another" <> name' <> " k) = k" blank indent $ do- forM_ members' $ \(n, m) ->+ forM_ (dropDuplicated members') $ \(n, m) -> line $ "toEnum " <> tshow (enumMemberValue m) <> " = " <> n line $ "toEnum k = Another" <> name' <> " k"