Finali[zs]ers

John Meacham john at repetae.net
Wed Oct 16 16:24:21 EDT 2002


it was less an argument either way and more of a statement of
consequence as to what disallowing Haskell finalizers would cause. The
problem can best be summed up by this snippet of the current FFI spec. 

excerpt from FFI:

	touchForeignPtr :: ForeignPtr a -> IO () Ensure that the
	foreign object in question is alive at the given place in
	the sequence of IO actions.  In particular, withForeignPtr
	does a touchForeignPtr after it executes the user action. 
	  
	  This function can be used to express liveness dependencies
	between ForeignPtrs: For example, if the finalizer for one
	ForeignPtr touches a second ForeignPtr, then it is ensured
	that the second ForeignPtr will stay alive at least as long
	as the first. This can be useful when you want to manipulate
	interior pointers to a foreign structure: You can use
	touchForeignPtr to express the requirement that the exterior
	pointer must not be finalized until the interior pointer is
	no longer referenced.


without haskell finalizers, one cannot touch another ForeignPtr the fact
that this is in the ffi but haskell finalizers arn't makes me think the
switch to foreign only finalizers was not well thought out in the first
place.

if we disallow Haskell finalizers, then some other mechanism will have
to be added to make up for loosing this one. (Weak pointers are one such
way).
	John


On Tue, Oct 15, 2002 at 08:57:55AM +0100, Simon Peyton-Jones wrote:
> John
> 
> I'm not quite sure what you mean.  I think you are saying that this is a
> reason it's important to have Haskell finalizers, but I'm not sure.  How
> would you like to write a paragraph or two to explain the issue, and we
> can put it in the document?  That way it would say what you mean.  
> 
> Simon
> 
> | -----Original Message-----
> | From: John Meacham [mailto:john at repetae.net]
> | Sent: 14 October 2002 22:22
> | To: ffi at haskell.org
> | Subject: Re: Finali[zs]ers
> | 
> | I dont have cvs write access but you should mention something about
> | expressing gc dependencies between ForeignPtr's. the only two ways to
> do
> | this in the current haskell systems are
> | * weak pointers
> | * touchForeignPtr from the finalizer of another ForeignPtr
> | 
> | if the second one is not allowed by restricting us to C only
> finalizers,
> | then the first needs to be added into the FFI, (or some other
> mechanism
> | invented). I consider this functionality vital for any non-trivial use
> | of ForeignPtr, and it becomes more important as we move more stuff to
> C
> | land, as C structures become more common.
> | 
> | for more info on the use of this, see the FFI touchForeignPtr
> | documentation and the paper describing Weak pointers in ghc. the fact
> | that multiple people saw the need for this and came up with solutions
> | probably says something about its usefulness.
> | 	John
> | 
> | On Mon, Oct 14, 2002 at 06:16:05PM +0100, Simon Marlow wrote:
> | > > Thanks to everyone who has contributed to this discussion so
> | > > far.  Since
> | > > there are a lot of subtle points to be considered at once, I
> | > > thought I'd
> | > > try to write a summary of the issues raised so far.
> | > >
> | > > I'll put something in the repository so we can all hack on it.
> | > > Hopefully I'll have something ready later today.
> | >
> | > oops, I should have mentioned that if you just want to read the
> | > document, it will be available here:
> | >
> | >
> | >
> http://cvs.haskell.org/cgi-bin/cvsweb.cgi/haskell-report/ffi/finalizers.
> | > txt
> | >
> | > just as soon as the CVS web server updates its repository.
> | >
> | > Cheers,
> | > 	Simon
> | >
> | > _______________________________________________
> | > FFI mailing list
> | > FFI at haskell.org
> | > http://www.haskell.org/mailman/listinfo/ffi
> | 
> | --
> |
> ------------------------------------------------------------------------
> ---
> | John Meacham - California Institute of Technology, Alum. -
> john at foo.net
> |
> ------------------------------------------------------------------------
> ---
> | _______________________________________________
> | FFI mailing list
> | FFI at haskell.org
> | http://www.haskell.org/mailman/listinfo/ffi

-- 
---------------------------------------------------------------------------
John Meacham - California Institute of Technology, Alum. - john at foo.net
---------------------------------------------------------------------------



More information about the FFI mailing list