Let's get this finished

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


Sven Panne <Sven.Panne at informatik.uni-muenchen.de> wrote,

> > [ MarshalString ]
> > 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').
> 
> Granted. And remember we already have a (quite ugly) module CString!

Is anybody actually depending on the old `CString'?  Or is
everybody using `PackedString' instead?

> So here is a new proposal:
> 
>    * Deprecate the old definitions in CString and add

The old definitions also include ByteArray stuff.  If they
are still needed, we may have to leave them in as a GHC
extension. 

>         type CString    = Ptr CChar
>         mallocCString    :: String -> IO CString
>         peekCString      :: CString -> IO String
>         pokeCString      :: CString -> String -> IO ()
>         withCString      :: String -> (CString -> IO a) -> IO a
>         newCString       :: String -> IO CString
> 
>    * Add a new module CStringLen with
> 
>         type CStringLen = (CString, Int)
>         mallocCStringLen :: String -> IO CStringLen
>         peekCStringLen   :: CStringLen -> IO String
>         pokeCStringLen   :: CStringLen -> String -> IO ()
>         withCStringLen   :: String -> (CStringLen -> IO a) -> IO a
>         newCStringLen    :: String -> IO CStringLen

I think, we need the alloca and realloc versions, too.
(Eg, Marcin needs the latter for his unicode stuff, I
think.)  

Otherwise, this sounds fine to me.

> > [ MarshalError ]
> > But SimonM said that he doesn't want to make errno Haskell
> > thread local...
> 
> Wasn't this only due to efficiency reasons? IIRC Fergus had a good
> suggestion (copying errno only on thread switches or something), so
> I'd like to hear Mr. HsLibs' opinion on this topic again.

I also think that this should be possible.  Simon?

> > [ MarshalUtils ]
> > BTW, can't we just use `with' now.  IIRC, the only reason
> > Marcin used `withObject' was because of a clash with the
> > implicit parameter extension.  This has been changed now,
> > hasn't it?
> 
> Nope, not yet. Although there was some consensus about SPJ's
> ?-suggestion for those bindings, it's not implemented yet.
> Any takers? If this has been done, `with' would be better, indeed.

So, let's make it `with' officially and implement
`withObject' flagging it as a GHC bug :-)

> > [ module (re-)exports ]
> > I was thinking of an extra module mainly because the
> > MarshalXXX code is system independent - in contrast to the
> > code in `Foreign'.  However, we may also just let Foreign
> > do the whole job.  Thinking about it again, I doubt that
> > anybody will ever import one module, but not the other -
> > so, let's make Foreign export the whole lot.
> > 
> > There is one exception: MarshalCString shouldn't be
> > re-exported by Foreign (like CTypes).
> 
> I'd opt for this too: Foreign re-exports MarshalAlloc, MarshalArray,
> MarshalError and MarshalUtils and *not* CString/CStringLen.

Ok.

> > > And just a final topic which really should be settled:
> > > "Marshal" or "Marshall"??   :-}
> > 
> > I would have taken the latter, but I think, SimonM
> > originally proposed the name MarshalUtils with one "l" and
> > as he is the native speaker...
> 
> *sigh* Have to change HOpenGL once again...   :-P

Oh - we can still change it.  Native speakers (Simon,
Malcolm, ...), shall we make it MarshallXXX?

Cheers,
Manuel




More information about the FFI mailing list