diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/bytecode.c | 6 | ||||
-rw-r--r-- | src/compiler.cc | 6 | ||||
-rw-r--r-- | src/ctinput.cc | 4 | ||||
-rw-r--r-- | src/input.c | 31 | ||||
-rw-r--r-- | src/input.h | 11 |
5 files changed, 30 insertions, 28 deletions
diff --git a/src/bytecode.c b/src/bytecode.c index b0f0b249..fbc0c99d 100644 --- a/src/bytecode.c +++ b/src/bytecode.c @@ -121,7 +121,7 @@ static void rcode_downref( program_t *prg, tree_t **sp, code_t *instr ); static void open_stdout( program_t *prg ) { if ( prg->stdout_val == 0 ) - prg->stdout_val = colm_stream_open_fd( prg, "<stdout>", 1 ); + prg->stdout_val = colm_stream_open_fd( prg, strdup("<stdout>"), 1 ); } static void flush_streams( program_t *prg ) @@ -3625,7 +3625,7 @@ again: /* Pop the root object. */ vm_pop_tree(); if ( prg->stdin_val == 0 ) - prg->stdin_val = colm_stream_open_fd( prg, "<stdin>", 0 ); + prg->stdin_val = colm_stream_open_fd( prg, strdup("<stdin>"), 0 ); vm_push_stream( prg->stdin_val ); break; @@ -3646,7 +3646,7 @@ again: /* Pop the root object. */ vm_pop_tree(); if ( prg->stderr_val == 0 ) - prg->stderr_val = colm_stream_open_fd( prg, "<stderr>", 2 ); + prg->stderr_val = colm_stream_open_fd( prg, strdup("<stderr>"), 2 ); vm_push_stream( prg->stderr_val ); break; diff --git a/src/compiler.cc b/src/compiler.cc index 5a33ed31..3020d7f5 100644 --- a/src/compiler.cc +++ b/src/compiler.cc @@ -990,7 +990,7 @@ void Compiler::initEmptyScanners() pda_run *Compiler::parsePattern( program_t *prg, tree_t **sp, const InputLoc &loc, int parserId, struct stream_impl *sourceStream ) { - struct stream_impl *in = colm_impl_new_generic( "<internal>" ); + struct stream_impl *in = colm_impl_new_generic( strdup("<internal>") ); struct pda_run *pdaRun = new pda_run; colm_pda_init( prg, pdaRun, pdaTables, parserId, 0, false, 0, false ); @@ -1035,13 +1035,13 @@ void Compiler::parsePatterns() for ( ConsList::Iter cons = replList; cons.lte(); cons++ ) { if ( cons->langEl != 0 ) { - struct stream_impl *in = colm_impl_new_cons( "<internal>", cons ); + struct stream_impl *in = colm_impl_new_cons( strdup("<internal>"), cons ); cons->pdaRun = parsePattern( prg, sp, cons->loc, cons->langEl->parserId, in ); } } for ( PatList::Iter pat = patternList; pat.lte(); pat++ ) { - struct stream_impl *in = colm_impl_new_pat( "<internal>", pat ); + struct stream_impl *in = colm_impl_new_pat( strdup("<internal>"), pat ); pat->pdaRun = parsePattern( prg, sp, pat->loc, pat->langEl->parserId, in ); } diff --git a/src/ctinput.cc b/src/ctinput.cc index 9c4f49c7..fbc67157 100644 --- a/src/ctinput.cc +++ b/src/ctinput.cc @@ -38,7 +38,7 @@ extern stream_funcs replFuncs; * Pattern */ -struct stream_impl *colm_impl_new_pat( const char *name, Pattern *pattern ) +struct stream_impl *colm_impl_new_pat( char *name, Pattern *pattern ) { struct stream_impl *ss = (struct stream_impl*)malloc(sizeof(struct stream_impl)); memset( ss, 0, sizeof(struct stream_impl) ); @@ -239,7 +239,7 @@ stream_funcs patternFuncs = * Constructor */ -struct stream_impl *colm_impl_new_cons( const char *name, Constructor *constructor ) +struct stream_impl *colm_impl_new_cons( char *name, Constructor *constructor ) { struct stream_impl *ss = (struct stream_impl*)malloc(sizeof(struct stream_impl)); memset( ss, 0, sizeof(struct stream_impl) ); diff --git a/src/input.c b/src/input.c index af98e684..1ca7d63a 100644 --- a/src/input.c +++ b/src/input.c @@ -113,10 +113,15 @@ void colm_stream_destroy( program_t *prg, tree_t **sp, struct_t *s ) if ( stream->impl->file != 0 ) fclose( stream->impl->file ); + /* FIXME: Need to leak this for now. Until we can return strings to a + * program loader and free them at a later date (after the colm program is + * deleted). */ + // if ( stream->impl->name != 0 ) + // free( stream->impl->name ); + free( stream->impl ); } - /* Keep the position up to date after consuming text. */ void update_position( struct stream_impl *is, const char *data, long length ) { @@ -367,7 +372,7 @@ void init_file_funcs() * StreamImpl struct, this wraps the list of input streams. */ -void init_stream_impl( struct stream_impl *is, const char *name ) +void init_stream_impl( struct stream_impl *is, char *name ) { memset( is, 0, sizeof(struct stream_impl) ); @@ -785,12 +790,16 @@ static void stream_prepend_data( struct stream_impl *is, const char *data, long if ( is_source_stream( is ) ) { // message( "sourcing line info\n" ); - /* steal the location information. */ + /* Steal the location information. */ stream_t *s = ((stream_t*)is->queue->tree); is->line = s->impl->line; is->column = s->impl->column; is->byte = s->impl->byte; - is->name = s->impl->name; + + /* Dup the name otherwise we will break stream destructor. */ + if ( is->name ) + free(is->name); + is->name = strdup(s->impl->name); } /* Create a new buffer for the data. This is the easy implementation. @@ -1027,34 +1036,29 @@ struct stream_funcs file_funcs = }; -struct stream_impl *colm_impl_new_file( const char *name, FILE *file ) +static struct stream_impl *colm_impl_new_file( char *name, FILE *file ) { struct stream_impl *ss = (struct stream_impl*)malloc(sizeof(struct stream_impl)); init_stream_impl( ss, name ); ss->funcs = &file_funcs; - ss->file = file; - return ss; } -struct stream_impl *colm_impl_new_fd( const char *name, long fd ) +static struct stream_impl *colm_impl_new_fd( char *name, long fd ) { struct stream_impl *ss = (struct stream_impl*)malloc(sizeof(struct stream_impl)); init_stream_impl( ss, name ); ss->funcs = &file_funcs; - ss->file = fdopen( fd, ( fd == 0 ) ? "r" : "w" ); - return ss; } -struct stream_impl *colm_impl_new_generic( const char *name ) +struct stream_impl *colm_impl_new_generic( char *name ) { struct stream_impl *ss = (struct stream_impl*)malloc(sizeof(struct stream_impl)); init_stream_impl( ss, name ); ss->funcs = &stream_funcs; - return ss; } @@ -1105,14 +1109,13 @@ stream_t *colm_stream_open_file( program_t *prg, tree_t *name, tree_t *mode ) stream = colm_stream_new_struct( prg ); stream->impl = colm_impl_new_file( file_name, file ); } - free( file_name ); return stream; } stream_t *colm_stream_new( program_t *prg ) { - struct stream_impl *impl = colm_impl_new_generic( "<internal>" ); + struct stream_impl *impl = colm_impl_new_generic( strdup("<internal>") ); struct colm_stream *stream = colm_stream_new_struct( prg ); stream->impl = impl; diff --git a/src/input.h b/src/input.h index be685662..1faf1ea6 100644 --- a/src/input.h +++ b/src/input.h @@ -137,7 +137,7 @@ struct stream_impl long column; long byte; - const char *name; + char *name; FILE *file; struct Pattern *pattern; @@ -152,11 +152,10 @@ struct stream_impl int indent; }; -struct stream_impl *colm_impl_new_pat( const char *name, struct Pattern *pattern ); -struct stream_impl *colm_impl_new_cons( const char *name, struct Constructor *constructor ); -struct stream_impl *colm_impl_new_file( const char *name, FILE *file ); -struct stream_impl *colm_impl_new_fd( const char *name, long fd ); -struct stream_impl *colm_impl_new_generic( const char *name ); +struct stream_impl *colm_impl_new_pat( char *name, struct Pattern *pattern ); +struct stream_impl *colm_impl_new_cons( char *name, struct Constructor *constructor ); +struct stream_impl *colm_impl_new_generic( char *name ); + void update_position( struct stream_impl *input_stream, const char *data, long length ); void undo_position( struct stream_impl *input_stream, const char *data, long length ); |