summaryrefslogtreecommitdiff
path: root/ghc/lib/std/PrelIO.lhs
Commit message (Collapse)AuthorAgeFilesLines
* [project @ 2001-05-18 16:54:04 by simonmar]simonmar2001-05-181-684/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I/O library rewrite ------------------- This commit replaces the old C/Haskell I/O implementation with a new Haskell-only one using the new FFI & hsc2hs. main points: - lots of code deleted: we're about 3000 lines of C lighter, but the amount of Haskell code is about the same. - performance is ok: some operations are faster, others are slower. There's still some tuning to do, though. - the new library is designed to handle read/write streams much better: a read/write stream gets a special kind of handle internally called a "DuplexHandle", which actually contains two separate handles, one for writing and one for reading. The upshot is that you can do simultaneous reading and writing to/from a socket or FIFO without any locking problems. The effect is similar to calling socketToHandle twice, except that finalization works properly (creating two separate Handles could lead to the socket being closed too early when one of the Handles is GC'd). - hConnectTo and withHandleFor are gone (no one responded to my mail on GHC users, but we can always bring 'em back if necessary). - I made a half-hearted attempt at keeping the system-specific code in one place: see PrelPosix.hsc. - I've rearranged the I/O tests and added lots more. ghc/tests/lib/IO now contains Haskell 98-only IO tests, ghc/test/lib/{IOExts, Directory, Time} now contain tests for the relevant libraries. I haven't quite finished in here yet, the IO tests work but the others don't yet. - I haven't done anything about Unicode yet, but now we can start to discuss what needs doing here. The new library is using MutableByteArrays for its buffers because that turned out to be a *lot* easier (and quicker) than malloc'd buffers - I hope this won't cause trouble for unicode translations though. WARNING: Windows users refrain from updating until we've had a chance to fix any issues that arise. Testing: the basic H98 stuff has been pretty thoroughly tested, but the new duplex handle stuff is still a little green.
* [project @ 2001-01-11 17:25:56 by simonmar]simonmar2001-01-111-29/+28
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Re-organisation of ghc/lib/std and hslibs/lang ---------------------------------------------- In brief: move deprecated features out of ghc/lib/std and into hslibs/lang, move new FFI libraries into ghc/lib/std and start using them. - foreign import may now return an unboxed type (this was advertised to work before, but in fact didn't). Subsequent cleanups in PrelInt/PrelWord. - Ptr is now defined in ghc/lib/std/PrelPtr.lhs. Ptr is no longer a newtype of Addr, it is defined directly in terms of Addr#. - PrelAddr has disappeared from ghc/lib/std, all uses of Addr in ghc/lib/std have been replaced with Ptr. The definitions of Addr has been moved to hslibs/lang/Addr.lhs, as has lots of other Addr-related stuff. - ForeignObj has been removed from ghc/lib/std, and replaced with ForeignPtr. The definition of ForeignObj has been moved to hslibs/lang/ForeignObj.lhs. - Most of the new FFI has been moved into ghc/lib/std in the form of modules PrelMarshalAlloc, PrelCString, PrelCError, PrelMarshalError, PrelMarshalArray, PrelMarshalUtils, PrelCTypes, PrelCTypesISO, and PrelStorable. The corresponding modules in hslibs/lang simply re-export the contents of these modules. - PrelPosixTypes defines a few POSIX types (CMode == mode_t, etc.) - PrelCError changed to access errno using foreign label and peek (the POSIX book I have says that errno is guaranteed to be an extern int, so this should be OK until I get around to making errno thread-safe). - Hacked the macros that generate the code for CTypes and CTypesISO to generate much less code (ghc/lib/std/cbits/CTypes.h). - RtsAPI is now a bit more honest when it comes to building heap objects (it uses the correct constructors). - the Bits class and related stuff has been moved to ghc/lib/std (it was simpler this way). - Directory and System have been converted to use the new FFI.
* [project @ 2001-01-11 07:04:16 by qrczak]qrczak2001-01-111-3/+3
| | | | Change the representation of IOException: add optional filename.
* [project @ 2000-11-07 10:42:55 by simonmar]simonmar2000-11-071-6/+5
| | | | | merge before-ghci -> before-ghci-branch-merged into the ghc (non-compiler) parts of the tree.
* [project @ 2000-07-25 15:20:10 by simonmar]simonmar2000-07-251-10/+4
| | | | | | | | | | | | | | | | | Fix bug reported by Hannah Schroeter: reading a file lazily using hGetContents and then closing it using hClose can cause the program to fall over with a deadlock. The reason is that when closing the file in lazyRead{Block,Line,Char}, we set the foreign object in the handle to nullFile__, which causes the finalizer to run (at some point in the future). The finalizer takes the MVar in the handle, frees the contents, but never puts the MVar back. hClose then tries to take the MVar, and deadlocks. The solution is not to set the foreign object to nullFile__ in the first place; I'm not sure why it was done this way, and in fact it leads to a memory leak. hClose itself has a similar problem, leading to a leak of the fileObject.
* [project @ 2000-07-07 11:03:57 by simonmar]simonmar2000-07-071-9/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Rearrange exception stuff, as per my message on glasgow-haskell-users recently. The main change is the IOError type is now a synonym for Exception. IO.ioError can therefore be used for throwing exceptions. IO.catch still catches only IO exceptions, for backwards compatibility. The interface exported by Exception has changed somewhat: try :: IO a -> IO (Either Exception a) tryJust :: (Exception -> Maybe b) -> a -> IO (Either b a) catch :: IO a -> (Exception -> IO a) -> IO a catchJust :: (Exception -> Maybe b) -> IO a -> (b -> IO a) -> IO a ioErrors :: Exception -> Maybe IOError arithExceptions :: Exception -> Maybe ArithException errorCalls :: Exception -> Maybe String dynExceptions :: Exception -> Maybe Dynamic assertions :: Exception -> Maybe String asyncExceptions :: Exception -> Maybe AsyncException raiseInThread is now called throwTo. Where possible, the old functions have been left around, but marked deprecated.
* [project @ 2000-06-14 10:08:47 by simonmar]simonmar2000-06-141-5/+5
| | | | Fix mondo bogosity in hGetLine, probably caused by cut-n-pasting with eyes shut.
* [project @ 2000-06-02 11:54:53 by simonmar]simonmar2000-06-021-1/+34
| | | | | | | Fix bug in new version of hGetLine: it didn't handle unbuffered handles properly. The fix involves re-importing the old code for hGetLine :-(
* [project @ 2000-05-18 12:42:20 by simonmar]simonmar2000-05-181-28/+31
| | | | | | | New version of hGetLine that is roughly 4 times faster than the original, and is tail-recursive to boot. I'm not entirely happy with the code, but it needs to get some testing.
* [project @ 2000-04-26 10:54:25 by simonmar]simonmar2000-04-261-4/+4
| | | | tidy up conditionals a bit.
* [project @ 2000-04-25 14:19:09 by simonmar]simonmar2000-04-251-13/+28
| | | | | | | | Fixes to commitBuffer and commitAndReleaseBuffer to maintain the invariant that we never leave the handle buffer in a completely full state. This fixes the crashes seen in recent Sparc builds. Found with help from: Electric Fence &:-)
* [project @ 2000-04-14 16:17:47 by simonmar]simonmar2000-04-141-4/+11
| | | | | catch exceptions around commitBuffer and free the buffer. This closes one memory leak in the new I/O stuff, there may be another small one left.
* [project @ 2000-04-14 15:28:24 by rrt]rrt2000-04-141-1/+1
| | | | Removed -fcompiling-prelude flag (now removed from compiler)
* [project @ 2000-04-14 12:46:34 by simonmar]simonmar2000-04-141-24/+39
| | | | | | | Fix a bug in commitBuffer, and tweak the semantics of commitBuffer/commitAndReleaseBuffer. Add some comments on the algorithms used here.
* [project @ 2000-04-12 17:33:16 by simonmar]simonmar2000-04-121-161/+218
| | | | | | | | | | | | | | | | | | | | | | | | This commit fixes the trace/stderr problem, and also fixes some other problems with the I/O library. - handles now contain a list of free buffers, which are guaranteed to be the same size as the primary handle buffer. - hPutStr now doesn't evaluate any part of the input string with the handle locked. Instead, it acquires a buffer from the handle copies characters into it, then commits the buffer. This is better for concurrency too, because the handle is only locked while we're actually reading/writing, not while evaluating. - there were an even number of off-by-one errors in the I/O system which compensated for each other. This has been fixed. - made the I/O subsystem a little more exception-safe. It still isn't totally exception-safe, but I can't face doing that without a complete rewrite of this thing in Haskell. - add hPutBufFull and hGetBufFull. The compiler probably needs to be updated to use these too.
* [project @ 2000-04-10 16:02:58 by simonpj]simonpj2000-04-101-1/+1
| | | | | | | | | | Make it so that -fcompiling-prelude applies only for Prelude modules (i.e. ones called Prelxxx). I've done this with an {-# OPTIONS #-} line in each such module (they all has -fno-implicit-prelude anyway) but a less repetitive approach in the Makefile would be welcome.
* [project @ 2000-04-10 13:18:13 by simonpj]simonpj2000-04-101-0/+561
| | | | | | | | | Complete the previous commit. I think things should be OK now; but the Hugs versioning may well need adjusting. NOTE: I've added PrelIO.lhs; it contains all the GHC parts of what was IO.lhs.
* [project @ 1998-08-27 13:09:44 by sof]sof1998-08-271-78/+0
| | | | Surplus to requirements (cf. last IO commit)
* [project @ 1998-02-02 17:27:26 by simonm]simonm1998-02-021-0/+78
Library re-organisation: All libraries now live under ghc/lib, which has the following structure: ghc/lib/std -- all prelude files (libHS.a) ghc/lib/std/cbits ghc/lib/exts -- standard Hugs/GHC extensions (libHSexts.a) -- available with '-fglasgow-exts' ghc/lib/posix -- POSIX library (libHSposix.a) ghc/lib/posix/cbits -- available with '-syslib posix' ghc/lib/misc -- used to be hslibs/ghc (libHSmisc.a) ghc/lib/misc/cbits -- available with '-syslib misc' ghc/lib/concurrent -- Concurrent libraries (libHSconc.a) -- available with '-concurrent' Also, several non-standard prelude modules had their names changed to begin with 'Prel' to reduce namespace pollution. Addr ==> PrelAddr (Addr interface available in 'exts') ArrBase ==> PrelArr CCall ==> PrelCCall (CCall interface available in 'exts') ConcBase ==> PrelConc GHCerr ==> PrelErr Foreign ==> PrelForeign (Foreign interface available in 'exts') GHC ==> PrelGHC IOHandle ==> PrelHandle IOBase ==> PrelIOBase GHCmain ==> PrelMain STBase ==> PrelST Unsafe ==> PrelUnsafe UnsafeST ==> PrelUnsafeST