I'm trying to wrap a C library using c2hs. I've got an opaque C struct that I've mapped in Haskell as follows:
{#pointer *foo as Foo foreign newtype #}
I've used a foreign pointer so I can automatically clean up with a finalizer. All of that seems to work fine. However, I now want to wrap a function pointer that looks like the following:
typedef void (*hook_func)(foo *f, int a);
My Haskell code then looks like this:
type HookFunc = Foo -> Int -> IO ()
foreign import ccall "wrapper"
mkHookFunc :: HookFunc -> IO (FunPtr HookFunc)
However, when I compile I get the following error:
Unacceptable argument type in foreign declaration:
ForeignPtr Foo
Any ideas on the best solution to this error? My initial thinking is that I need to use unsafeForeignPtrToPtr
to convert to just a foo pointer, but I'm not sure how to do this/where to put it in the "wrapper".
Any clues?