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.
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to