ANN: H98 FFI Addendum 1.0, Release Candidate 9

Marcin 'Qrczak' Kowalczyk qrczak at knm.org.pl
Mon Jun 9 23:55:24 EDT 2003


Dnia wto 10. czerwca 2003 01:00, Ross Paterson napisał:

> I meant to say that you can't pass an HsDouble to a "polymorphic" C
> function expecting (void *),

You can pass a pointer to double.

Imagine a hashtable implemented in C. It will most probably store void *
as values. You can use it for any concrete value type by storing pointers
to values, probably living in malloced memory, unless they already are 
pointers, in which case it's implicitly convertible to and from void *.

Imagine a C API which gives you handles to pictures as opaque values.
You are supposed to use its functions only to work on the picture data.
You want to store pictures in a hashtable. If it gives you type Picture and 
doesn't say how the type is represented, you must malloc(sizeof Picture)
and store the pointer in the hashtable. But if it explicitly says that Picture
is a pointer, or it even uses Picture *, then you can store them without 
additional wrapping.

> so why should you be able to pass an HsStablePtr?

Because we can arrange that you don't need to wrap it in an additional 
pointer. Even if it was safe to cast them void *, you could not be sure -
you can't portably conclude it from the fact that it's an integral value.
Why not to provide the convenience?

-- 
   __("<         Marcin Kowalczyk
   \__/       qrczak at knm.org.pl
    ^^     http://qrnik.knm.org.pl/~qrczak/



More information about the FFI mailing list