haskell / c2hs

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

#fun hook didn't work as expected for getmntent(3) #201

Open krisis opened 6 years ago

krisis commented 6 years ago

Description

getmntent function signature from man,

struct mntent *getmntent(FILE *stream);

#fun hook syntax used when this issue was observed,

{#fun unsafe getmntent as ^ {`MntHandle'} -> `MntEntPtr' peek*#}

Generated definiton for getmntent

getmntent :: (MntHandle) -> IO ((MntEntPtr))                                                                                                  
getmntent a1 =                                                                                                                                
  let {a1' = id a1} in                                                                                                                        
  getmntent'_ a1' >>= \res ->                                                                                                                 
  peek res >>= \res' ->                                                                                                                       
  return (res')  

foreign import ccall unsafe "Sample.chs.h getmntent"                                                                                          
  getmntent'_ :: ((MntHandle) -> (IO (C2HSImp.Ptr ()))) 

Full example to recreate this issue can be found here

Steps to reproduce

To get things to work, I copied the generated definition for getmntent into the .chs file and modifed the return type to IO (Ptr MntEnt). This works as expected. From the documentation, I expected #fun hook to give this type automatically. Let me know if I am missing something or if I should provide further information to recreate this issue.