aboutsummaryrefslogtreecommitdiff
path: root/libgfortran/io/unix.c
diff options
context:
space:
mode:
authorJanne Blomqvist <jb@gcc.gnu.org>2012-03-16 10:30:26 +0200
committerJanne Blomqvist <jb@gcc.gnu.org>2012-03-16 10:30:26 +0200
commit33959d1d3c8f791c6b293367fdfb8acacab17534 (patch)
treea57a717a913b31ddd91e573fff313fe1d159570e /libgfortran/io/unix.c
parentc4256b35bfb6a4395951053536300ca1725b0521 (diff)
downloadgcc-33959d1d3c8f791c6b293367fdfb8acacab17534.zip
gcc-33959d1d3c8f791c6b293367fdfb8acacab17534.tar.gz
gcc-33959d1d3c8f791c6b293367fdfb8acacab17534.tar.bz2
Share vtables instead of replicating them for each unit.
2012-03-16 Janne Blomqvist <jb@gcc.gnu.org> * io/unix.h (struct stream): Rename to stream_vtable. (struct stream): New struct definition. (sread): Dereference vtable pointer. (swrite): Likewise. (sseek): Likewise. (struncate): Likewise. (sflush): Likewise. (sclose): Likewise. * io/unix.c (raw_vtable): New variable. (buf_vtable): Likewise. (mem_vtable): Likewise. (mem4_vtable): Likewise. (raw_init): Assign vtable pointer. (buf_init): Likewise. (open_internal): Likewise. (open_internal4): Likewise. From-SVN: r185454
Diffstat (limited to 'libgfortran/io/unix.c')
-rw-r--r--libgfortran/io/unix.c87
1 files changed, 51 insertions, 36 deletions
diff --git a/libgfortran/io/unix.c b/libgfortran/io/unix.c
index 6eef3f9..978c3ff 100644
--- a/libgfortran/io/unix.c
+++ b/libgfortran/io/unix.c
@@ -401,17 +401,21 @@ raw_close (unix_stream * s)
return retval;
}
+static const struct stream_vtable raw_vtable = {
+ .read = (void *) raw_read,
+ .write = (void *) raw_write,
+ .seek = (void *) raw_seek,
+ .tell = (void *) raw_tell,
+ .size = (void *) raw_size,
+ .trunc = (void *) raw_truncate,
+ .close = (void *) raw_close,
+ .flush = (void *) raw_flush
+};
+
static int
raw_init (unix_stream * s)
{
- s->st.read = (void *) raw_read;
- s->st.write = (void *) raw_write;
- s->st.seek = (void *) raw_seek;
- s->st.tell = (void *) raw_tell;
- s->st.size = (void *) raw_size;
- s->st.trunc = (void *) raw_truncate;
- s->st.close = (void *) raw_close;
- s->st.flush = (void *) raw_flush;
+ s->st.vptr = &raw_vtable;
s->buffer = NULL;
return 0;
@@ -619,17 +623,21 @@ buf_close (unix_stream * s)
return raw_close (s);
}
+static const struct stream_vtable buf_vtable = {
+ .read = (void *) buf_read,
+ .write = (void *) buf_write,
+ .seek = (void *) buf_seek,
+ .tell = (void *) buf_tell,
+ .size = (void *) buf_size,
+ .trunc = (void *) buf_truncate,
+ .close = (void *) buf_close,
+ .flush = (void *) buf_flush
+};
+
static int
buf_init (unix_stream * s)
{
- s->st.read = (void *) buf_read;
- s->st.write = (void *) buf_write;
- s->st.seek = (void *) buf_seek;
- s->st.tell = (void *) buf_tell;
- s->st.size = (void *) buf_size;
- s->st.trunc = (void *) buf_truncate;
- s->st.close = (void *) buf_close;
- s->st.flush = (void *) buf_flush;
+ s->st.vptr = &buf_vtable;
s->buffer = get_mem (BUFFER_SIZE);
return 0;
@@ -872,6 +880,31 @@ mem_close (unix_stream * s)
return 0;
}
+static const struct stream_vtable mem_vtable = {
+ .read = (void *) mem_read,
+ .write = (void *) mem_write,
+ .seek = (void *) mem_seek,
+ .tell = (void *) mem_tell,
+ /* buf_size is not a typo, we just reuse an identical
+ implementation. */
+ .size = (void *) buf_size,
+ .trunc = (void *) mem_truncate,
+ .close = (void *) mem_close,
+ .flush = (void *) mem_flush
+};
+
+static const struct stream_vtable mem4_vtable = {
+ .read = (void *) mem_read4,
+ .write = (void *) mem_write4,
+ .seek = (void *) mem_seek,
+ .tell = (void *) mem_tell,
+ /* buf_size is not a typo, we just reuse an identical
+ implementation. */
+ .size = (void *) buf_size,
+ .trunc = (void *) mem_truncate,
+ .close = (void *) mem_close,
+ .flush = (void *) mem_flush
+};
/*********************************************************************
Public functions -- A reimplementation of this module needs to
@@ -895,16 +928,7 @@ open_internal (char *base, int length, gfc_offset offset)
s->logical_offset = 0;
s->active = s->file_length = length;
- s->st.close = (void *) mem_close;
- s->st.seek = (void *) mem_seek;
- s->st.tell = (void *) mem_tell;
- /* buf_size is not a typo, we just reuse an identical
- implementation. */
- s->st.size = (void *) buf_size;
- s->st.trunc = (void *) mem_truncate;
- s->st.read = (void *) mem_read;
- s->st.write = (void *) mem_write;
- s->st.flush = (void *) mem_flush;
+ s->st.vptr = &mem_vtable;
return (stream *) s;
}
@@ -926,16 +950,7 @@ open_internal4 (char *base, int length, gfc_offset offset)
s->logical_offset = 0;
s->active = s->file_length = length;
- s->st.close = (void *) mem_close;
- s->st.seek = (void *) mem_seek;
- s->st.tell = (void *) mem_tell;
- /* buf_size is not a typo, we just reuse an identical
- implementation. */
- s->st.size = (void *) buf_size;
- s->st.trunc = (void *) mem_truncate;
- s->st.read = (void *) mem_read4;
- s->st.write = (void *) mem_write4;
- s->st.flush = (void *) mem_flush;
+ s->st.vptr = &mem4_vtable;
return (stream *) s;
}