6 patches for repository http://code.haskell.org/c2hs:
Mon Nov 8 23:46:25 GMT 2010 [email protected] * Convert an accented surname in a comment to UTF-8 hasktags makes the (reasonable) assumption that source files are UTF-8, and gets very upset if they're not. Tue Nov 9 06:02:13 GMT 2010 [email protected] * Fix generation of superclass instances Previously, specifying a superclass in a {# class #} rule would generate incorrect code. For instance, the 'pointer' test case includes the following: > {#pointer *Point as APoint newtype#} > {#class APointClass APoint#} > > {#pointer *ColourPoint as AColourPoint newtype#} > {#class APointClass => AColourPointClass AColourPoint#} This generates an incorrect instance of APointClass for AColourPoint, as follows: > instance APointClass AColourPoint where > aColourPoint (AColourPoint p) = AColourPoint (castPtr p) > fromAColourPoint (AColourPoint p) = AColourPoint (castPtr p) This was due to the code generator using the name of the type being defined rather than the name of the superclass type, which was due to a missing apostrophe. This is my favourite kind of bug fix. Tue Nov 9 06:13:26 GMT 2010 [email protected] * Split collecting superclasses out of a where clause This would have prevented the bug I just fixed, since the mistaken type identifier would not have been in scope. Tue Nov 9 06:16:37 GMT 2010 [email protected] * Simplify generating class cast instances Tue Nov 9 16:37:47 GMT 2010 [email protected] * Squash an unused result warning Tue Nov 9 17:49:46 GMT 2010 [email protected] * Fix deprecation warnings and build trivia in test suite The test suite was passing -fffi to GHC; this patch adds LANGUAGE ForeignFunctionInterface to the relevant files instead. The test suite also used the deprecated C2HS module for converting between Int and CInt; this patch fixes all tests that were using these functions. Also, the Sizeof test didn't compile. It now compiles, but still fails due to bug #10. Finally, compilation errors would previously not cause `make` to fail in some cases.
New patches: [Convert an accented surname in a comment to UTF-8 [email protected]**20101108234625 Ignore-this: ed70882c10d1c992a3af3ccbdbbf62ff hasktags makes the (reasonable) assumption that source files are UTF-8, and gets very upset if they're not. ] hunk ./src/Text/Lexers.hs 83 -- -- * In this implementation, the combinators `quest`, `star`, and `plus` are -- *right* associative - this was different in the ``Lazy Lexing is Fast'' --- paper. This change was made on a suggestion by Martin Norbäck +-- paper. This change was made on a suggestion by Martin Norbäck -- <[email protected]>. -- --- TODO ---------------------------------------------------------------------- [Fix generation of superclass instances [email protected]**20101109060213 Ignore-this: 506b6a57787d328abdb8abc7c7cf1cd Previously, specifying a superclass in a {# class #} rule would generate incorrect code. For instance, the 'pointer' test case includes the following: > {#pointer *Point as APoint newtype#} > {#class APointClass APoint#} > > {#pointer *ColourPoint as AColourPoint newtype#} > {#class APointClass => AColourPointClass AColourPoint#} This generates an incorrect instance of APointClass for AColourPoint, as follows: > instance APointClass AColourPoint where > aColourPoint (AColourPoint p) = AColourPoint (castPtr p) > fromAColourPoint (AColourPoint p) = AColourPoint (castPtr p) This was due to the code generator using the name of the type being defined rather than the name of the superclass type, which was due to a missing apostrophe. This is my favourite kind of bug fix. ] hunk ./src/C2HS/Gen/Bind.hs 665 Class oclassIde' typeIde' <- queryClass ide ptr <- queryPointer typeIde' classes <- collectClasses oclassIde' - return $ (identToString ide, identToString typeIde, ptr) : classes + return $ (identToString ide, identToString typeIde', ptr) : classes -- traceInfoClass = traceGenBind $ "** Class hook:\n" [Split collecting superclasses out of a where clause [email protected]**20101109061326 Ignore-this: b1f74e59925ecb0b86e7c46fdac625ef This would have prevented the bug I just fixed, since the mistaken type identifier would not have been in scope. ] { hunk ./src/C2HS/Gen/Bind.hs 656 classDef pos (identToString classIde) (identToString typeIde) ptrType isNewtype superClasses where - -- compile a list of all super classes (the direct super class first) - -- - collectClasses :: Maybe Ident -> GB [(String, String, HsObject)] - collectClasses Nothing = return [] - collectClasses (Just ide) = - do - Class oclassIde' typeIde' <- queryClass ide - ptr <- queryPointer typeIde' - classes <- collectClasses oclassIde' - return $ (identToString ide, identToString typeIde', ptr) : classes - -- traceInfoClass = traceGenBind $ "** Class hook:\n" hunk ./src/C2HS/Gen/Bind.hs 658 +-- | compile a list of all super classes, with the supplied direct superclass +-- (if any) first +-- +collectClasses :: Maybe Ident -> GB [(String, String, HsObject)] +collectClasses Nothing = return [] +collectClasses (Just ide) = + do + Class oclassIde typeIde <- queryClass ide + ptr <- queryPointer typeIde + classes <- collectClasses oclassIde + return $ (identToString ide, identToString typeIde, ptr) : classes + -- | produce code for an enumeration -- -- * an extra instance declaration is required when any of the enumeration } [Simplify generating class cast instances [email protected]**20101109061637 Ignore-this: 5de9a66444e174b56ec461f123456bf2 ] { hunk ./src/C2HS/Gen/Bind.hs 1308 "instance " ++ className ++ " " ++ typeName ++ " where\n" ++ " " ++ toMethodName ++ " = id\n" ++ " " ++ fromMethodName ++ " = id\n" - instDefs <- castInstDefs superClasses - return $ classDefStr ++ instDefs ++ instDef + instDefs <- mapM castInstDef superClasses + return $ classDefStr ++ concat instDefs ++ instDef where hunk ./src/C2HS/Gen/Bind.hs 1311 - castInstDefs [] = return "" - castInstDefs ((superName, ptrName, Pointer ptrType' isNewtype'):classes) = + castInstDef (superName, ptrName, Pointer ptrType' isNewtype') = do unless (ptrType == ptrType') $ pointerTypeMismatchErr pos className superName hunk ./src/C2HS/Gen/Bind.hs 1329 ++ superConstr ++ "(" ++ castFun ++ " p)\n" ++ " " ++ fromMethodName ++ " (" ++ superConstr ++ "p) = " ++ typeConstr ++ "(" ++ castFun ++ " p)\n" - instDefs <- castInstDefs classes - return $ instDef ++ instDefs + return instDef -- C code computations } [Squash an unused result warning [email protected]**20101109163747 Ignore-this: cc6e420756bf73771bb51f0dc24f0f8f ] hunk ./src/C2HS/C/Trav.hs 249 Just prevTag -> case isRefinedOrUse prevTag tag of Nothing -> return otag Just (fullTag, foreIde) -> do - transAttrCCT $ \ac -> addDefTagC ac ide fullTag + _ <- transAttrCCT $ \ac -> addDefTagC ac ide fullTag foreIde `refersToDef` TagCD fullTag return Nothing -- transparent for env where [Fix deprecation warnings and build trivia in test suite [email protected]**20101109174946 Ignore-this: 8ae34094e0dbf239b76417cd5b5cd515 The test suite was passing -fffi to GHC; this patch adds LANGUAGE ForeignFunctionInterface to the relevant files instead. The test suite also used the deprecated C2HS module for converting between Int and CInt; this patch fixes all tests that were using these functions. Also, the Sizeof test didn't compile. It now compiles, but still fails due to bug #10. Finally, compilation errors would previously not cause `make` to fail in some cases. ] { hunk ./tests/system/Calls.chs 2 -- -*-haskell-*- +{-# LANGUAGE ForeignFunctionInterface #-} module Main where hunk ./tests/system/Calls.chs 8 import Monad +import Foreign +import Foreign.C import C2HS {#context lib="calls"#} hunk ./tests/system/Cpp.chs 2 -- -*-haskell-*- +{-# LANGUAGE ForeignFunctionInterface #-} module Cpp where hunk ./tests/system/Cpp.chs 7 -import C2HS +import Foreign.C.Types -- CPP directive -- - hunk ./tests/system/Enums.chs 2 -- -*-haskell-*- +{-# LANGUAGE ForeignFunctionInterface #-} import Monad hunk ./tests/system/Enums.chs 4 -import C2HS +import Foreign +import Foreign.C {#context prefix="enums"#} hunk ./tests/system/Enums.chs 23 colourOfSide :: Side -> Colour colourOfSide = - cToEnum . {#call fun colourOfSide as colourOfSidePrim#} . cFromEnum + toEnum . fromIntegral . {#call fun colourOfSide as colourOfSidePrim#} . fromIntegral . fromEnum #c enum ThisThat { hunk ./tests/system/Makefile 5 # Therefore we shouldn't use one for C and one for HS HC=ghc -HCFLAGS= -fffi C2HS = ../../dist/build/c2hs/c2hs # C2HSFLAGS = -d trace -d genbind -d ctrav -d chs PRGMS = simple calls enums pointer structs marsh cpp hunk ./tests/system/Makefile 17 cp -p ../../C2HS.hs . $(HC) -c C2HS.hs -simple: C2HS.o Simple.chs simple.h simple.c +simple: Simple.chs simple.h simple.c $(C2HS) $(C2HSFLAGS) simple.h Simple.chs $(HC) -c -o Simple_hs.o Simple.hs $(HCFLAGS) $(CC) -c simple.c hunk ./tests/system/Makefile 21 - $(HC) -o simple simple.o Simple_hs.o C2HS.o + $(HC) -o simple simple.o Simple_hs.o hunk ./tests/system/Makefile 23 -calls: C2HS.o Calls.chs calls.h +calls: Calls.chs calls.h C2HS.o $(C2HS) $(C2HSFLAGS) calls.h Calls.chs hunk ./tests/system/Makefile 25 - $(HC) -c -o Calls.o Calls.hs -#include\"calls.h\" $(HCFLAGS) || \ - echo "!!! Building calls failed ! known bug #?" + $(HC) -c -o Calls.o Calls.hs C2HS.o || \ + ( echo "!!! Building calls failed ! known bug #?"; exit 1) hunk ./tests/system/Makefile 28 -enums: C2HS.o Enums.chs enums.h +enums: Enums.chs enums.h $(C2HS) $(C2HSFLAGS) enums.h Enums.chs $(CC) -o enums_c.o -c enums.c hunk ./tests/system/Makefile 31 - $(HC) -o enums enums_c.o Enums.hs -#include\"enums.h\" $(HCFLAGS) C2HS.o + $(HC) -o enums enums_c.o Enums.hs hunk ./tests/system/Makefile 33 -pointer: C2HS.o Pointer.chs pointer.h pointer.c +pointer: Pointer.chs pointer.h pointer.c $(C2HS) $(C2HSFLAGS) pointer.h Pointer.chs $(CC) -o pointer_c.o -c pointer.c hunk ./tests/system/Makefile 36 - $(HC) -o pointer pointer_c.o Pointer.hs -#include\"pointer.h\"\ - $(HCFLAGS) C2HS.o + $(HC) -o pointer pointer_c.o Pointer.hs hunk ./tests/system/Makefile 38 -sizeof: C2HS.o Sizeof.chs sizeof.h sizeof.c +sizeof: Sizeof.chs sizeof.h sizeof.c $(C2HS) $(C2HSFLAGS) sizeof.h Sizeof.chs hunk ./tests/system/Makefile 40 - $(HC) -c -o Sizeof.o Sizeof.hs -#include\"sizeof.h\" $(HCFLAGS) + $(HC) -c -o Sizeof.o Sizeof.hs $(CC) -o sizeof_c.o -c sizeof.c hunk ./tests/system/Makefile 42 - $(HC) -o sizeof sizeof_c.o Sizeof.o $(HCFLAGS) C2HS.o + $(HC) -o sizeof sizeof_c.o Sizeof.o hunk ./tests/system/Makefile 44 -structs: C2HS.o Structs.chs structs.h structs.c +structs: Structs.chs structs.h structs.c $(C2HS) $(C2HSFLAGS) structs.h Structs.chs hunk ./tests/system/Makefile 46 - $(HC) -c -o Structs.o Structs.hs -#include\"structs.h\" $(HCFLAGS) + $(HC) -c -o Structs.o Structs.hs $(CC) -o structs_c.o -c structs.c hunk ./tests/system/Makefile 48 - $(HC) -o structs structs_c.o Structs.o $(HCFLAGS) C2HS.o + $(HC) -o structs structs_c.o Structs.o hunk ./tests/system/Makefile 50 -marsh: C2HS.o Marsh.chs marsh.h +marsh: Marsh.chs marsh.h $(C2HS) $(C2HSFLAGS) marsh.h Marsh.chs hunk ./tests/system/Makefile 52 - $(HC) -o marsh Marsh.hs -#include\"marsh.h\" $(HCFLAGS) C2HS.o + $(HC) -o marsh Marsh.hs hunk ./tests/system/Makefile 54 -cpp: C2HS.o Cpp.chs cpp.h +cpp: Cpp.chs cpp.h $(C2HS) $(C2HSFLAGS) Cpp.chs hunk ./tests/system/Makefile 56 - $(HC) -c -o Cpp.o Cpp.hs -#include\"Cpp.h\" $(HCFLAGS) C2HS.o + $(HC) -c -o Cpp.o Cpp.hs # runs hunk ./tests/system/Makefile 90 sizeof.run: sizeof @echo "---=== Output for \`sizeof'": @./sizeof || \ - echo "!!! sizeof FAILED: Maybe related to bug #10" + ( echo "!!! sizeof FAILED: Maybe related to bug #10"; exit 1) @echo "---=== End of Output" hunk ./tests/system/Marsh.chs 7 -- % ghc -fglasgow-exts '-#include<marsh.h>' -o marsh\ -- -i../lib -L../lib Marsh.hs {-marsh.o-} -lc2hs -import C2HS +import Foreign +import Foreign.C main :: IO () main = do hunk ./tests/system/Pointer.chs 2 -- -*-haskell-*- +{-# LANGUAGE ForeignFunctionInterface #-} import Monad hunk ./tests/system/Pointer.chs 4 -import C2HS +import Foreign +import Foreign.C {#pointer string as MyCString foreign newtype#} hunk ./tests/system/Pointer.chs 28 makeCPoint :: Int -> Int -> IO CPoint makeCPoint x y = do - ptr <- {#call unsafe make_point#} (cIntConv x) (cIntConv y) + ptr <- {#call unsafe make_point#} (fromIntegral x) (fromIntegral y) newForeignPtr finalizerFree ptr transCPoint :: CPoint -> Int -> Int -> IO CPoint hunk ./tests/system/Pointer.chs 34 transCPoint pnt x y = do ptr <- withForeignPtr pnt $ \pnt' -> - {#call unsafe trans_point#} pnt' (cIntConv x) (cIntConv y) + {#call unsafe trans_point#} pnt' (fromIntegral x) (fromIntegral y) newForeignPtr finalizerFree ptr -- test function pointers hunk ./tests/system/Simple.chs 1 +{-# LANGUAGE ForeignFunctionInterface #-} module Main where hunk ./tests/system/Sizeof.chs 1 +{-# LANGUAGE ForeignFunctionInterface #-} module Main where import Monad (liftM, when) hunk ./tests/system/Structs.chs 6 -- % ../c2hs structs.h Structs.chs -- % ghc -fglasgow-exts '-#include<structs.h>' -o structs\ -- -i../lib -L../lib Structs.hs structs.o -lc2hs +{-# LANGUAGE ForeignFunctionInterface #-} import Monad (liftM, when) hunk ./tests/system/Structs.chs 9 -import C2HS +import Foreign +import Foreign.C newtype Point = Point {#type point#} hunk ./tests/system/Structs.chs 18 unPoint (Point p) = p makePoint :: Int -> Int -> Point -makePoint x y = Point ({#call fun make_point#} (cIntConv x) (cIntConv y)) +makePoint x y = Point $ + {#call fun make_point#} (fromIntegral x) (fromIntegral y) pointSize :: Int pointSize = {#sizeof point#} hunk ./tests/system/Structs.chs 28 main :: IO () main = do - val <- liftM cIntConv $ {#get _point.y#} $! unPoint pnt - val' <- liftM cIntConv $ {#get point->y#} $! unPoint pnt + val <- liftM fromIntegral $ {#get _point.y#} $! unPoint pnt + val' <- liftM fromIntegral $ {#get point->y#} $! unPoint pnt when (val /= val') $ error "val /= val': Panic!" weird <- {#call make_weird#} hunk ./tests/system/Structs.chs 33 - val2 <- liftM cIntConv $ {#get weird->x#} weird - val3 <- liftM cIntConv $ {#get weird->nested.z#} weird - val4 <- liftM cIntConv $ {#get weird->nested.pnt->y#} weird + val2 <- liftM fromIntegral $ {#get weird->x#} weird + val3 <- liftM fromIntegral $ {#get weird->nested.z#} weird + val4 <- liftM fromIntegral $ {#get weird->nested.pnt->y#} weird const nop $ {#set cpoint->col#} nullPtr 5 -- only for seeing what is generated spacePtr <- {#call getSpacePtr#} hunk ./tests/system/sizeof.h 11 size_t align_of_s1(); size_t align_of_s2(); size_t align_of_s3(); +size_t align_of_s4(); typedef struct s1 { int x; } Context: [Deprecate unused functions in the C2HS source module Duncan Coutts <[email protected]>**20100608003144 Ignore-this: 97a58b35219b3235cf4bccd11c49fc3e It should not be a general provider of utility functions. It should just be for marshaling functions that are needed by code generated by c2hs. ] [Generate standard marshalers for int, float and bool Duncan Coutts <[email protected]>**20100608000741 Ignore-this: 302d7c98b3de571ed8f795c6272f9db8 Rather than non-stanard aliases from the annoying C2HS module. ] [Remove redundant vim modeline which apparently confuses emacs Duncan Coutts <[email protected]>**20100530224328 Ignore-this: 3d6c5aae17fb80fc690ebee4749d0acc Also add ghc-options: -fwarn-tabs ] [Extend the sizeof test to do alignment too Duncan Coutts <[email protected]>**20100423174026 Ignore-this: 46730bba6e9c3b9a3de6f2049a0b08a6 The bitfield size tests fail. See ticket #10. ] [Rename "alignment" keyword to "alignof" Duncan Coutts <[email protected]>**20100423173753 Ignore-this: 4b3a8530eb5d65245c5b15b36069fe71 To match sizeof, and the GNU C __alignof__ keyword. Also fix implementation to return the alignment rather than size. ] [alignment keyword support [email protected]**20091022153809 Ignore-this: 6bc67ccada198cb9979a0ed04a003839 ] [TAG 0.16.2 Duncan Coutts <[email protected]>**20100422171301 Ignore-this: 961a5a4883231850ff0f7248beb1b439 ] [Bump version number Duncan Coutts <[email protected]>**20100422171232 Ignore-this: 8b89818bc1879f0403f9ba3f90bc07fa Will use even numbers for releases. ] [Specify GPL version number 2 in .cabal metadata Duncan Coutts <[email protected]>**20100422171209 Ignore-this: 5088233f62c4286e17fe0d6267346c9d ] [Fix a few warnings Duncan Coutts <[email protected]>**20100422171022 Ignore-this: c3889d1a59cccc206c6a301db97633ce ] [Remove a couple old comments that are no longer applicable Duncan Coutts <[email protected]>**20100419224920 Ignore-this: 17026945fea02ec85ee1fa48fc2d86c5 ] [Bump version number Duncan Coutts <[email protected]>**20100419224828 Ignore-this: 687f3af0846f640430e5e9bf33c39d96 ] [Specify source repository in .cabal file Duncan Coutts <[email protected]>**20100419224706 Ignore-this: d9370e4b60aa8f27b761656c48c051ad Requires Cabal 1.6, also allows using file globs for extra source files ] [Workaround .chs lexer problem by using latin1 encoding Duncan Coutts <[email protected]>**20100419224401 Ignore-this: 6714eb66dcda0e766b4e933f082ce839 The .chs lexer cannot handle chars > 255 so as a workaround force the file I/O to use latin1 encoding. This becomes a problem with base-4.2 since by default it uses locale encoding where preciously it used only latin1 encoding. Eventually we should move to .chs files being utf8 since .hs files are utf8. ] [Improve error message formatting in some cases Duncan Coutts <[email protected]>**20100419224223 Ignore-this: 311b937efd9ce34897ed58f8ca84b44e Workaround for wierd Show instance for CError from language-c ] [Fix printing of FFI foreign entity strings to not have leading whitespace Duncan Coutts <[email protected]>**20100419223932 Ignore-this: 3ca3ce15b0efb62e5560dc13de293253 Early betas of ghc-6.12 could not parse these. Fixed in 6.12.1 I think but still worth making the output prettier. ] [Fix line number info in error messages about C function types Duncan Coutts <[email protected]>**20100419223032 Ignore-this: a3e40d7ae3ae51613505289d0ab4ad8f Preserve source positions when constructing attributes while analysing C function declarations. In particular this fixed the error messages for binding long double C types. ] [Workaround the lack of CLDouble support in ghc/base Duncan Coutts <[email protected]>**20100419134939 Ignore-this: 29920798e12fdc8dbcef328a0d94af9e If users try to bind to functions that use "long double" they will get an error message about the type not being supported. ] [TAG 0.16.0 Duncan Coutts <[email protected]>**20090228132823] Patch bundle hash: 16fb6701d208f5eef6e15815dad05bb1669363c8
_______________________________________________ C2hs mailing list [email protected] http://www.haskell.org/mailman/listinfo/c2hs
