again: nullForeignPtr

Axel Simon A.Simon at kent.ac.uk
Tue Jul 8 07:47:08 EDT 2003


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.



More information about the FFI mailing list