Marcin 'Qrczak' Kowalczyk wrote:
> On the one hand, I certainly would not be happy to add to all
> those 50 foreign imports that use ForeignObjs code dealing with
> protecting them.

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. What e.g. about stable pointers? Should they
be dereferenced automatically or not? Should memory allocated for
passing Strings be deallocated after a foreign call or not? This all
depends on your application, so there's no general rule which serves
all. OTOH, the pattern needed for protecting foreign objects

   ...
   foo <- prepareSomething
   bar <- callForeignFunctionUsing foo
   aftermath foo bar
   ...

is common enough that FFI libs should support it conveniently.

> [...] 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.

> [...] The StablePtr trick, if would be required, has a flaw: when
> forgotten, silently leads to incorrect code.

Hmmm, using foreign functions is dangerous anyway, and forgetting to
protect a foreign object is one of the easiest bugs to find... :-}
 
> A function of type (Addr -> IO a) -> (ForeignObj -> IO a) [...]
> only is not enough because there are several patterns of arguments
> [...] The drawback of marsh* is that calls are not uniform.
> [...] I have no presise idea how to make them better, sorry,

If *we* had a good idea yet, the higher-level FFI lib would be
finished already. :-)

> but I believe it's possible. [...]

So do we. I think what is needed to come up with a good design is
a bunch of typical code patterns around foreign calls. In a next step
they should be made compositional (which is not really the case in the
current Marshal/C2HSMarsh proposals) and then a nice syntax could be
invented.

Cheers,
   Sven
-- 
Sven Panne                                        Tel.: +49/89/2178-2235
LMU, Institut fuer Informatik                     FAX : +49/89/2178-2211
LFE Programmier- und Modellierungssprachen              Oettingenstr. 67
mailto:[EMAIL PROTECTED]            D-80538 Muenchen
http://www.informatik.uni-muenchen.de/~Sven.Panne

Reply via email to