c2hs icon indicating copy to clipboard operation
c2hs copied to clipboard

In what case would c2hs import Foreign.Ptr?

Open Magicloud opened this issue 6 years ago • 1 comments

I have two pointers defined in exactly the same way. And two modules contains fun definitions for each pointer. One of them built well. The other complains on unknown type Ptr. Apparently, in the second .hs file, a few imports are missing. I could not figure out what caused the difference.

error message

Not in scope: type constructor or class ‘C2HSImp.Ptr’
Neither ‘Foreign.C.Types’ nor ‘Foreign.ForeignPtr’ exports ‘Ptr’.

pointer definition {#pointer *c_typedef as Typedef foreign finalizer typedef_destroy newtype#}

broken .hs generated

import qualified Foreign.C.Types as C2HSImp
import qualified Foreign.ForeignPtr as C2HSImp
import MyTypes

working .hs generated

import qualified Foreign.C.String as C2HSImp
import qualified Foreign.C.Types as C2HSImp
import qualified Foreign.ForeignPtr as C2HSImp
import qualified Foreign.Marshal.Utils as C2HSImp
import qualified Foreign.Ptr as C2HSImp
import MyTypes
import Foreign -- I have this in .chs

Magicloud avatar Dec 07 '18 10:12 Magicloud

I also got another issue that Foreign.Marshal is not imported when I need with and alloca. And Foreign.Storable when I need peek.

Magicloud avatar Dec 08 '18 17:12 Magicloud