diff options
author | jvdelisle <jvdelisle@138bc75d-0d04-0410-961f-82ee72b054a4> | 2007-07-10 05:37:29 +0000 |
---|---|---|
committer | jvdelisle <jvdelisle@138bc75d-0d04-0410-961f-82ee72b054a4> | 2007-07-10 05:37:29 +0000 |
commit | 5d5f00d59fce8d4f8c5da07d3d54a18f7a5c0110 (patch) | |
tree | 2a610d19110bd011851316a599cf55540a6a308d /libgfortran | |
parent | 6b98ca3d0713c5497fc464082f9a5466a53d396b (diff) | |
download | gcc-5d5f00d59fce8d4f8c5da07d3d54a18f7a5c0110.tar.gz |
2007-07-09 Jerry DeLisle <jvdelisle@gcc.gnu.org>
PR libgfortran/32702
* io/unix.c (unix_stream): Restore buffer pointer and small_buffer.
(fd_alloc): If the number of bytes needed is greater than the default
BUFFER_SIZE, allocate a new buffer large enough. Free the old buffer if
necessary. (fd_sfree): Restore use of buffer pointer.
(fd_close): Likewise. (fd_open): Likewise.
(init_error_stream): Likewise.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@126510 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgfortran')
-rw-r--r-- | libgfortran/ChangeLog | 10 | ||||
-rw-r--r-- | libgfortran/io/unix.c | 37 |
2 files changed, 41 insertions, 6 deletions
diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog index 154d241f651..25b5d4ca227 100644 --- a/libgfortran/ChangeLog +++ b/libgfortran/ChangeLog @@ -1,3 +1,13 @@ +2007-07-09 Jerry DeLisle <jvdelisle@gcc.gnu.org> + + PR libgfortran/32702 + * io/unix.c (unix_stream): Restore buffer pointer and small_buffer. + (fd_alloc): If the number of bytes needed is greater than the default + BUFFER_SIZE, allocate a new buffer large enough. Free the old buffer if + necessary. (fd_sfree): Restore use of buffer pointer. + (fd_close): Likewise. (fd_open): Likewise. + (init_error_stream): Likewise. + 2007-07-09 Thomas Koenig <tkoenig@gcc.gnu.org> PR libfortran/32336 diff --git a/libgfortran/io/unix.c b/libgfortran/io/unix.c index 39ee87d076f..bdfd245a533 100644 --- a/libgfortran/io/unix.c +++ b/libgfortran/io/unix.c @@ -97,6 +97,7 @@ typedef struct gfc_offset dirty_offset; /* Start of modified bytes in buffer */ gfc_offset file_length; /* Length of the file, -1 if not seekable. */ + char *buffer; int len; /* Physical length of the current buffer */ int active; /* Length of valid bytes in the buffer */ @@ -107,7 +108,7 @@ typedef struct int unbuffered; /* =1 if the stream is not buffered */ - char buffer[BUFFER_SIZE]; + char small_buffer[BUFFER_SIZE]; } unix_stream; @@ -437,17 +438,29 @@ static void fd_alloc (unix_stream * s, gfc_offset where, int *len __attribute__ ((unused))) { - int n; + char *new_buffer; + int n, read_len; + + if (*len <= BUFFER_SIZE) + { + new_buffer = s->small_buffer; + read_len = BUFFER_SIZE; + } + else + { + new_buffer = get_mem (*len); + read_len = *len; + } /* Salvage bytes currently within the buffer. This is important for * devices that cannot seek. */ - if (s->buffer_offset <= where && + if (s->buffer != NULL && s->buffer_offset <= where && where <= s->buffer_offset + s->active) { n = s->active - (where - s->buffer_offset); - memmove (s->buffer, s->buffer + (where - s->buffer_offset), n); + memmove (new_buffer, s->buffer + (where - s->buffer_offset), n); s->active = n; } @@ -458,7 +471,13 @@ fd_alloc (unix_stream * s, gfc_offset where, s->buffer_offset = where; - s->len = BUFFER_SIZE; + /* free the old buffer if necessary */ + + if (s->buffer != NULL && s->buffer != s->small_buffer) + free_mem (s->buffer); + + s->buffer = new_buffer; + s->len = read_len; } @@ -590,7 +609,8 @@ static try fd_sfree (unix_stream * s) { if (s->ndirty != 0 && - (options.all_unbuffered || s->unbuffered)) + (s->buffer != s->small_buffer || options.all_unbuffered || + s->unbuffered)) return fd_flush (s); return SUCCESS; @@ -791,6 +811,9 @@ fd_close (unix_stream * s) if (fd_flush (s) == FAILURE) return FAILURE; + if (s->buffer != NULL && s->buffer != s->small_buffer) + free_mem (s->buffer); + if (s->fd != STDOUT_FILENO && s->fd != STDERR_FILENO) { if (close (s->fd) < 0) @@ -819,6 +842,7 @@ fd_open (unix_stream * s) s->st.write = (void *) fd_write; s->st.set = (void *) fd_sset; + s->buffer = NULL; } @@ -1377,6 +1401,7 @@ init_error_stream (unix_stream *error) error->st.sfree = (void *) fd_sfree; error->unbuffered = 1; + error->buffer = error->small_buffer; return (stream *) error; } |