<br><br><div class="gmail_quote">On Mon, Jun 20, 2011 at 1:46 PM, Stephen Blackheath [to GHC-iPhone] <span dir="ltr"><<a href="mailto:likeliest.complexions.stephen@blacksapphire.com">likeliest.complexions.stephen@blacksapphire.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">David,<br>
<br>
I hadn't quite grasped your code. The problem with your code is that these two lines...<br>
<br>
> func <- funky<br>
> freeHaskellFunPtr func<br>
<br>
...allocate then deallocate a function pointer, with a net result of nothing useful, and no effect on the function pointer you allocated on the third line.<br>
<br>
If you use this trick, however...<br>
<br>
{-# LANGUAGE DoRec #-}<br>
<br>
foreign import ccall safe "wrapper" mkInit<br>
:: (Ptr WorkerThread -> CInt -> IO ()) -> IO (FunPtr (Ptr WorkerThread -> CInt -> IO ()))<br>
<br>
applicationMain init dealloc = mdo<br>
fInit <- mkInit $ \callbackWorker fd -> do<br>
freeHaskellFunPtr fInit<br>
...<br>
...<br>
<br>
...then you can do it quite painlessly. Note that DoRec is correct for ghc 6.10, but its name has changed in later ghc versions. The compiler will tell you.<br></blockquote><div><br><br>Excellent! Thanks for the "pointer" oh wait... "thunk" oh wait... ;-)<br>
</div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<br>
<br>
Steve<div class="im"><br>
<br>
On 21/06/11 05:00, David Pollak wrote:<br>
</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">
<br>
<br>
On Sun, Jun 19, 2011 at 1:32 PM, Stephen Blackheath [to GHC-iPhone]<br>
<<a href="mailto:likeliest.complexions.stephen@blacksapphire.com" target="_blank">likeliest.complexions.<u></u>stephen@blacksapphire.com</a><br></div><div><div></div><div class="h5">
<mailto:<a href="mailto:likeliest.complexions.stephen@blacksapphire.com" target="_blank">likeliest.complexions.<u></u>stephen@blacksapphire.com</a>>> wrote:<br>
<br>
David,<br>
<br>
In GHC-iPhone the number of function pointers that are allowed to be<br>
active for a given function is limited, but you can change the size<br>
of the limit. This is documented in<br>
<br>
<br>
Steve,<br>
<br>
Yep... I understand that there are not an unlimited number of function<br>
pointers. However, the function that I wrote was "supposed" to<br>
automatically release the function:<br>
<br>
runOnMain :: IO () -> IO ()<br>
runOnMain todo = do<br>
func <- funky<br>
dispatchFunc func<br>
where funky = mkStrCB $ \v -> do<br>
todo<br>
func <- funky<br>
freeHaskellFunPtr func<br>
<br>
Note the freeHaskellFunPtr function call at the end of the lambda.<br>
<br>
I'm thinking that the "func <- funky" line is being treated as a<br>
recursive call and I'm also thinking that this is a limitation of my<br>
understanding the magic of lazy evaluation.<br>
<br>
So, please let me rephrase my question:<br>
<br>
How do I get the pointer to a wrapper function so that the pointer can<br>
be used within the wrapped function itself?<br>
<br>
I have worked around the particular issue by making a call to<br>
freeHaskellFunPtr in the Objective-C code that invokes the function.<br>
It's less optimal that being able to have the Haskell code be able to<br>
auto-free the function pointer after the function is invoked.<br>
<br>
Thanks,<br>
<br>
David<br>
<br>
<a href="http://projects.haskell.org/__ghc-iphone/downloads/GHC-__iPhone.pdf" target="_blank">http://projects.haskell.org/__<u></u>ghc-iphone/downloads/GHC-__<u></u>iPhone.pdf</a><br>
<<a href="http://projects.haskell.org/ghc-iphone/downloads/GHC-iPhone.pdf" target="_blank">http://projects.haskell.org/<u></u>ghc-iphone/downloads/GHC-<u></u>iPhone.pdf</a>><br>
<br>
on p5 under 'Pool sizes for foreign function "wrapper" callbacks'.<br>
<br>
<br>
Steve<br>
<br>
<br>
On 18/06/11 11:29, David Pollak wrote:<br>
<br>
Howdy,<br>
<br>
I tried to build a function that would create an auto-freeing<br>
function<br>
pointer:<br>
<br>
runOnMain :: IO () -> IO ()<br>
runOnMain todo = do<br>
func <- funky<br>
dispatchFunc func<br>
where funky = mkStrCB $ \v -> do<br>
todo<br>
func <- funky<br>
freeHaskellFunPtr func<br>
<br>
Unfortunately, I wind up getting:<br>
internal error: iPhoneCreateAdjustor - adjustor pool<br>
'Main_d2K2' is<br>
empty (capacity 32)<br>
(GHC version 6.10.4-iphone-simulator for i386_apple_darwin)<br>
<br>
I'm not sure why, but I suspect that funky is being called<br>
recursively<br>
and thus stuff is never being freed.<br>
<br>
Any hints as to the issue and solutions?<br>
<br>
Thanks,<br>
<br>
David<br>
<br>
<br>
--<br>
Lift, the simply functional web framework <a href="http://liftweb.net" target="_blank">http://liftweb.net</a><br>
Simply Lift <a href="http://simply.liftweb.net" target="_blank">http://simply.liftweb.net</a><br>
Follow me: <a href="http://twitter.com/dpp" target="_blank">http://twitter.com/dpp</a><br>
Blog: <a href="http://goodstuff.im" target="_blank">http://goodstuff.im</a><br>
<br>
<br>
<br>
______________________________<u></u>___________________<br>
iPhone mailing list<br></div></div>
<a href="mailto:iPhone@haskell.org" target="_blank">iPhone@haskell.org</a> <mailto:<a href="mailto:iPhone@haskell.org" target="_blank">iPhone@haskell.org</a>><div class="im"><br>
<a href="http://www.haskell.org/__mailman/listinfo/iphone" target="_blank">http://www.haskell.org/__<u></u>mailman/listinfo/iphone</a><br>
<<a href="http://www.haskell.org/mailman/listinfo/iphone" target="_blank">http://www.haskell.org/<u></u>mailman/listinfo/iphone</a>><br>
<br>
<br>
______________________________<u></u>___________________<br>
iPhone mailing list<br></div>
<a href="mailto:iPhone@haskell.org" target="_blank">iPhone@haskell.org</a> <mailto:<a href="mailto:iPhone@haskell.org" target="_blank">iPhone@haskell.org</a>><div class="im"><br>
<a href="http://www.haskell.org/__mailman/listinfo/iphone" target="_blank">http://www.haskell.org/__<u></u>mailman/listinfo/iphone</a><br></div><div class="im">
<<a href="http://www.haskell.org/mailman/listinfo/iphone" target="_blank">http://www.haskell.org/<u></u>mailman/listinfo/iphone</a>><br>
<br>
<br>
<br>
<br>
--<br>
Lift, the simply functional web framework <a href="http://liftweb.net" target="_blank">http://liftweb.net</a><br>
Simply Lift <a href="http://simply.liftweb.net" target="_blank">http://simply.liftweb.net</a><br>
Follow me: <a href="http://twitter.com/dpp" target="_blank">http://twitter.com/dpp</a><br>
Blog: <a href="http://goodstuff.im" target="_blank">http://goodstuff.im</a><br>
<br>
</div></blockquote>
</blockquote></div><br><br clear="all"><br>-- <br>Lift, the simply functional web framework <a href="http://liftweb.net" target="_blank">http://liftweb.net</a><div>Simply Lift <a href="http://simply.liftweb.net" target="_blank">http://simply.liftweb.net</a><br>
Follow me: <a href="http://twitter.com/dpp" target="_blank">http://twitter.com/dpp</a><br>Blog: <a href="http://goodstuff.im" target="_blank">http://goodstuff.im</a><br></div><br>