[C2hs] Possible bug

Dominic Fox dominic.fox at gmail.com
Sun Sep 18 17:14:10 EDT 2005


Hi,

I have had a problem compiling the following header file and .chs
file; Duncan Coutts has suggested that it might be a bug.

The header file is this:

---
typedef void* clientBufferPtr;
typedef int result;

clientBufferPtr create_client_buffer(char* hostname, unsigned int port);
void delete_client_buffer(clientBufferPtr buffer);
result client_buffer_login(clientBufferPtr buffer, char* name, int
red, int green, int blue, char* global_password, char* user_password);
---

The .chs file is as follows:

---
module ClientBuffer (createBuffer, deleteBuffer, login) where
import Foreign
import CForeign

cIntConv = fromIntegral

#include "client_buffer.h"

newtype ClientBuffer = ClientBuffer (Ptr ())
clientBuffer (ClientBuffer a) = a

{#fun create_client_buffer as createBuffer {`String', `Int'} -> `ClientBuffer'
ClientBuffer #}

{#fun delete_client_buffer as deleteBuffer {clientBuffer
`ClientBuffer'} -> `()'#}

{#fun client_buffer_login as login {clientBuffer `ClientBuffer', `String',
`Int', `Int', `Int', `String', `String'} -> `Int' #}
---

The generated .hs file looks like this:

--
-- GENERATED by C->Haskell Compiler, version 0.14.3 Travelling
Lightly, 09 Aug 2005 (Haskell)
-- Edit the ORIGNAL .chs file instead!


{-# LINE 1 "ClientBuffer.chs" #-}module ClientBuffer (createBuffer,
deleteBuffer, login) where
import Foreign
import CForeign

cIntConv = fromIntegral


newtype ClientBuffer = ClientBuffer (Ptr ())
clientBuffer (ClientBuffer a) = a

createBuffer :: String -> Int -> IO (ClientBuffer)
createBuffer a1 a2 =
  withCString a1 $ \a1' -> 
  let {a2' = cIntConv a2} in 
  createBuffer'_ a1' a2' >>= \res ->
  let {res' = ClientBuffer res} in
  return (res')
{-# LINE 13 "ClientBuffer.chs" #-}

deleteBuffer :: ClientBuffer -> IO ()
deleteBuffer a1 =
  let {a1' = clientBuffer a1} in 
  deleteBuffer'_ a1' >>= \res ->
  return ()
{-# LINE 15 "ClientBuffer.chs" #-}

login :: ClientBuffer -> String -> Int -> Int -> Int -> String ->
String -> IO (Int)
login a1 a2 a3 a4 a5 a6 a7 =
  let {a1' = clientBuffer a1} in 
  withCString a2 $ \a2' -> 
  let {a3' = cIntConv a3} in 
  let {a4' = cIntConv a4} in 
  let {a5' = cIntConv a5} in 
  withCString a6 $ \a6' -> 
  withCString a7 $ \a7' -> 
  login'_ a1' a2' a3' a4' a5' a6' a7' >>= \res ->
  let {res' = cIntConv res} in
  return (res')
{-# LINE 12 "ClientBuffer.chs" #-}
foreign import ccall safe "ClientBuffer.h create_client_buffer"
  createBuffer'_ :: ((Ptr CChar) -> (CUInt -> (IO (Ptr ()))))

foreign import ccall safe "ClientBuffer.h delete_client_buffer"
  deleteBuffer'_ :: ((Ptr ()) -> (IO ()))

foreign import ccall safe "ClientBuffer.h client_buffer_login"
  login'_ :: ((Ptr ()) -> ((Ptr CChar) -> (CInt -> (CInt -> (CInt ->
((Ptr CChar) -> ((Ptr CChar) -> (IO CInt))))))))
---

And the error I get from ghc (6.4) when it tries to type-check this
file is this:

ClientBuffer.chs:25:18:
    Couldn't match `CInt' against `CUInt'
      Expected type: CInt
      Inferred type: CUInt
    In the third argument of `login'_', namely `a3''
    In the first argument of `(>>=)', namely `login'_ a1' a2' a3' a4'
a5' a6' a7''

Is this a problem with c2hs, or am I doing something wrong?

thanks,
Dominic


More information about the C2hs mailing list