diff options
author | Adrian Thurston <thurston@complang.org> | 2015-01-27 10:04:35 -0500 |
---|---|---|
committer | Adrian Thurston <thurston@complang.org> | 2015-01-27 10:04:35 -0500 |
commit | 09c75e4b10915cb32786d2482af6727841659b80 (patch) | |
tree | 72484da41111b29b1895261b61727d44f85b73b2 | |
parent | 680cdd650f327b28129f23bf027ca5fa79b44ae3 (diff) | |
download | colm-09c75e4b10915cb32786d2482af6727841659b80.tar.gz |
added a destructor for stream
-rw-r--r-- | src/input.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/input.c b/src/input.c index 56c3c7df..a8b50446 100644 --- a/src/input.c +++ b/src/input.c @@ -78,6 +78,20 @@ void clearSourceStream( struct colm_program *prg, sourceStream->queue = 0; } +void colm_stream_destroy( Program *prg, Tree **sp, Struct *s ) +{ + Stream *stream = (Stream*) s; + clearSourceStream( prg, sp, stream->impl ); + + if ( stream->impl->file != 0 ) + fclose( stream->impl->file ); + else if ( stream->impl->fd >= 0 ) + close( stream->impl->fd ); + + free( stream->impl ); +} + + /* Keep the position up to date after consuming text. */ void updatePosition( StreamImpl *is, const char *data, long length ) { @@ -1033,6 +1047,7 @@ Stream *colm_stream_new_struct( Program *prg ) memset( stream, 0, memsize ); colm_struct_add( prg, (struct colm_struct *)stream ); stream->id = STRUCT_INBUILT_ID; + stream->destructor = &colm_stream_destroy; return stream; } |