diff options
author | ridiculousfish <corydoras@ridiculousfish.com> | 2012-08-04 17:44:14 -0700 |
---|---|---|
committer | ridiculousfish <corydoras@ridiculousfish.com> | 2012-08-04 17:44:14 -0700 |
commit | 682353f9cc1d2e1eb305cbb343ffec9523d846ba (patch) | |
tree | 82ef0a5abd869f2533f4f4dca43fdc64a0867a8f /parser.cpp | |
parent | 25c6671a8744a2c12c71f60ad3070ef7637781a8 (diff) |
Fix to restore an optimization from parse_util_get_line_from_offset in a more thread-safe way
Diffstat (limited to 'parser.cpp')
-rw-r--r-- | parser.cpp | 37 |
1 files changed, 18 insertions, 19 deletions
@@ -1009,25 +1009,14 @@ const wchar_t *parser_t::is_function() const int parser_t::get_lineno() const { - const wchar_t *whole_str; - const wchar_t *function_name; - int lineno; - -/* static const wchar_t *prev_str = 0; - static int i=0; - static int lineno=1; -*/ - if( !current_tokenizer ) - return -1; - - whole_str = tok_string( current_tokenizer ); - - if( !whole_str ) + + if( ! current_tokenizer || ! tok_string( current_tokenizer )) return -1; - - lineno = parse_util_lineno( whole_str, current_tokenizer_pos ); - + + lineno = current_tokenizer->line_number_of_character_at_offset(current_tokenizer_pos); + + const wchar_t *function_name; if( (function_name = is_function()) ) { lineno += function_get_definition_offset( function_name ); @@ -1036,6 +1025,16 @@ int parser_t::get_lineno() const return lineno; } +int parser_t::line_number_of_character_at_offset(size_t idx) const +{ + if( ! current_tokenizer) + return -1; + + int result = current_tokenizer->line_number_of_character_at_offset(idx); + //assert(result == parse_util_lineno(tok_string( current_tokenizer ), idx)); + return result; +} + const wchar_t *parser_t::current_filename() const { /* We query a global array for the current file name, so it only makes sense to ask this on the principal parser. */ @@ -2536,7 +2535,7 @@ int parser_t::eval( const wcstring &cmdStr, io_data_t *io, enum block_type_t blo this->push_block( block_type ); - current_tokenizer = (tokenizer *)malloc( sizeof(tokenizer)); + current_tokenizer = new tokenizer; tok_init( current_tokenizer, cmd, 0 ); error_code = 0; @@ -2588,7 +2587,7 @@ int parser_t::eval( const wcstring &cmdStr, io_data_t *io, enum block_type_t blo this->print_errors_stderr(); tok_destroy( current_tokenizer ); - free( current_tokenizer ); + delete current_tokenizer; while (forbidden_function.size() > forbid_count) parser_t::allow_function(); |