aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar axel <axel@liljencrantz.se>2006-02-07 01:18:17 +1000
committerGravatar axel <axel@liljencrantz.se>2006-02-07 01:18:17 +1000
commit6291be256b520fe66408acc34579011d3f2dedbe (patch)
tree30608632a38b14f10f9a0cfbbd5e1ec709abab24
parente756f7d619a7458768d59cd9bd1c97c6a1c7788a (diff)
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
-rw-r--r--builtin.c17
-rw-r--r--common.c5
-rw-r--r--common.h5
-rw-r--r--exec.c5
-rw-r--r--io.c2
-rw-r--r--parser.c6
-rw-r--r--proc.c2
7 files changed, 22 insertions, 20 deletions
diff --git a/builtin.c b/builtin.c
index a54be9e4..7444ef09 100644
--- a/builtin.c
+++ b/builtin.c
@@ -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
{
diff --git a/common.c b/common.c
index 054b5741..cc873688 100644
--- a/common.c
+++ b/common.c
@@ -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 )
{
diff --git a/common.h b/common.h
index c3ef109b..180f0fd4 100644
--- a/common.h
+++ b/common.h
@@ -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
diff --git a/exec.c b/exec.c
index da3587a4..b7ef061e 100644
--- a/exec.c
+++ b/exec.c
@@ -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();
diff --git a/io.c b/io.c
index 8da4dad1..de36e56e 100644
--- a/io.c
+++ b/io.c
@@ -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 )
diff --git a/parser.c b/parser.c
index 6808dc82..80fcaf7c 100644
--- a/parser.c
+++ b/parser.c
@@ -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
diff --git a/proc.c b/proc.c
index 5769ba14..a52107c6 100644
--- a/proc.c
+++ b/proc.c
@@ -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 );
}
}