[GHC] #2979: better support for FFI C wrappers for macros in system headers
GHC
cvs-ghc at haskell.org
Tue Dec 6 06:03:06 CET 2011
#2979: better support for FFI C wrappers for macros in system headers
----------------------------------+-----------------------------------------
Reporter: duncan | Owner:
Type: feature request | Status: new
Priority: normal | Milestone: 7.6.1
Component: Compiler (FFI) | Version: 7.3
Resolution: | Keywords:
Testcase: | Blockedby:
Difficulty: Unknown | Os: Unknown/Multiple
Blocking: | Architecture: Unknown/Multiple
Failure: Building GHC failed |
----------------------------------+-----------------------------------------
Comment(by PHO):
> Perhaps we should have something like
{{{
foreign import capi unsafe "HsBase.h sigaddset"
c_sigaddset :: {-# CType "sigset_t *" #-} Ptr CSigset -> CInt -> IO
CInt
}}}
Or perhaps something like this?
{{{
-- Defined in somewhere around Foreign.C
class CType a where
cType :: a -> String
data CSigset
instance CType CSigset where cType = "sigset_t"
instance CType CInt where cType = "int" -- Defined in Foreign.C.Types
instance CType a => CType (Ptr a) where -- Defined in Foreign.C.Types
cType = (++ "*") . cType
-- Good: every types are instances of CType.
foreign import capi unsafe "HsBase.h sigaddset"
c_sigaddset :: Ptr CSigset -> CInt -> IO CInt
-- Bad: Foo isn't an instance of CType, resulting in a compilation error.
data Foo
foreign import capi unsafe "HsBase.h sigaddset"
c_sigaddset :: Ptr Foo -> CInt -> IO CInt
-- OK: ccall doesn't care about CType.
foreign import ccall unsafe "HsBase.h sigaddset"
c_sigaddset :: Ptr CSigset -> CInt -> IO CInt
}}}
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/2979#comment:19>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the Glasgow-haskell-bugs
mailing list