[C2hs] c2hs seems to ignore the types I give it when generating foreign import declarations

Cale Gibbard cgibbard at gmail.com
Sat Nov 26 00:55:42 EST 2005

Hello, I've just started writing bindings to the Enlightenment
Foundation Libraries, using c2hs. I've run into the following problem
with the types in the foreign import declarations generated.

In Imlib2.h, there is a function prototype:
int imlib_get_visual_depth(Display * display, Visual * visual);

In Imlib.chs, I have (among other things)
import qualified Graphics.X11.Xlib.Types as Xlib
-- ...
{# fun imlib_get_visual_depth as getVisualDepth { id `Xlib.Display',
id `Xlib.Visual' } -> `Int' #}

I run:
c2hs -k /usr/local/include/Imlib2.h Imlib.chs

and in the resulting Imlib.hs, I get:

--- this part is correct:
getVisualDepth :: Xlib.Display -> Xlib.Visual -> IO (Int)
getVisualDepth a1 a2 =
  let {a1' = id a1} in
  let {a2' = id a2} in
  getVisualDepth'_ a1' a2' >>= \res ->
  let {res' = cIntConv res} in
  return (res')

--- this part is not:
foreign import ccall safe "Imlib.h imlib_get_visual_depth"
  getVisualDepth'_ :: ((Ptr ()) -> ((Ptr ()) -> (IO CInt)))

Why did it choose the type Ptr (), when I gave the type Xlib.Display?
I could do an additional cast, but it will get tedious, as I have a
lot of functions to import, and there shouldn't be any need for it
anyway. As this is, it doesn't typecheck at all. If by hand, I change
it to read:

foreign import ccall safe "Imlib.h imlib_get_visual_depth"
  getVisualDepth'_ :: Xlib.Display -> Xlib.Visual -> IO CInt

(which is what I expected it to produce in the first place) then it
works as expected.

Am I making a grievous error, or is this a bug/lack of a feature?

 - Cale

More information about the C2hs mailing list