From: Jeremy O'D. <jer...@gm...> - 2012-05-14 08:43:35
|
Hi Fabian, On 12 May 2012 16:12, Fabian Binz <fab...@ya...> wrote: > Hi Jeremy, **** > > I don't know if you continued working on this, but I forked wxHaskell on > GitHub and tried to implement it myself: > https://github.com/FabianBinz/wxHaskell > I have been doing some work, but I don't have a lot of time right now, so it is going more slowly than I would like. > For testing purposes, I only implemented the OnGetItemText and > SetItemCount method and it seems to work. > > To implement the "virtual" list control, I defined a new class > wxVirtualListCtrl in wxc:**** > > > https://github.com/FabianBinz/wxHaskell/blob/master/wxc/src/include/virtuallistctrl_impl.h > **** > > Since it needs to invoke a callback function, I created the typedef > OnGetItemTextCallback. To make wxdirect accept this new type, I extended > the parser (patomtype) in ParseC.hs. This solution is very ad-hoc and I > think because wxc is supposed to be a language agnostic C wrapper, we > should maybe add another macro to wcx_types.hs (something like TCallback), > which is then recognized by wxdirect.**** > > So, while this all works pretty well, there is unfortunately a memory leak > in Graphics.UI.WXCore.VirtualListCtrl, because of my use of newCString. At > the moment I don't know how to fix it and would be glad if someone could > give me some advice. > You need to use a finalizer - this is what I am looking into. There is an overview at http://www.haskell.org/haskellwiki/GHC/Using_the_FFI#Calling_Haskell_from_C, but it could be clearer! Basic idea is that you free the CString when the GC has no more references to the closure in which it is used. I am using the event handler code as a model, since this already allows callbacks from C to Haskell, and handles reference counting. Just haven't finished yet. I will take a look at your fork and see if you are further along than me, and take code accordingly. Best regards Jeremy |