Fri Apr 23 11:24:09 EST 2010 Trevor McDonell * choose ccall/stdcall ABI based on language.c attributes - not for dynamic import hooks at the moment New patches: [choose ccall/stdcall ABI based on language.c attributes Trevor McDonell **20100423012409 Ignore-this: aa08e95321472e6af7a89e0a4e083298 - not for dynamic import hooks at the moment ] { hunk ./src/C2HS/Gen/Bind.hs 130 import C2HS.State (CST, errorsPresent, showErrors, fatal, SwitchBoard(..), Traces(..), putTraceStr, getSwitch) import C2HS.C (AttrC, CObj(..), CTag(..), - CDecl(..), CDeclSpec(..), CTypeSpec(..), + CDecl(..), CDeclSpec(..), CTypeSpec(..), CAttr(..), CStructUnion(..), CStructTag(..), CEnum(..), CDeclr(..), CDerivedDeclr(..),CArrSize(..), CExpr(..), CBinaryOp(..), CUnaryOp(..), CConst (..), hunk ./src/C2HS/Gen/Bind.hs 138 runCT, ifCTExc, raiseErrorCTExc, findValueObj, findFunObj, findTag, applyPrefixToNameSpaces, - simplifyDecl, declrNamed, structMembers, + simplifyDecl, declrNamed, structMembers, partitionDeclSpecs, structName, tagName, declaredName , structFromDecl, funResultAndArgs, chaseDecl, findAndChaseDecl, checkForAlias, checkForOneAliasName, checkForOneCUName, hunk ./src/C2HS/Gen/Bind.hs 757 -- show' x = if x < 0 then "(" ++ show x ++ ")" else show x + +-- By default, C2HS uses the @ccall@ convention to control how function arguments +-- are passed and values retrieved. This function looks for a @__stdcall__@ +-- attribute in the declaration, and if found uses that convention instead. +-- +getABI :: CDecl -> String +getABI (CDecl specs _ _) = if any stdcall attrs then "stdcall" else "ccall" + where + (_,attrs,_,_,_) = partitionDeclSpecs specs + stdcall (CAttr (Ident "__stdcall__" _ _) _ _) = True + stdcall _ = False + -- | generate a foreign import declaration that is put into the delayed code -- -- * the C declaration is a simplified declaration of the function that we hunk ./src/C2HS/Gen/Bind.hs 784 extType <- extractFunType pos cdecl isPure header <- getSwitch headerSB when (isVariadic extType) (variadicErr pos (posOf cdecl)) - delayCode hook (foreignImport header ideLexeme hsLexeme isUns extType) + delayCode hook (foreignImport header ideLexeme hsLexeme (getABI cdecl) isUns extType) traceFunType extType where traceFunType et = traceGenBind $ hunk ./src/C2HS/Gen/Bind.hs 806 -- | Haskell code for the foreign import declaration needed by a call hook -- -foreignImport :: String -> String -> String -> Bool -> ExtType -> String -foreignImport header ident hsIdent isUnsafe ty = - "foreign import ccall " ++ safety ++ " " ++ show entity ++ +foreignImport :: String -> String -> String -> String -> Bool -> ExtType -> String +foreignImport header ident hsIdent abi isUnsafe ty = + "foreign import " ++ abi ++ " " ++ safety ++ " " ++ show entity ++ "\n " ++ hsIdent ++ " :: " ++ showExtType ty ++ "\n" where safety = if isUnsafe then "unsafe" else "safe" } Context: [TAG 0.16.2 Duncan Coutts **20100422171301 Ignore-this: 961a5a4883231850ff0f7248beb1b439 ] [Bump version number Duncan Coutts **20100422171232 Ignore-this: 8b89818bc1879f0403f9ba3f90bc07fa Will use even numbers for releases. ] [Specify GPL version number 2 in .cabal metadata Duncan Coutts **20100422171209 Ignore-this: 5088233f62c4286e17fe0d6267346c9d ] [Fix a few warnings Duncan Coutts **20100422171022 Ignore-this: c3889d1a59cccc206c6a301db97633ce ] [Remove a couple old comments that are no longer applicable Duncan Coutts **20100419224920 Ignore-this: 17026945fea02ec85ee1fa48fc2d86c5 ] [Bump version number Duncan Coutts **20100419224828 Ignore-this: 687f3af0846f640430e5e9bf33c39d96 ] [Specify source repository in .cabal file Duncan Coutts **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 **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 **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 **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 **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 **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 **20090228132823] Patch bundle hash: d81c4a0788c4fe82db68f9a4ebeef84886ee92fa