Are FunPtr's stable? (was: how to write an haskell binding)

Bulat Ziganshin wrote:
Hello Brian,
Tuesday, June 27, 2006, 2:43:15 AM, you wrote:
achieve a goal. One other thing to bear in mind is that foreign calls are extremely slow, so for example it is much faster to use the Foreign.Marshal.Array and Foreign.C.String functions to allocate and populate a temporary array with the contents of a list, and send the pointer to this array to C with one foreign call, than to send each element of the list with multiple foreign calls (eg to paste only 19K of text from the Windows clipboard to my app took over 1 minute!!!
he-he-he :) just add "unsafe" specifier:
Thanks Bulat! It turns out nearly every foreign function I'm using doesn't make callbacks into Haskell so can be marked "unsafe" so your solution has saved me an enormous amount of refactoring... :-) On a related note, as I was reading the FFI specification again, I can't find any mention of whether or not FunPtr's are stable with respect to garbage collection. I'm assuming they are but am I correct? Thanks, Brian. -- Logic empowers us and Love gives us purpose. Yet still phantoms restless for eras long past, congealed in the present in unthought forms, strive mightily unseen to destroy us. http://www.metamilk.com

On a related note, as I was reading the FFI specification again, I can't find any mention of whether or not FunPtr's are stable with respect to garbage collection. I'm assuming they are but am I correct?
Did you read Tackling the Awkward Squad? I think Section 6 (esp. 6.4.2) addresses this: http://research.microsoft.com/~simonpj/papers/marktoberdorf/ Jared. -- http://www.updike.org/~jared/ reverse ")-:"

Jared Updike wrote:
On a related note, as I was reading the FFI specification again, I can't find any mention of whether or not FunPtr's are stable with respect to garbage collection. I'm assuming they are but am I correct?
Did you read Tackling the Awkward Squad? I think Section 6 (esp. 6.4.2) addresses this: http://research.microsoft.com/~simonpj/papers/marktoberdorf/
Thanks - from 6.4.2: "Incidentally, the alert reader may have noticed that foreign import "wrapper", described in Section 6.2, must use stable pointers." Perhaps a future revision of the FFI document could also include a direct confirmation like this? Best regards, Brian. -- Logic empowers us and Love gives us purpose. Yet still phantoms restless for eras long past, congealed in the present in unthought forms, strive mightily unseen to destroy us. http://www.metamilk.com

Can I urge any of you who learn stuff that "I wish I'd know at the beginning" to add that information to GHC's FFI Wiki page? http://haskell.org/haskellwiki/GHC/Using_the_FFI Anyone can add to this material, and it's extremely helpful to jot down what you've learned while it's fresh in your mind. The current page is largely about C++ bindings, but that's only because that's what the last contributor was interested in. Feel free to re-structure it, add new sections etc. Simon | -----Original Message----- | From: haskell-cafe-bounces@haskell.org [mailto:haskell-cafe-bounces@haskell.org] On Behalf Of Brian | Hulley | Sent: 27 June 2006 22:56 | To: Jared Updike | Cc: Haskell-cafe | Subject: Re: [Haskell-cafe] Are FunPtr's stable? (was: how to write an haskellbinding) | | Jared Updike wrote: | >> On a related note, as I was reading the FFI specification again, I | >> can't find any mention of whether or not FunPtr's are stable with | >> respect to garbage collection. I'm assuming they are but am I | >> correct? | > | > Did you read Tackling the Awkward Squad? I think Section 6 (esp. | > 6.4.2) addresses this: | > http://research.microsoft.com/~simonpj/papers/marktoberdorf/ | | Thanks - from 6.4.2: | | "Incidentally, the alert reader may have noticed | that foreign import "wrapper", described | in Section 6.2, must use stable pointers." | | Perhaps a future revision of the FFI document could also include a direct | confirmation like this? | | Best regards, Brian. | | -- | Logic empowers us and Love gives us purpose. | Yet still phantoms restless for eras long past, | congealed in the present in unthought forms, | strive mightily unseen to destroy us. | | http://www.metamilk.com | | _______________________________________________ | Haskell-Cafe mailing list | Haskell-Cafe@haskell.org | http://www.haskell.org/mailman/listinfo/haskell-cafe

Simon Peyton-Jones wrote:
Can I urge any of you who learn stuff that "I wish I'd know at the beginning" to add that information to GHC's FFI Wiki page? http://haskell.org/haskellwiki/GHC/Using_the_FFI Anyone can add to this material, and it's extremely helpful to jot down what you've learned while it's fresh in your mind.
The current page is largely about C++ bindings, but that's only because that's what the last contributor was interested in. Feel free to re-structure it, add new sections etc.
I've added a section on unsafe/safe and a "Random Questions" section which will hopefully make it easier to quickly add useful things that spring to mind for anyone who doesn't want to do re-structuring - at the moment it just has the answer to "Are FunPtr's stable?" Regards, Brian. -- Logic empowers us and Love gives us purpose. Yet still phantoms restless for eras long past, congealed in the present in unthought forms, strive mightily unseen to destroy us. http://www.metamilk.com
participants (3)
-
Brian Hulley
-
Jared Updike
-
Simon Peyton-Jones