From 06fd1aa9f8aa2d9705ba942055c76518fb1da1f6 Mon Sep 17 00:00:00 2001 From: axel Date: Fri, 3 Feb 2006 01:23:56 +1000 Subject: [PATCH] Make stack traces print absolute filenames darcs-hash:20060202152356-ac50b-9e6ab31c03d5f49824ccca7eee3b8e62d66b0009.gz --- builtin.c | 20 +++++++++++++---- configure.ac | 20 ++++++++++++++++- main.c | 12 +++++++--- parser.c | 11 ++------- parser.h | 4 ++-- reader.c | 3 +-- reader.h | 2 +- wutil.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++ wutil.h | 8 +++++++ 9 files changed, 121 insertions(+), 22 deletions(-) diff --git a/builtin.c b/builtin.c index 6496719dc..8a48603ef 100644 --- a/builtin.c +++ b/builtin.c @@ -2001,7 +2001,6 @@ static int builtin_source( wchar_t ** argv ) argc = builtin_count_args( argv ); - if( argc != 2 ) { sb_printf( sb_err, _( L"%ls: Expected exactly one argument, got %d\n" ), argv[0], argc ); @@ -2029,10 +2028,23 @@ static int builtin_source( wchar_t ** argv ) } else { - parser_push_block( SOURCE ); - reader_push_current_filename( argv[1] ); + wchar_t *fn = wrealpath( argv[1], 0 ); + const wchar_t *fn_intern; - current_block->param1.source_dest = wcsdup( argv[1] ); + if( !fn ) + { + fn_intern = intern( argv[1] ); + } + else + { + fn_intern = intern(fn); + free( fn ); + } + + parser_push_block( SOURCE ); + reader_push_current_filename( fn_intern ); + + current_block->param1.source_dest = fn_intern; res = reader_read( fd ); parser_pop_block(); diff --git a/configure.ac b/configure.ac index 32eba6af4..d104c7dae 100644 --- a/configure.ac +++ b/configure.ac @@ -18,8 +18,9 @@ for i in /usr/pkg /sw; do else AC_MSG_RESULT(no) fi + done - + # If needed, run autoheader automatically AC_MSG_CHECKING([if autoheader needs to be run]) if test ! -f ./config.h.in -o config.h.in -ot configure.ac; then @@ -163,6 +164,23 @@ else AC_MSG_RESULT(no) fi +# Check if realpath accepts null for its second argument +AC_MSG_CHECKING([if realpath accepts null for its second argument]) +AC_RUN_IFELSE( + [AC_LANG_PROGRAM([#include +#include ], + [int status; char *res; res = realpath( "foo", 0 ); status = (res && (strlen(res)>3))?0:1; free(res); exit( status );])], + [have_realpath_null=yes], + [have_realpath_null=no] ) + +if test "$have_realpath_null" = yes; then + AC_MSG_RESULT(yes) + AC_DEFINE([HAVE_REALPATH_NULL], [1], + [Define to 1 if realpath accepts null for its second argument.]) +else + AC_MSG_RESULT(no) +fi + # Check for libraries AC_CHECK_LIB(socket, connect) diff --git a/main.c b/main.c index 2594dda1d..2dbb97266 100644 --- a/main.c +++ b/main.c @@ -244,7 +244,8 @@ int main( int argc, char **argv ) int i; string_buffer_t sb; int fd; - + wchar_t *rel_filename, *abs_filename; + if( ( fd = open(file, O_RDONLY) ) == -1 ) { wperror( L"open" ); @@ -267,8 +268,13 @@ int main( int argc, char **argv ) env_set( L"argv", (wchar_t *)sb.buff, 0 ); sb_destroy( &sb ); } + + rel_filename = str2wcs( file ); + abs_filename = wrealpath( rel_filename, 0 ); + reader_push_current_filename( intern( abs_filename ) ); + free( rel_filename ); + free( abs_filename ); - reader_push_current_filename( str2wcs( file ) ); res = reader_read( fd ); if( res ) @@ -277,7 +283,7 @@ int main( int argc, char **argv ) _(L"Error while reading file %ls\n"), reader_current_filename()?reader_current_filename(): _(L"Standard input") ); } - free(reader_pop_current_filename()); + reader_pop_current_filename(); } } } diff --git a/parser.c b/parser.c index 04d0a4ff3..d26b3769c 100644 --- a/parser.c +++ b/parser.c @@ -36,6 +36,7 @@ The fish parser. Contains functions for parsing code. #include "env_universal.h" #include "event.h" #include "translate.h" +#include "intern.h" /** Maximum number of block levels in code. This is not the same as @@ -339,7 +340,7 @@ void parser_push_block( int type ) block_t *new = calloc( 1, sizeof( block_t )); new->src_lineno = parser_get_lineno(); - new->src_filename = parser_current_filename()?wcsdup(parser_current_filename()):0; + new->src_filename = parser_current_filename()?intern(parser_current_filename()):0; debug( 3, L"Block push %ls %d\n", parser_get_block_desc(type), block_count( current_block)+1 ); @@ -418,12 +419,6 @@ void parser_pop_block() break; } - case SOURCE: - { - free( current_block->param1.source_dest ); - break; - } - } for( eb=current_block->first_event_block; eb; eb=eb_next ) @@ -432,8 +427,6 @@ void parser_pop_block() free(eb); } - free( current_block->src_filename ); - block_t *old = current_block; current_block = current_block->outer; free( old ); diff --git a/parser.h b/parser.h index 4ad0162f0..51c5b7150 100644 --- a/parser.h +++ b/parser.h @@ -65,7 +65,7 @@ typedef struct block int if_state; /**< The state of the if block */ wchar_t *switch_value; /**< The value to test in a switch block */ wchar_t *function_name; /**< The name of the function to define or the function called*/ - wchar_t *source_dest; /**< The name of the file to source*/ + const wchar_t *source_dest; /**< The name of the file to source*/ event_t *event; /**