summaryrefslogtreecommitdiff
path: root/ghc/lib/std/cbits/fileGetc.c
diff options
context:
space:
mode:
authorsimonmar <unknown>2001-05-18 16:54:11 +0000
committersimonmar <unknown>2001-05-18 16:54:11 +0000
commitd9af408e5c512501cfa991f5e4a76c9154bca917 (patch)
tree627365b7dad9c2a5e1d892a1f631690b46e24a11 /ghc/lib/std/cbits/fileGetc.c
parent5f6f90850d5c82dc56d13bbc035d635e1cb2106b (diff)
downloadhaskell-d9af408e5c512501cfa991f5e4a76c9154bca917.tar.gz
[project @ 2001-05-18 16:54:04 by simonmar]
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.
Diffstat (limited to 'ghc/lib/std/cbits/fileGetc.c')
-rw-r--r--ghc/lib/std/cbits/fileGetc.c93
1 files changed, 0 insertions, 93 deletions
diff --git a/ghc/lib/std/cbits/fileGetc.c b/ghc/lib/std/cbits/fileGetc.c
deleted file mode 100644
index 810ee4c401..0000000000
--- a/ghc/lib/std/cbits/fileGetc.c
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * (c) The GRASP/AQUA Project, Glasgow University, 1994-1998
- *
- * $Id: fileGetc.c,v 1.6 2000/01/18 12:41:03 simonmar Exp $
- *
- * hGetChar Runtime Support
- */
-
-#include "Rts.h"
-#include "stgio.h"
-
-#define EOT 4
-
-/* Pre-condition: only ever called on a readable fileObject */
-StgInt
-fileGetc(StgForeignPtr ptr)
-{
- IOFileObject* fo = (IOFileObject*)ptr;
- int rc=0;
- unsigned char c;
-
-#if 0
- fprintf(stderr, "fgc: %d %d %d\n", fo->bufRPtr, fo->bufWPtr, fo->flags);
-#endif
- /*
- fileGetc does the following:
- - if the input is buffered, try fetch the char from buffer.
- - failing that,
-
- - if the input stream is 'connected' to an output stream,
- flush it before requesting any input.
- - if unbuffered, read in one character.
- - if line-buffered, read in one line, returning the first.
- - if block-buffered, fill up block, returning the first.
- */
-
- if ( FILEOBJ_WRITEABLE(fo) && FILEOBJ_JUST_WRITTEN(fo) && FILEOBJ_NEEDS_FLUSHING(fo) ) {
- rc = flushBuffer(ptr);
- if (rc < 0) return rc;
- }
-
- fo->flags = (fo->flags & ~FILEOBJ_RW_WRITE) | FILEOBJ_RW_READ;
-
- if ( FILEOBJ_IS_EOF(fo) ) {
- ghc_errtype = ERR_EOF;
- ghc_errstr = "";
- return -1;
- }
-
- if ( FILEOBJ_BUFFER_EMPTY(fo) ) {
- ;
- } else if ( FILEOBJ_UNBUFFERED(fo) && !FILEOBJ_HAS_PUSHBACKS(fo) ) {
- ;
- } else if ( FILEOBJ_UNBUFFERED(fo) ) { /* Unbuffered stream has pushbacks, retrieve them */
- c=((unsigned char*)(fo->buf))[fo->bufRPtr++];
- return (int)c;
- } else {
- c=((unsigned char*)(fo->buf))[fo->bufRPtr];
- fo->bufRPtr++;
- return (int)c;
- }
-
- /* Nothing in the buffer, go out and fetch a byte for our customer,
- filling up the buffer if needs be.
- */
- if ( FILEOBJ_UNBUFFERED(fo) ) {
- return (readChar(ptr));
- } else if ( FILEOBJ_LINEBUFFERED(fo) ) {
-
- /* if input stream is connect to an output stream, flush it first */
- if ( fo->connectedTo != NULL &&
- fo->connectedTo->fd != -1 &&
- (fo->connectedTo->flags & FILEOBJ_WRITE) ) {
- rc = flushFile((StgForeignPtr)fo->connectedTo);
- }
- if (rc < 0) return rc;
-
- rc = fill_up_line_buffer(fo);
- if (rc < 0) return rc;
-
- c=((unsigned char*)(fo->buf))[fo->bufRPtr];
- fo->bufRPtr++;
- return (int)c;
-
- } else { /* Fully-buffered */
- rc = readBlock(ptr);
- if (rc < 0) return rc;
-
- c=((unsigned char*)(fo->buf))[fo->bufRPtr];
- fo->bufRPtr++;
- return (int)c;
- }
-}