Switch from die_mem function to DIE_MEM macro in order to be able to give a line and file for the OOM message

darcs-hash:20060703103957-ac50b-8d7a860d931fd087f6d1759bc1e934dba1cfefe2.gz
This commit is contained in:
axel 2006-07-03 20:39:57 +10:00
parent 38175cdd30
commit d56ab1d365
24 changed files with 77 additions and 84 deletions

View file

@ -481,7 +481,7 @@ static int builtin_block( wchar_t **argv )
event_block_t *eb = malloc( sizeof( event_block_t ) );
if( !eb )
die_mem();
DIE_MEM();
eb->type = type;
@ -1112,7 +1112,7 @@ static int builtin_function( wchar_t **argv )
e = halloc( current_block, sizeof(event_t));
if( !e )
die_mem();
DIE_MEM();
e->type = EVENT_SIGNAL;
e->param1.signal = sig;
e->function_name=0;
@ -1136,7 +1136,7 @@ static int builtin_function( wchar_t **argv )
e = halloc( current_block, sizeof(event_t));
if( !e )
die_mem();
DIE_MEM();
e->type = EVENT_VARIABLE;
e->param1.variable = halloc_wcsdup( current_block, woptarg );
e->function_name=0;
@ -1153,7 +1153,7 @@ static int builtin_function( wchar_t **argv )
e = halloc( current_block, sizeof(event_t));
if( !e )
die_mem();
DIE_MEM();
if( ( opt == 'j' ) &&
( wcscasecmp( woptarg, L"caller" ) == 0 ) )

View file

@ -631,7 +631,7 @@ static int builtin_set( wchar_t **argv )
if( !(dest = wcsdup(argv[woptind])))
{
die_mem();
DIE_MEM();
}
if( wcschr( dest, L'[' ) )

View file

@ -98,7 +98,7 @@ wchar_t **list_to_char_arr( array_list_t *l )
int i;
if( res == 0 )
{
die_mem();
DIE_MEM();
}
for( i=0; i<al_get_count( l ); i++ )
{
@ -124,7 +124,7 @@ int fgetws2( wchar_t **b, int *len, FILE *f )
buff = realloc( buff, sizeof(wchar_t)*new_len );
if( buff == 0 )
{
die_mem();
DIE_MEM();
}
else
{
@ -196,7 +196,7 @@ wchar_t *str2wcs( const char *in )
if( !out )
{
die_mem();
DIE_MEM();
}
return str2wcs_internal( in, out );
@ -258,7 +258,7 @@ char *wcs2str( const wchar_t *in )
if( !out )
{
die_mem();
DIE_MEM();
}
return wcs2str_internal( in, out );
@ -314,7 +314,7 @@ char **wcsv2strv( const wchar_t **in )
char **res = malloc( sizeof( char *)*(count+1));
if( res == 0 )
{
die_mem();
DIE_MEM();
}
for( i=0; i<count; i++ )
@ -349,7 +349,7 @@ wchar_t *wcsdupcat2( const wchar_t *a, ... )
wchar_t *res = malloc( sizeof(wchar_t)*(len +1 ));
if( res == 0 )
{
die_mem();
DIE_MEM();
}
wcscpy( res, a );
@ -375,7 +375,7 @@ wchar_t **strv2wcsv( const char **in )
wchar_t **res = malloc( sizeof( wchar_t *)*(count+1));
if( res == 0 )
{
die_mem();
DIE_MEM();
}
for( i=0; i<count; i++ )
@ -518,18 +518,6 @@ int read_blocked(int fd, void *buf, size_t count)
return res;
}
void die_mem()
{
/*
Do not translate this message, and do not send it through the
usual channels. This increases the odds that the message gets
through correctly, even if we are out of memory.
*/
fwprintf( stderr, L"Out of memory, shutting down fish.\n" );
exit(1);
}
void debug( int level, const wchar_t *msg, ... )
{
va_list va;
@ -665,7 +653,7 @@ wchar_t *escape( const wchar_t *in,
pos = out;
if( !out )
die_mem();
DIE_MEM();
while( *in != 0 )
{
@ -788,7 +776,7 @@ wchar_t *unescape( const wchar_t * orig, int unescape_special )
in = wcsdup( orig );
if( !in )
die_mem();
DIE_MEM();
for( in_pos=0, out_pos=0;
in_pos<len;
@ -1440,7 +1428,7 @@ void tokenize_variable_array( const wchar_t *val, array_list_t *out )
if( !cpy )
{
die_mem();
DIE_MEM();
}
for( start=pos=cpy; *pos; pos++ )

View file

@ -87,6 +87,15 @@ extern wchar_t *program_name;
} \
/**
Exit program at once, leaving an error message about running out of memory
*/
#define DIE_MEM() \
{ \
fwprintf( stderr, L"fish: Out of memory on line %d of file %s, shutting down fish\n", __LINE__, __FILE__ ); \
exit(1); \
} \
/**
Take an array_list_t containing wide strings and converts them to a
single null-terminated wchar_t **. The array is allocated using
@ -245,10 +254,6 @@ int contains_str( const wchar_t *needle, ... );
*/
int read_blocked(int fd, void *buf, size_t count);
/**
Exit program at once, leaving an error message about running out of memory
*/
void die_mem();
/**
Issue a debug message with printf-style string formating and

View file

@ -268,7 +268,7 @@ static int condition_test( const wchar_t *condition )
condition_cache = malloc( sizeof( hash_table_t ) );
if( !condition_cache )
{
die_mem();
DIE_MEM();
}
@ -397,7 +397,7 @@ void complete_add( const wchar_t *cmd,
{
if( !(c = malloc( sizeof(complete_entry) )))
{
die_mem();
DIE_MEM();
}
c->next = first_entry;
@ -412,7 +412,7 @@ void complete_add( const wchar_t *cmd,
if( !(opt = malloc( sizeof( complete_entry_opt ) )))
{
die_mem();
DIE_MEM();
}
opt->next = c->first_option;
@ -649,7 +649,7 @@ int complete_is_valid_option( const wchar_t *str,
if( !(short_validated = halloc( context, wcslen( opt ) )))
{
die_mem();
DIE_MEM();
}
@ -860,7 +860,7 @@ static const wchar_t *complete_get_desc_suffix( const wchar_t *suff_orig )
{
suffix_hash = malloc( sizeof( hash_table_t) );
if( !suffix_hash )
die_mem();
DIE_MEM();
hash_init( suffix_hash, &hash_wcs_func, &hash_wcs_cmp );
}
@ -1687,7 +1687,7 @@ static int complete_param( wchar_t *cmd_orig,
wchar_t *next_opt =
malloc( sizeof(wchar_t)*(3 + wcslen(desc)));
if( !next_opt )
die_mem();
DIE_MEM();
next_opt[0]=o->short_opt;
next_opt[1]=COMPLETE_SEP;

2
env.c
View file

@ -1306,7 +1306,7 @@ static void export_func2( void *k, void *v, void *aux )
if( !ks || !vs )
{
die_mem();
DIE_MEM();
}
/*

View file

@ -261,7 +261,7 @@ static void parse_message( wchar_t *msg,
var_uni_entry_t *entry =
malloc( sizeof(var_uni_entry_t) + sizeof(wchar_t)*(wcslen(val)+1) );
if( !entry )
die_mem();
DIE_MEM();
entry->export=export;
wcscpy( entry->val, val );
@ -433,7 +433,7 @@ message_t *create_message( int type,
msg = malloc( sizeof( message_t ) + sz );
if( !msg )
die_mem();
DIE_MEM();
strcpy( msg->body, (type==SET?SET_MBS:SET_EXPORT_MBS) );
strcat( msg->body, " " );
@ -453,7 +453,7 @@ message_t *create_message( int type,
msg = malloc( sizeof( message_t ) + sz );
if( !msg )
die_mem();
DIE_MEM();
strcpy( msg->body, ERASE_MBS " " );
strcat( msg->body, key );
@ -466,7 +466,7 @@ message_t *create_message( int type,
msg = malloc( sizeof( message_t ) +
strlen( BARRIER_MBS ) +2);
if( !msg )
die_mem();
DIE_MEM();
strcpy( msg->body, BARRIER_MBS "\n" );
break;
}
@ -476,7 +476,7 @@ message_t *create_message( int type,
msg = malloc( sizeof( message_t ) +
strlen( BARRIER_REPLY_MBS ) +2);
if( !msg )
die_mem();
DIE_MEM();
strcpy( msg->body, BARRIER_REPLY_MBS "\n" );
break;
}

View file

@ -140,7 +140,7 @@ static event_t *event_copy( event_t *event, int copy_arguments )
{
event_t *e = malloc( sizeof( event_t ) );
if( !e )
die_mem();
DIE_MEM();
memcpy( e, event, sizeof(event_t));
if( e->function_name )

2
exec.c
View file

@ -495,7 +495,7 @@ static io_data_t *io_transmogrify( io_data_t * in )
out = malloc( sizeof( io_data_t ) );
if( !out )
die_mem();
DIE_MEM();
out->fd = in->fd;
out->io_mode = IO_FD;

View file

@ -684,7 +684,7 @@ static int expand_variables( wchar_t *in, array_list_t *out, int last_idx )
{
var_tmp = sb_halloc( global_context );
if( !var_tmp )
die_mem();
DIE_MEM();
}
else
{
@ -695,7 +695,7 @@ static int expand_variables( wchar_t *in, array_list_t *out, int last_idx )
{
var_idx_list = al_halloc( global_context );
if( !var_idx_list )
die_mem();
DIE_MEM();
}
else
{
@ -907,7 +907,7 @@ static int expand_variables( wchar_t *in, array_list_t *out, int last_idx )
if( !(new_in = malloc( sizeof(wchar_t)*new_len )))
{
die_mem();
DIE_MEM();
}
else
{

View file

@ -129,7 +129,7 @@ static void autoload_names( array_list_t *out, int get_hidden )
*suffix = 0;
dup = intern( fn );
if( !dup )
die_mem();
DIE_MEM();
al_push( out, dup );
}
}

View file

@ -35,7 +35,7 @@ array_list_t *al_halloc( void *context )
{
array_list_t *res = halloc( context, sizeof( array_list_t ) );
if( !res )
die_mem();
DIE_MEM();
al_init( res );
halloc_register_function( context, (void (*)(void *)) &al_destroy, res );
return res;
@ -45,7 +45,7 @@ string_buffer_t *sb_halloc( void *context )
{
string_buffer_t *res = halloc( context, sizeof( string_buffer_t ) );
if( !res )
die_mem();
DIE_MEM();
sb_init( res );
halloc_register_function( context, (void (*)(void *)) &sb_destroy, res );
return res;
@ -81,7 +81,7 @@ wchar_t *halloc_wcsdup( void *context, const wchar_t *in )
if( out == 0 )
{
die_mem();
DIE_MEM();
}
memcpy( out, in, sizeof( wchar_t)*(len+1));
return out;
@ -92,7 +92,7 @@ wchar_t *halloc_wcsndup( void * context, const wchar_t *in, int c )
wchar_t *res = halloc( context, sizeof(wchar_t)*(c+1) );
if( res == 0 )
{
die_mem();
DIE_MEM();
}
wcslcpy( res, in, c+1 );
res[c] = L'\0';

View file

@ -160,7 +160,7 @@ static int history_load()
history_current = malloc( sizeof( ll_node_t ) );
if( !history_current )
{
die_mem();
DIE_MEM();
}

View file

@ -40,7 +40,7 @@ const wchar_t *intern( const wchar_t *in )
intern_table = malloc( sizeof( hash_table_t ) );
if( !intern_table )
{
die_mem();
DIE_MEM();
}
hash_init( intern_table, &hash_wcs_func, &hash_wcs_cmp );
}
@ -59,7 +59,7 @@ const wchar_t *intern( const wchar_t *in )
res = wcsdup( in );
if( !res )
{
die_mem();
DIE_MEM();
}
hash_put( intern_table, res, res );
@ -81,7 +81,7 @@ const wchar_t *intern_static( const wchar_t *in )
intern_static_table = malloc( sizeof( hash_table_t ) );
if( !intern_static_table )
{
die_mem();
DIE_MEM();
}
hash_init( intern_static_table, &hash_wcs_func, &hash_wcs_cmp );
}

2
io.c
View file

@ -189,7 +189,7 @@ io_data_t *io_duplicate( void *context, io_data_t *l )
if( !res )
{
die_mem();
DIE_MEM();
}

View file

@ -440,7 +440,7 @@ void writestr( const wchar_t *str )
writestr_buff = realloc( writestr_buff, len );
if( !writestr_buff )
{
die_mem();
DIE_MEM();
}
writestr_buff_sz = len;
}

View file

@ -274,7 +274,7 @@ static void job_or_process_extent( const wchar_t *buff,
if( !buffcpy )
{
die_mem();
DIE_MEM();
}
for( tok_init( &tok, buffcpy, TOK_ACCEPT_UNFINISHED );
@ -376,7 +376,7 @@ void parse_util_token_extent( const wchar_t *buff,
if( !buffcpy )
{
die_mem();
DIE_MEM();
}
for( tok_init( &tok, buffcpy, TOK_ACCEPT_UNFINISHED );
@ -527,7 +527,7 @@ int parse_util_load( const wchar_t *cmd,
halloc_register_function_void( global_context, &parse_util_destroy );
if( !all_loaded )
{
die_mem();
DIE_MEM();
}
hash_init( all_loaded, &hash_wcs_func, &hash_wcs_cmp );
}
@ -539,7 +539,7 @@ int parse_util_load( const wchar_t *cmd,
loaded = malloc( sizeof( hash_table_t ) );
if( !loaded )
{
die_mem();
DIE_MEM();
}
hash_init( loaded, &hash_wcs_func, &hash_wcs_cmp );
hash_put( all_loaded, wcsdup(path_var_name), loaded );
@ -598,7 +598,7 @@ int parse_util_load( const wchar_t *cmd,
{
tm = malloc(sizeof(time_t)*2);
if( !tm )
die_mem();
DIE_MEM();
}
tm[0] = buf.st_mtime;
@ -632,7 +632,7 @@ int parse_util_load( const wchar_t *cmd,
{
tm = malloc(sizeof(time_t)*2);
if( !tm )
die_mem();
DIE_MEM();
tm[0] = 0;
tm[1] = time(0);
@ -675,7 +675,7 @@ wchar_t *parse_util_unescape_wildcards( const wchar_t *str )
wchar_t *unescaped = wcsdup(str);
if( !unescaped )
die_mem();
DIE_MEM();
for( in=out=unescaped; *in; in++ )
{

View file

@ -680,7 +680,7 @@ wchar_t *parser_cdpath_get( void *context, wchar_t *dir )
if( !path_cpy )
{
die_mem();
DIE_MEM();
}
for( nxt_path = wcstok( path_cpy, ARRAY_SEP_STR, &state );
@ -803,7 +803,7 @@ wchar_t *parser_get_filename( void *context, const wchar_t *cmd )
if( (new_cmd==0) || (path_cpy==0) )
{
die_mem();
DIE_MEM();
}
for( nxt_path = wcstok( path_cpy, ARRAY_SEP_STR, &state );
@ -1063,7 +1063,7 @@ int eval_args( const wchar_t *line, array_list_t *args )
if( !tmp )
{
die_mem();
DIE_MEM();
}
if( expand_string( 0, tmp, args, 0 ) == EXPAND_ERROR )
@ -1519,7 +1519,7 @@ static void parse_job_main_loop( process_t *p,
p->next = halloc( j, sizeof( process_t ) );
if( p->next == 0 )
{
die_mem();
DIE_MEM();
}
tok_next( tok );
@ -1664,7 +1664,7 @@ static void parse_job_main_loop( process_t *p,
new_io = halloc( j, sizeof(io_data_t) );
if( !new_io )
die_mem();
DIE_MEM();
new_io->fd = wcstol( tok_last( tok ),
0,

View file

@ -449,7 +449,7 @@ static int check_size()
data->color==0 ||
data->new_color == 0 )
{
die_mem();
DIE_MEM();
}
}
@ -2567,7 +2567,7 @@ wchar_t *reader_readline()
{
wchar_t *str = wcsndup( data->buff, data->buff_pos );
if( !str )
die_mem();
DIE_MEM();
kill_add( str );
free( str );

View file

@ -140,7 +140,7 @@ void tok_init( tokenizer *tok, const wchar_t *b, int flags )
tok->orig_buff = tok->buff = wcsdup( tok->orig_buff );
if( !tok->orig_buff )
{
die_mem();
DIE_MEM();
}
tok->orig_buff[l-1] = L'\0';
}

View file

@ -102,7 +102,7 @@ static char *translate_wcs2str( const wchar_t *in )
wcs2str_buff = realloc( wcs2str_buff, len );
if( wcs2str_buff == 0 )
{
die_mem();
DIE_MEM();
}
}

10
util.c
View file

@ -664,7 +664,7 @@ array_list_t *al_new()
{
array_list_t *res = malloc( sizeof( array_list_t ) );
if( !res )
die_mem();
DIE_MEM();
al_init( res );
return res;
}
@ -865,7 +865,7 @@ string_buffer_t *sb_new()
{
string_buffer_t *res = malloc( sizeof( string_buffer_t ) );
if( !res )
die_mem();
DIE_MEM();
sb_init( res );
return res;
}
@ -972,7 +972,7 @@ int sb_vprintf( string_buffer_t *buffer, const wchar_t *format, va_list va_orig
buffer->length = MIN_SIZE;
buffer->buff = malloc( MIN_SIZE );
if( !buffer->buff )
die_mem();
DIE_MEM();
}
@ -1012,7 +1012,7 @@ int sb_vprintf( string_buffer_t *buffer, const wchar_t *format, va_list va_orig
buffer->buff = realloc( buffer->buff, 2*buffer->length );
if( !buffer->buff )
die_mem();
DIE_MEM();
buffer->length *= 2;
}
return res;
@ -1085,7 +1085,7 @@ void b_append( buffer_t *b, const void *d, ssize_t len )
void *d = realloc( b->buff, l );
if( !d )
{
die_mem();
DIE_MEM();
}
b->buff=d;

View file

@ -290,7 +290,7 @@ static wchar_t *make_path( const wchar_t *base_dir, const wchar_t *name )
int base_len = wcslen( base_dir );
if( !(long_name= malloc( sizeof(wchar_t)*(base_len+wcslen(name)+1) )))
{
die_mem();
DIE_MEM();
}
wcscpy( long_name, base_dir );
wcscpy(&long_name[base_len], name );
@ -637,7 +637,7 @@ int wildcard_expand( const wchar_t *wc,
if( (!new_dir) || (!wc_str) )
{
die_mem();
DIE_MEM();
}
wcscpy( new_dir, base_dir );

View file

@ -108,7 +108,7 @@ static char *wutil_wcs2str( const wchar_t *in )
tmp = realloc( tmp, new_sz );
if( !tmp )
{
die_mem();
DIE_MEM();
}
tmp_len = new_sz;
}
@ -135,7 +135,7 @@ static wchar_t *wutil_str2wcs( const char *in )
tmp2 = realloc( tmp2, new_sz );
if( !tmp2 )
{
die_mem();
DIE_MEM();
}
tmp2_len = new_sz;
}