Second checkin of halloc changeover. Make the argv array, but not it's contents, be allocated using halloc. Also make list_to_char_arr use halloc

darcs-hash:20060206151817-ac50b-e8fd4cff831ee975c5bf3855d9ecfc15a3fb9215.gz
This commit is contained in:
axel 2006-02-07 01:18:17 +10:00
parent e756f7d619
commit 6291be256b
7 changed files with 22 additions and 20 deletions

View File

@ -59,6 +59,7 @@
#include "event.h"
#include "signal.h"
#include "translate.h"
#include "halloc.h"
/**
The default prompt for the read command
@ -494,7 +495,7 @@ static int builtin_builtin( wchar_t **argv )
al_init( &names );
builtin_get_names( &names );
names_arr = list_to_char_arr( &names );
names_arr = list_to_char_arr( 0, &names );
qsort( names_arr,
al_get_count( &names ),
sizeof(wchar_t *),
@ -509,7 +510,7 @@ static int builtin_builtin( wchar_t **argv )
L"\n",
(void *)0 );
}
free( names_arr );
halloc_free( names_arr );
al_destroy( &names );
}
return 0;
@ -811,7 +812,7 @@ static int builtin_functions( wchar_t **argv )
al_init( &names );
function_get_names( &names, show_hidden );
names_arr = list_to_char_arr( &names );
names_arr = list_to_char_arr( 0, &names );
qsort( names_arr,
al_get_count( &names ),
sizeof(wchar_t *),
@ -843,7 +844,7 @@ static int builtin_functions( wchar_t **argv )
}
}
free( names_arr );
halloc_free( names_arr );
al_destroy( &names );
return 0;
}
@ -856,7 +857,7 @@ static int builtin_functions( wchar_t **argv )
sb_append( sb_out, _( L"Current function definitions are:\n\n" ) );
al_init( &names );
function_get_names( &names, show_hidden );
names_arr = list_to_char_arr( &names );
names_arr = list_to_char_arr( 0, &names );
qsort( names_arr,
al_get_count( &names ),
sizeof(wchar_t *),
@ -865,7 +866,7 @@ static int builtin_functions( wchar_t **argv )
{
functions_def( names_arr[i] );
}
free( names_arr );
halloc_free( names_arr );
al_destroy( &names );
break;
}
@ -1167,7 +1168,7 @@ static int builtin_function( wchar_t **argv )
al_init( &names );
function_get_names( &names, 0 );
names_arr = list_to_char_arr( &names );
names_arr = list_to_char_arr( 0, &names );
qsort( names_arr,
al_get_count( &names ),
sizeof(wchar_t *),
@ -1193,7 +1194,7 @@ static int builtin_function( wchar_t **argv )
al_foreach( events, (void (*)(const void *))&event_free );
al_destroy( events );
free( events );
halloc_free( events );
}
else
{

View File

@ -58,6 +58,7 @@ parts of fish.
#include "proc.h"
#include "wildcard.h"
#include "parser.h"
#include "halloc.h"
/**
The maximum number of minor errors to report. Further errors will be omitted.
@ -115,9 +116,9 @@ void common_destroy()
}
}
wchar_t **list_to_char_arr( array_list_t *l )
wchar_t **list_to_char_arr( void *context, array_list_t *l )
{
wchar_t ** res = malloc( sizeof(wchar_t *)*(al_get_count( l )+1) );
wchar_t ** res = halloc( context, sizeof(wchar_t *)*(al_get_count( l )+1) );
int i;
if( res == 0 )
{

View File

@ -83,9 +83,10 @@ extern wchar_t *program_name;
/**
Take an array_list_t containing wide strings and converts them to a
single null-terminated wchar_t **.
single null-terminated wchar_t **. The array is allocated using
halloc, and uses the \c context parameter as context.
*/
wchar_t **list_to_char_arr( array_list_t *l );
wchar_t **list_to_char_arr( void *context, array_list_t *l );
/**
Read a line from the stream f into the buffer buff of length len. If

5
exec.c
View File

@ -37,6 +37,7 @@
#include "signal.h"
#include "env_universal.h"
#include "translate.h"
#include "halloc.h"
/**
Prototype for the getpgid library function. The prototype for this
@ -791,7 +792,7 @@ void exec( job_t *j )
int i;
string_buffer_t sb;
const wchar_t * def = wcsdup(function_get_definition( p->argv[0] ));
wchar_t * def = halloc_wcsdup( j, function_get_definition( p->argv[0] ));
//fwprintf( stderr, L"run function %ls\n", argv[0] );
if( def == 0 )
{
@ -834,8 +835,6 @@ void exec( job_t *j )
internal_exec_helper( def, TOP, j->io );
free( def );
parser_allow_function();
parser_pop_block();

2
io.c
View File

@ -37,7 +37,7 @@ Utilities for io redirection.
#include "common.h"
#include "io.h"
#include "translate.h"
#include "halloc.h"
void io_buffer_read( io_data_t *d )

View File

@ -1376,7 +1376,7 @@ static void parse_job_main_loop( process_t *p,
return;
}
p->pipe_fd = wcstol( tok_last( tok ), 0, 10 );
p->argv = list_to_char_arr( args );
p->argv = list_to_char_arr( j, args );
p->next = halloc( j, sizeof( process_t ) );
if( p->next == 0 )
{
@ -1398,7 +1398,7 @@ static void parse_job_main_loop( process_t *p,
case TOK_END:
{
p->argv = list_to_char_arr( args );
p->argv = list_to_char_arr( j, args );
if( tok_has_next(tok))
tok_next(tok);
@ -2089,7 +2089,7 @@ static int parse_job( process_t *p,
{
if( p->type == INTERNAL_BUILTIN && parser_skip_arguments( (wchar_t *)al_get(&args, 0) ) )
{
p->argv = list_to_char_arr( &args );
p->argv = list_to_char_arr( j, &args );
// tok_next(tok);
}
else

2
proc.c
View File

@ -53,6 +53,7 @@ Some of the code in this file is based on code from the Glibc manual.
#include "signal.h"
#include "event.h"
#include "translate.h"
#include "halloc.h"
/**
Size of message buffer
@ -127,7 +128,6 @@ static void free_process( process_t *p )
{
free( *arg );
}
free(p->argv );
}
}