diff options
author | Max Bolingbroke <batterseapower@hotmail.com> | 2011-05-14 22:50:46 +0100 |
---|---|---|
committer | Max Bolingbroke <batterseapower@hotmail.com> | 2011-05-14 22:50:46 +0100 |
commit | dc58b7398910a433259a6c0f58a0d05a48555191 (patch) | |
tree | a01062281a0cf1dd42329110ff0d0326be407f2b /libraries/base/System/Posix/Internals.hs | |
parent | cdbce1218d9f9fb4152bdabffe8bbdee09f5ce60 (diff) | |
download | haskell-dc58b7398910a433259a6c0f58a0d05a48555191.tar.gz |
Big patch to improve Unicode support in GHC. Validated on OS X and Windows, this
patch series fixes #5061, #1414, #3309, #3308, #3307, #4006 and #4855.
The major changes are:
1) Make Foreign.C.String.*CString use the locale encoding
This change follows the FFI specification in Haskell 98, which
has never actually been implemented before.
The functions exported from Foreign.C.String are partially-applied
versions of those from GHC.Foreign, which allows the user to supply
their own TextEncoding.
We also introduce foreignEncoding as the name of the text encoding
that follows the FFI appendix in that it transliterates encoding
errors.
2) I also changed the code so that mkTextEncoding always tries the
native-Haskell decoders in preference to those from iconv, even on
non-Windows. The motivation here is simply that it is better for
compatibility if we do this, and those are the ones you get for
the utf* and latin1* predefined TextEncodings anyway.
3) Implement surrogate-byte error handling mode for TextEncoding
This implements PEP383-like behaviour so that we are able to
roundtrip byte strings through Strings without loss of information.
The withFilePath function now uses this encoding to get to/from CStrings,
so any code that uses that will get the right PEP383 behaviour automatically.
4) Implement three other coding failure modes: ignore, throw error, transliterate
These mimic the behaviour of the GNU Iconv extensions.
Diffstat (limited to 'libraries/base/System/Posix/Internals.hs')
-rw-r--r-- | libraries/base/System/Posix/Internals.hs | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/libraries/base/System/Posix/Internals.hs b/libraries/base/System/Posix/Internals.hs index 4a83635983..6a30ba07e8 100644 --- a/libraries/base/System/Posix/Internals.hs +++ b/libraries/base/System/Posix/Internals.hs @@ -51,6 +51,10 @@ import GHC.IO import GHC.IO.IOMode import GHC.IO.Exception import GHC.IO.Device +#ifndef mingw32_HOST_OS +import {-# SOURCE #-} GHC.IO.Encoding (fileSystemEncoding) +import qualified GHC.Foreign as GHC +#endif #elif __HUGS__ import Hugs.Prelude (IOException(..), IOErrorType(..)) import Hugs.IO (IOMode(..)) @@ -65,6 +69,18 @@ import DIOError {-# CFILES cbits/PrelIOUtils.c cbits/consUtils.c #-} #endif + +-- --------------------------------------------------------------------------- +-- Debugging the base package + +puts :: String -> IO () +puts s = withCAStringLen (s ++ "\n") $ \(p, len) -> do + -- In reality should be withCString, but assume ASCII to avoid loop + -- if this is called by GHC.Foreign + _ <- c_write 1 (castPtr p) (fromIntegral len) + return () + + -- --------------------------------------------------------------------------- -- Types @@ -171,10 +187,26 @@ fdGetMode fd = do #ifdef mingw32_HOST_OS withFilePath :: FilePath -> (CWString -> IO a) -> IO a -withFilePath = withCWString +withFilePath = withCWString + +peekFilePath :: CWString -> IO FilePath +peekFilePath = peekCWString #else + withFilePath :: FilePath -> (CString -> IO a) -> IO a +peekFilePath :: CString -> IO FilePath +peekFilePathLen :: CStringLen -> IO FilePath + +#if __GLASGOW_HASKELL__ +withFilePath = GHC.withCString fileSystemEncoding +peekFilePath = GHC.peekCString fileSystemEncoding +peekFilePathLen = GHC.peekCStringLen fileSystemEncoding +#else withFilePath = withCString +peekFilePath = peekCString +peekFilePathLen = peekCStringLen +#endif + #endif -- --------------------------------------------------------------------------- |