Let's get this finished

Marcin 'Qrczak' Kowalczyk mk167280 at students.mimuw.edu.pl
Mon Jan 15 07:40:02 EST 2001


On Mon, 15 Jan 2001, Simon Marlow wrote:

> 	data UnsafeCString
> 	withUnsafeCString :: String -> (UnsafeCString -> IO a) -> IO a
> 
> where an UnsafeCString is valid only in an argument position of an
> unsafe foreign import.

Much of the conversion stuff would have to be done in a different way.
An additional internal interface to conversions implemented in C
(with ByteArrays instead of Ptrs), pointer arithmetic moved from
Haskell to C, and in future hard to mix with Handle I/O done on
Ptrs.

All because there is no safe way to safely get a Ptr to a ByteArray to be
used in Haskell.

> I still can't think of a good way to do this in general.  Perhaps
> enhancing the garbage collector so that it could "pin" objects - but
> you've still got the problem of keeping the lifetime of the ByteArray
> in sync with the Ptr.

Lifetime is not a problem:
    withByteArray :: ByteArray -> (Ptr a -> IO b) -> IO b

(And now we know that the ByteArray type should be parametrized!)

This begins looking similarly to ForeignPtr from the outside.

-- 
Marcin 'Qrczak' Kowalczyk





More information about the FFI mailing list