CWString API

John Meacham john at repetae.net
Tue Nov 30 04:34:50 EST 2004


On Tue, Nov 30, 2004 at 12:41:04AM -0800, Krasimir Angelov wrote:
>    Hello guys,
> 
> I am working on updated version of HDirect and now I
> am going to use CWString API to marshal (wchar_t *)
> type to String. I found some inconsistencies in the
> API. 
>   - castCWcharToChar and castCharToCWchar functions
> are defined only for Posix systems and they aren't
> exported. In the same time castCCharToChar and
> castCharToCChar have the same meaning and they are
> defined and exported on all platforms.

The problem is that these operations are very unsafe, there is no
guarenteed isomorphism or even injection between wchar_ts and Chars. If
people really know what they are doing, they can do the conversion
themselves via fromIntegral/ord/chr, but I don't think we should
encourage such unsafe usage with functions when it is simple for the
user to work around it themselves. 

>   - CWchar type looks a little bit strange compared to
> CChar, CString and CWString types. In my opinion
> CWChar looks more consistent. 

I originally had it as CWChar, but it was changed to CWchar to conform
to the already written FFI spec which defined the wchar_t equivalant to
be CWchar 

> Since the CWString API isn't released in previous GHC
> releases I think now is the time to fix that. Any
> opinions?

Any changes would have to be propegated to the FFI spec which is pretty
stable. 
        John

-- 
John Meacham - ⑆repetae.net⑆john⑈ 


More information about the Glasgow-haskell-users mailing list