Hi, the discussion on ForeignPtrs without finalizers didn't come to a conclusion. I specifically need the nullForeignPtr which was easy enough with the FFI of GHC 5.04: newForeignPtr nullPtr (return ()) Judging from the source code of GHC 6.0, newForeignPtr nullPtr nullFunPtr will lead to a crash when the finalizer is executed. Could that be fixed in 6.0.1? Or do I have to create a dummy C function? Thanks, Axel.
the discussion on ForeignPtrs without finalizers didn't come to a conclusion. I specifically need the nullForeignPtr which was easy enough with the FFI of GHC 5.04: [...] do I have to create a dummy C function?
Yes, create a dummy C function. (Actually, you could use 'free' since it does nothing if passed NULL.) -- Alastair ps Personally, I would use Maybe (ForeignPtr a) in the places where you are currently using a ForeignPtr which could be null with 'Just x' being used only when x is not null. I haven't tried exactly this but I have lots of experience using Maybe (Ptr a) in this way and it works great: Haskell's type system catches errors that would be runtime errors in C.
On Mon, Jul 07, 2003 at 07:31:13PM +0100, Alastair Reid wrote:
the discussion on ForeignPtrs without finalizers didn't come to a conclusion. I specifically need the nullForeignPtr which was easy enough with the FFI of GHC 5.04: [...] do I have to create a dummy C function?
Yes, create a dummy C function. (Actually, you could use 'free' since it does nothing if passed NULL.)
That's a good tip. Thanks.
ps Personally, I would use
Maybe (ForeignPtr a)
in the places where you are currently using a ForeignPtr which could be null with 'Just x' being used only when x is not null. Oh, I do indeed. The need for nullForeignPtr arises when a function expects a pointer to some data structure or a null pointer. In this case I cannot make the foreign import have the type (Maybe (ForeignPtr ()) since it's not accepted by the FFI.
Thanks, Axel.
The need for nullForeignPtr arises when a function expects a pointer to some data structure or a null pointer. In this case I cannot make the foreign import have the type (Maybe (ForeignPtr ()) since it's not accepted by the FFI.
I guess I've mostly used this trick with GreenCard whcih supports this idiom quite well. Mind you, ForeignPtr isn't accepted by the FFI either so the code you currently use to marshall them could be modified to marshall Maybe (ForeignPtr ()) instead. -- Alastair
Axel Simon <A.Simon@kent.ac.uk> wrote,
the discussion on ForeignPtrs without finalizers didn't come to a conclusion. I specifically need the nullForeignPtr which was easy enough with the FFI of GHC 5.04:
newForeignPtr nullPtr (return ())
The discussion came to a conclusion with newForeignPtr_ :: Ptr a -> IO (ForeignPtr a) being added in RC 11. Manuel
participants (3)
-
Alastair Reid -
Axel Simon -
Manuel M T Chakravarty