Is c2hs able to generate FunPtr rather than just the function?

Hi Everyone, I'm trying to figure out an elegant way of letting the Haskell garbage collector deal with structures allocated from C. So I have the C pair: fluid_event_t* new_fluid_event(void); void delete_fluid_event(fluid_event_t* evt); I've handled the new_fluid_event thing nicely, ForeignPtr and all. Now if I want to add a finalizer to the ForeignPtr via newForeignPtr, and for that I need a FunPtr. So what I need is: foreign import ccall safe "fluidsynth.h &delete_fluid_event" deleteFluidEvent'' :: FunPtr (((Ptr (Event)) -> (IO ()))) (if I use that as a finalizer, everything works nicely) But the closest I can get to generating something similar with c2hs is: {# fun delete_fluid_event as ^ {fromEvent `Event'} -> `()' #} which results in: foreign import ccall safe "Event.chs.h delete_fluid_event" deleteFluidEvent'_ :: ((Ptr (Event)) -> (IO ())) Is there a neat way to have c2hs generate the FunPtr version for me? Sincerely, Rafal Kolanski.

Hello Rafal, Monday, October 5, 2009, 9:18:30 AM, you wrote:
Is there a neat way to have c2hs generate the FunPtr version for me?
from my program: -- |My callback function type type CALLBACK_FUNC = Ptr CChar -> IO CInt foreign import ccall threadsafe "wrapper" mkCALL_BACK :: CALLBACK_FUNC -> IO (FunPtr CALLBACK_FUNC) key word here is "wrapper" in foreign import statement. read FFI specs for that -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com
participants (2)
-
Bulat Ziganshin
-
Rafal Kolanski