Let's get this finished

Manuel M. T. Chakravarty chak at cse.unsw.edu.au
Sat Jan 6 20:42:50 EST 2001

qrczak at knm.org.pl (Marcin 'Qrczak' Kowalczyk) wrote,

> Sat, 06 Jan 2001 21:58:26 +1100, Manuel M. T. Chakravarty <chak at cse.unsw.edu.au> pisze:
> > >     type CString    = Ptr CChar
> > >     type CStringLen = (CString, Int)
> > 
> > Hmmm, yes, although pointer/length pairs are not very common
> > in C and this module is a language dependent module (and so
> > should be called `MarshalCString').
> I added the explicit-length variants when I needed them for the Python
> interface, after I realized that it's not possible to express them
> with variants which always stoped on input '\0' and didn't mark the
> output length besides writing a '\0'. The '\0' variants are now small
> wrappers around the explicit-length variants.

Yes, this is how I did it in C2HS, too.  It is the most
natural solution.

> > But SimonM said that he doesn't want to make errno Haskell thread
> > local...
> It would force wrapping every C function which may set errno in another
> C function which returns the error in a thred-safe way. The wrapper
> would have to check for errno and pass it in some way to Haskell
> together with the proper result - either through a pointer (which needs
> extra alloca per C function call) or special thread-local variables.
> It would be really bad to not have thread-local errno.

I agree.  Let's see what Simon's current opinion regarding
this topic is.

> > This has been changed now, hasn't it?
> Everybody agreed that "let" should be used instead of "with",
> but the change has not been made yet.
> > There is one exception: MarshalCString shouldn't be
> > re-exported by Foreign (like CTypes).
> If language separation is realistic, we would also keep errno handling
> outside basic Foreign. But it yields several separate C-specific modules...
> module CForeign?
> It would reexport Foreign, CTypes, CTypesISO, MarshalCString and CErrors
> (or whatever they will be called).

Good idea!

> BTW, why are CTypes and CTypesISO separate?

IIRC, the idea was to have the types defined by the
standard C libraries in an extra module.  But it is not that
important, I think.


More information about the FFI mailing list