Mon, 21 Feb 2000 11:57:18 +0100, Sven Panne <[EMAIL PROTECTED]>
pisze:
> Granted, but nevertheless I support Manuel's view: The FFI should
> deal with *primitive* types automatically and libraries/tools should
> take care of the rest.
In principle I agree, but here IMHO manual protection would be painful
and error prone, and the current behavior is convenient and safe enough
to be kept. Easy: as long as a ForeignObj stays as a ForeignObj, it is
alive. A ForeignObj passed to a C function is assumed alive, because
you can't tell more exactly and this assumption is safe. Moreover,
this is IMHO most commonly wanted.
> What e.g. about stable pointers? Should they be dereferenced
> automatically or not?
No, because I want to pass them around in the C world, store in them in
C data structures and pass them back to Haskell later. (Yes, really.)
> Should memory allocated for passing Strings be deallocated after
> a foreign call or not?
It depends, so the place for it is in a library. But a default most
common behavior could be built into FFI as well: it would have '\0'
at the end and stay alive until the called function returns.
> This all depends on your application, so there's no general rule
> which serves all.
With ForeignObj there is a good general rule, and if you want complete
control and allow earlier finalization, you can pass raw Addrs to C
and use StablePtrs for specifying the lifetime.
In fact switching from finalized Addrs to ForeignObjs helped me to
fix about two places where I forgotten to add a finalizer to the Addr
returned from a C function. Static typing is good.
> > [...] On the other hand, if it means that a foreign import that
> > calls back to Haskell (in extremely rare circumstances some can)
>
> Again, this is highly application-dependent, e.g. if a callback-based
> GUI is used, calling back Haskell from C land is the normal case.
Yes, I meant that in my case it was rare (so it would be a pity if
such a rare possibility would force complication of half of foreign
imports, and it would be very hard to debug if eventually happened
with bad consequences).
--
__("< Marcin Kowalczyk * [EMAIL PROTECTED] http://qrczak.ids.net.pl/
\__/ GCS/M d- s+:-- a22 C+++$ UL++>++++$ P+++ L++>++++$ E-
^^ W++ N+++ o? K? w(---) O? M- V? PS-- PE++ Y? PGP+ t
QRCZAK 5? X- R tv-- b+>++ DI D- G+ e>++++ h! r--%>++ y-