cvs commit: fptools/ghc/lib/std PrelStorable.lhs fptools/hslibs/lang Storable.lhs
Marcin 'Qrczak' Kowalczyk
qrczak at knm.org.pl
Wed Mar 14 03:44:41 EST 2001
Wed, 14 Mar 2001 10:37:04 +1100, Manuel M. T. Chakravarty <chak at cse.unsw.edu.au> pisze:
> > Add 'destruct :: Ptr a -> IO ()' method to class Storable. Thanks
> > Wojciech Moczydlowski <khaliff at astercity.net> for the suggestion.
>
> Is this supposed to be a GHC-only extension of the FFI libraries?
> If not, why didn't we discuss it - or did I miss something?
Sorry, I should have discussed it.
In the Storable instance of a C struct sometimes poke wants to allocate
additional memory. E.g. the struct contains char* which corresponds to
String in Haskell.
It must be freed somewhere. Usually poke is idempotent, but in this
case it's not. There is always a well-defined piece of code derived
from what poke does, corresponding to C++'s destructor.
There was no good place to put it. It should be called by withObject /
withArray functions (I'm going to finish it), and sometimes explicitly
before free. Storable is IMHO a very good place. This method has a
default definition, so you can forget about it when using Storable
for trivial types.
Any objections?
If not, I'm going to add also destructArray and destructArray0 to
MarshalArray, and lengthArray0 while I am at it (it was used internally
so it makes sense to be provided separately), and document it.
--
__("< Marcin Kowalczyk * qrczak at knm.org.pl http://qrczak.ids.net.pl/
\__/
^^ SYGNATURA ZASTÊPCZA
QRCZAK
More information about the FFI
mailing list