haskell / c2hs

c2hs is a pre-processor for Haskell FFI bindings to C libraries
http://hackage.haskell.org/package/c2hs
Other
198 stars 50 forks source link

Missing import of C2HSImp #151

Closed albertov closed 8 years ago

albertov commented 8 years ago

c2hs 0.26.1 seems to forget to add an import for C2HSImp as can be seen in the failing build here.

The offending is code seems to be a {#pointer #} to a function pointer type in this line

Adding import qualified Foreign.C.Types as C2HSImpfixes the problem.

ian-ross commented 8 years ago

@albertov Thanks for the report. I'm not surprised that you found a hole in the new import management stuff. To be honest, I was expecting a lot more problems with it! I'll take a look at this some time this week.

ian-ross commented 8 years ago

I think this should be fixed in HEAD now.

TomMD commented 8 years ago

I'm not seeing Ptr exported by Foreign.C.Types - shouldn't this import be Foreign.Ptr?

Prelude> import Foreign.C.Types
Prelude Foreign.C.Types> :i Ptr

<interactive>:1:1: Not in scope: ‘Ptr’
Prelude Foreign.C.Types> import Foreign.Ptr
Prelude Foreign.C.Types Foreign.Ptr> :i Ptr
type role Ptr phantom
data Ptr a = GHC.Ptr.Ptr GHC.Prim.Addr#
        -- Defined in ‘GHC.Ptr’
ian-ross commented 8 years ago

@TomMD That's right, but if you have a .chs file with a {#pointer ...#} hook in it, C2HS generates Haskell with the imports

import qualified Foreign.C.Types as C2HSImp
import qualified Foreign.Ptr as C2HSImp

so you get both the things that are needed. The problem in this issue was just that I'd forgotten to do the import collection for some kinds of pointer hooks -- I have a function that traverses a representation of the Haskell type corresponding to values needed by C2HS hooks and works out what library modules to import, and that works fine. I just wasn't calling it in the right place.