- 23 Jun, 2009 2 commits
-
-
Simon Marlow authored
-
Simon Marlow authored
-
- 22 Jun, 2009 2 commits
-
-
Simon Marlow authored
-
Simon Marlow authored
-
- 18 Jun, 2009 2 commits
-
-
Simon Marlow authored
-
Simon Marlow authored
-
- 20 Jun, 2009 1 commit
-
-
Ian Lynagh authored
It used to only exist if (WORD_SIZE_IN_BITS == 32 || WORD_SIZE_IN_BITS == 64)
-
- 15 Jun, 2009 2 commits
-
-
Ian Lynagh authored
It was breaking the build on Windows. The problem was that we included stdio.h which gave a prototype for some functions (e.g. remove), then the AC_C_CONST meant that we did /* Define to empty if `const' does not conform to ANSI C. */ #define const /**/ and then we included io.h which gave prototypes that, due to const being removed, conflicted with the earlier prototypes.
-
Ian Lynagh authored
-
- 12 Jun, 2009 1 commit
-
-
Duncan Coutts authored
The gcdInt# primop uses gmp internally, even though the interface is just Int#. Since we want to get gmp out of the rts we cannot keep gcdInt#, however it's also a bit odd for the integer package to export something that doesn't actually use Integer in its interface. Using gcdInteger is still not terribly satisfactory aesthetically. However in the short-term it works and it is no slower since gcdInteger calls gcdInt# for the special case of two small Integers.
-
- 20 Jun, 2009 1 commit
-
-
Ian Lynagh authored
-
- 15 Jun, 2009 2 commits
-
-
Ian Lynagh authored
-
Ian Lynagh authored
-
- 14 Jun, 2009 1 commit
-
-
Simon Marlow authored
We previously had an ugly hack to check for a BOM when re-decoding some binary data in flushCharBuffer. The hack was there essentially because codecs like UTF-16 have a state, and we had not restored it. This patch gives codecs an explicit state, and implemented saving/restoring of the state as necessary. Hence, the hack in flushCharBuffer is replaced by a more general mechanism that works for any codec with state. Unfortunately, iconv doesn't give us a way to save and restore the state, so this is currently only implemented for the built-in codecs.
-
- 16 Jun, 2009 1 commit
-
-
Simon Marlow authored
-
- 15 Jun, 2009 1 commit
-
-
Malcolm.Wallace@cs.york.ac.uk authored
Also affects GHC.IO.Device, which is not very GHC-specific at all.
-
- 12 Jun, 2009 2 commits
-
-
Ian Lynagh authored
For example, we need -liconv on OS X.
-
Simon Marlow authored
Highlights: * Unicode support for Handle I/O: ** Automatic encoding and decoding using a per-Handle encoding. ** The encoding defaults to the locale encoding (only on Unix so far, perhaps Windows later). ** Built-in UTF-8, UTF-16 (BE/LE), and UTF-32 (BE/LE) codecs. ** iconv-based codec for other encodings on Unix * Modularity: the low-level IO interface is exposed as a type class (GHC.IO.IODevice) so you can build your own low-level IO providers and make Handles from them. * Newline translation: instead of being Windows-specific wired-in magic, the translation from \r\n -> \n and back again is available on all platforms and is configurable for reading/writing independently. Unicode-aware Handles ~~~~~~~~~~~~~~~~~~~~~ This is a significant restructuring of the Handle implementation with the primary goal of supporting Unicode character encodings. The only change to the existing behaviour is that by default, text IO is done in the prevailing locale encoding of the system (except on Windows [1]). Handles created by openBinaryFile use the Latin-1 encoding, as do Handles placed in binary mode using hSetBinaryMode. We provide a way to change the encoding for an existing Handle: GHC.IO.Handle.hSetEncoding :: Handle -> TextEncoding -> IO () and various encodings (from GHC.IO.Encoding): latin1, utf8, utf16, utf16le, utf16be, utf32, utf32le, utf32be, localeEncoding, and a way to lookup other encodings: GHC.IO.Encoding.mkTextEncoding :: String -> IO TextEncoding (it's system-dependent whether the requested encoding will be available). We may want to export these from somewhere more permanent; that's a topic for a future library proposal. Thanks to suggestions from Duncan Coutts, it's possible to call hSetEncoding even on buffered read Handles, and the right thing happens. So we can read from text streams that include multiple encodings, such as an HTTP response or email message, without having to turn buffering off (though there is a penalty for switching encodings on a buffered Handle, as the IO system has to do some re-decoding to figure out where it should start reading from again). If there is a decoding error, it is reported when an attempt is made to read the offending character from the Handle, as you would expect. Performance varies. For "hGetContents >>= putStr" I found the new library was faster on my x86_64 machine, but slower on an x86. On the whole I'd expect things to be a bit slower due to the extra decoding/encoding, but probabaly not noticeably. If performance is critical for your app, then you should be using bytestring and text anyway. [1] Note: locale encoding is not currently implemented on Windows due to the built-in Win32 APIs for encoding/decoding not being sufficient for our purposes. Ask me for details. Offers of help gratefully accepted. Newline Translation ~~~~~~~~~~~~~~~~~~~ In the old IO library, text-mode Handles on Windows had automatic translation from \r\n -> \n on input, and the opposite on output. It was implemented using the underlying CRT functions, which meant that there were certain odd restrictions, such as read/write text handles needing to be unbuffered, and seeking not working at all on text Handles. In the rewrite, newline translation is now implemented in the upper layers, as it needs to be since we have to perform Unicode decoding before newline translation. This means that it is now available on all platforms, which can be quite handy for writing portable code. For now, I have left the behaviour as it was, namely \r\n -> \n on Windows, and no translation on Unix. However, another reasonable default (similar to what Python does) would be to do \r\n -> \n on input, and convert to the platform-native representation (either \r\n or \n) on output. This is called universalNewlineMode (below). The API is as follows. (available from GHC.IO.Handle for now, again this is something we will probably want to try to get into System.IO at some point): -- | The representation of a newline in the external file or stream. data Newline = LF -- ^ "\n" | CRLF -- ^ "\r\n" deriving Eq -- | Specifies the translation, if any, of newline characters between -- internal Strings and the external file or stream. Haskell Strings -- are assumed to represent newlines with the '\n' character; the -- newline mode specifies how to translate '\n' on output, and what to -- translate into '\n' on input. data NewlineMode = NewlineMode { inputNL :: Newline, -- ^ the representation of newlines on input outputNL :: Newline -- ^ the representation of newlines on output } deriving Eq -- | The native newline representation for the current platform nativeNewline :: Newline -- | Map "\r\n" into "\n" on input, and "\n" to the native newline -- represetnation on output. This mode can be used on any platform, and -- works with text files using any newline convention. The downside is -- that @readFile a >>= writeFile b@ might yield a different file. universalNewlineMode :: NewlineMode universalNewlineMode = NewlineMode { inputNL = CRLF, outputNL = nativeNewline } -- | Use the native newline representation on both input and output nativeNewlineMode :: NewlineMode nativeNewlineMode = NewlineMode { inputNL = nativeNewline, outputNL = nativeNewline } -- | Do no newline translation at all. noNewlineTranslation :: NewlineMode noNewlineTranslation = NewlineMode { inputNL = LF, outputNL = LF } -- | Change the newline translation mode on the Handle. hSetNewlineMode :: Handle -> NewlineMode -> IO () IO Devices ~~~~~~~~~~ The major change here is that the implementation of the Handle operations is separated from the underlying IO device, using type classes. File descriptors are just one IO provider; I have also implemented memory-mapped files (good for random-access read/write) and a Handle that pipes output to a Chan (useful for testing code that writes to a Handle). New kinds of Handle can be implemented outside the base package, for instance someone could write bytestringToHandle. A Handle is made using mkFileHandle: -- | makes a new 'Handle' mkFileHandle :: (IODevice dev, BufferedIO dev, Typeable dev) => dev -- ^ the underlying IO device, which must support -- 'IODevice', 'BufferedIO' and 'Typeable' -> FilePath -- ^ a string describing the 'Handle', e.g. the file -- path for a file. Used in error messages. -> IOMode -- ^ The mode in which the 'Handle' is to be used -> Maybe TextEncoding -- ^ text encoding to use, if any -> NewlineMode -- ^ newline translation mode -> IO Handle This also means that someone can write a completely new IO implementation on Windows based on native Win32 HANDLEs, and distribute it as a separate package (I really hope somebody does this!). This restructuring isn't as radical as previous designs. I haven't made any attempt to make a separate binary I/O layer, for example (although hGetBuf/hPutBuf do bypass the text encoding and newline translation). The main goal here was to get Unicode support in, and to allow others to experiment with making new kinds of Handle. We could split up the layers further later. API changes and Module structure ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ NB. GHC.IOBase and GHC.Handle are now DEPRECATED (they are still present, but are just re-exporting things from other modules now). For 6.12 we'll want to bump base to version 5 and add a base4-compat. For now I'm using #if __GLASGOW_HASKEL__ >= 611 to avoid deprecated warnings. I split modules into smaller parts in many places. For example, we now have GHC.IORef, GHC.MVar and GHC.IOArray containing the implementations of IORef, MVar and IOArray respectively. This was necessary for untangling dependencies, but it also makes things easier to follow. The new module structurue for the IO-relatied parts of the base package is: GHC.IO Implementation of the IO monad; unsafe*; throw/catch GHC.IO.IOMode The IOMode type GHC.IO.Buffer Buffers and operations on them GHC.IO.Device The IODevice and RawIO classes. GHC.IO.BufferedIO The BufferedIO class. GHC.IO.FD The FD type, with instances of IODevice, RawIO and BufferedIO. GHC.IO.Exception IO-related Exceptions GHC.IO.Encoding The TextEncoding type; built-in TextEncodings; mkTextEncoding GHC.IO.Encoding.Types GHC.IO.Encoding.Iconv GHC.IO.Encoding.Latin1 GHC.IO.Encoding.UTF8 GHC.IO.Encoding.UTF16 GHC.IO.Encoding.UTF32 Implementation internals for GHC.IO.Encoding GHC.IO.Handle The main API for GHC's Handle implementation, provides all the Handle operations + mkFileHandle + hSetEncoding. GHC.IO.Handle.Types GHC.IO.Handle.Internals GHC.IO.Handle.Text Implementation of Handles and operations. GHC.IO.Handle.FD Parts of the Handle API implemented by file-descriptors: openFile, stdin, stdout, stderr, fdToHandle etc.
-
- 11 Jun, 2009 1 commit
-
-
Duncan Coutts authored
-
- 05 Jun, 2009 1 commit
-
-
Malcolm.Wallace@cs.york.ac.uk authored
Fixes this bootstrapping error: Undefined symbols: "___hscore_readdir", referenced from: _FR_System_46Posix_46Internals_46readdir_35 in libHSbase.a(Internals.o)
-
- 02 Jun, 2009 1 commit
-
-
Ian Lynagh authored
-
- 29 May, 2009 2 commits
-
-
Simon Marlow authored
-
simonpj@microsoft.com authored
Now that -Werror rejects programs that use silent type-class defaulting, we must commit in the source code. I've used Double in CPUTime, which is the same as was picked automatically before, but I expect Float would be ok. realToInteger :: Real a => a -> Integer realToInteger ct = round (realToFrac ct :: Double) In GHC.Float I used Float (rather that than the auto-picked Double) because I'm pretty certain it has enough precision. -- f :: Integer, log :: Float -> Float, -- ceiling :: Float -> Int ceiling ((log (fromInteger (f+1) :: Float) +
-
- 28 May, 2009 1 commit
-
-
Simon Marlow authored
-
- 24 May, 2009 1 commit
-
-
Ian Lynagh authored
-
- 23 May, 2009 2 commits
-
-
Ian Lynagh authored
-
Ian Lynagh authored
-
- 20 May, 2009 3 commits
-
-
Simon Marlow authored
-
Simon Marlow authored
-
Ian Lynagh authored
We need to do this as it has a (, ...) type, which we aren't allowed to directly call with the FFI.
-
- 24 Apr, 2009 2 commits
-
-
Ian Lynagh authored
-
Ian Lynagh authored
-
- 23 Apr, 2009 1 commit
-
-
Simon Marlow authored
-
- 10 Apr, 2009 1 commit
-
-
Ian Lynagh authored
-
- 03 Apr, 2009 3 commits
-
-
simonpj@microsoft.com authored
-
simonpj@microsoft.com authored
Before this patch, GHC/Err.lhs-boot exported divZeroError and overflowError, as well as plain 'error'. The latter has a wired-in defn in GHC (MkId.lhs), but the former two do not. As a result GHC doesn't see that overflowError is a bottoming function at a crucial moment when compiling GHC.Real, and that means that divMod wasn't getting the CPR property. The fix is easy: - GHC/Err.lhs-boot should export only 'error' - GHC.Real, GHC.Int, and GHC.Word should import GHC.Err directly. They can do this nowadays without creating a module loop, thanks to the new exception story
-
simonpj@microsoft.com authored
There's no point in inlining unpackCString, so this patch adds a NOINLINE pragma. (Otherwise, it's just on the threshold.)
-
- 01 Apr, 2009 1 commit
-
-
Malcolm.Wallace@cs.york.ac.uk authored
-
- 30 Mar, 2009 1 commit
-
-
Ian Lynagh authored
-
- 27 Mar, 2009 1 commit
-
-
Ian Lynagh authored
-