g'day everyone,
I'm getting segv's from a program using the FFI (ghc5.0x) on MacOS X only, i.e. not on Linux, my primary development platform.
So... does anyone have any tips for showing up dodgy uses of the FFI wrt memory handling? What settings for GHC's garbage collector will create the most pathological situations?
Also, I have some qualms about foreignPtrToPtr; by it's type, it seems to be exactly what you want most of the time, but due to the "if this is the last reference, the finalizers may run" caveat it almost always isn't. I note that it already has some warnings attached to it, but...
Most of the time you should be using 'withForeignPtr'. I don't think there can be any legitimate uses for foreignPtrToPtr unless there is a touchForeignPtr that is guaranteed to happen later. And that's a tricky guarantee, because it involves reasoning about strictness. Does anyone else think that foreignPtrToPtr should really be called unsafeForeignPtrToPtr?
- does anyone have a safe use for it that doesn't involve touchForeignPtr?
- can the FFI spec somehow group together all functions that may introduce memory leaks or unsafety?
Unsafety is normally indicated with an 'unsafe' prefix on the function name. Memory leaks are a different matter - since malloc on its own can introduce a memory leak, I'm not sure how you'd indicate that. Cheers, Simon
Malcolm Wallace <Malcolm.Wallace@cs.york.ac.uk> wrote,
"Simon Marlow" <simonmar@microsoft.com> writes:
Does anyone else think that foreignPtrToPtr should really be called unsafeForeignPtrToPtr?
Yes, I agree.
Ok, so unless their are any objections, I will rename the function. Manuel
On Tue, 10 Jun 2003, Simon Marlow wrote:
Does anyone else think that foreignPtrToPtr should really be called unsafeForeignPtrToPtr?
I was actually advocating that it be disposed of, but thought that would be too forward of me. What use is it without touchForeignPtr, and if the latter depends on strictness anyway, how many uses of it are safe and aren't captured by withForeignPtr? cheers peter
Peter Gammie <peteg@cse.unsw.edu.au> wrote,
On Tue, 10 Jun 2003, Simon Marlow wrote:
Does anyone else think that foreignPtrToPtr should really be called unsafeForeignPtrToPtr?
I was actually advocating that it be disposed of, but thought that would be too forward of me. What use is it without touchForeignPtr, and if the latter depends on strictness anyway, how many uses of it are safe and aren't captured by withForeignPtr?
We had this discussion before. foreignPtrToPtr is mainly useful for generators and, yes, you need to combine it with touchForeignPtr. Manuel
participants (4)
-
Malcolm Wallace -
Manuel M T Chakravarty -
Peter Gammie -
Simon Marlow