[prev in list] [next in list] [prev in thread] [next in thread]
List: haskell-c2hs
Subject: [C2hs] bug in C2HSMarsh.extractBitMasks function
From: Duncan Coutts <duncan.coutts () worc ! ox ! ac ! uk>
Date: 2005-05-09 11:31:57
Message-ID: 1115638317.8291.280.camel () localhost
[Download RAW message or body]
Hi,
> extractBitMasks bits =
> [bm | bm <- [minBound..maxBound], bits `containsBitMask` bm]
Sadly this does not work since [minBound..maxBound] uses succ to
enmerate the flags and the Enum instance that c2hs generates does not
include a definition of succ and the default assumes that the enum is
packed whereas of course for flags it is sparse (only has values for
2^n).
We had this bug in gtk2hs too:
> toFlags :: Flags a => Int -> [a]
> toFlags n = andNum n minBound
> where
> andNum n m = (if (n .|. fromEnum m) == n then (m:) else id)
> (if fromEnum m==fromEnum (maxBound `asTypeOf` m) then [] else andNum n (succ m))
We changed this to:
> toFlags :: Flags a => Int -> [a]
> toFlags f = testBits f 1
> where testBits f n
> | f == 0 = []
> | f `testBit` 0 = toEnum n : testBits (f `shiftR` 1) (n `shiftL` 1)
> | otherwise = testBits (f `shiftR` 1) (n `shiftL` 1)
So, extractBitMasks needs fixing, probably in a similar way.
Duncan
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic