c2hs icon indicating copy to clipboard operation
c2hs copied to clipboard

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

Open krisis opened this issue 7 years ago • 0 comments

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

  • Command used to generate Haskell binding module
c2hs --cppopts='-I/usr/include/' -l Sample.chs
  • Compile the generated Haskell binding module
ghc Sample.hs

Software versions used

  • GHC - ghc-nopie-8.2.2 (I use stack for development)
  • c2hs - C->Haskell Compiler, version 0.28.3 Switcheroo, 25 November 2017
  • Platform - Linux komboothi 4.13.0-32-generic #35-Ubuntu SMP

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.

krisis avatar Feb 27 '18 13:02 krisis