aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--common.cpp17
-rw-r--r--common.h1
-rw-r--r--exec.cpp4
-rw-r--r--io.cpp16
-rw-r--r--io.h16
-rw-r--r--parser.cpp25
-rw-r--r--parser.h2
-rw-r--r--path.cpp40
-rw-r--r--path.h5
-rw-r--r--proc.h8
10 files changed, 41 insertions, 93 deletions
diff --git a/common.cpp b/common.cpp
index 0cab244d..40c07404 100644
--- a/common.cpp
+++ b/common.cpp
@@ -113,11 +113,6 @@ int debug_level=1;
*/
static struct winsize termsize;
-/**
- String buffer used by the wsetlocale function
-*/
-static string_buffer_t *setlocale_buff=0;
-
void show_stackframe()
{
@@ -485,20 +480,26 @@ wchar_t **strv2wcsv( const char **in )
return res;
}
-
wcstring format_string(const wchar_t *format, ...)
{
va_list va;
va_start( va, format );
+ wcstring result = vformat_string(format, va);
+ va_end( va );
+ return result;
+}
+
+wcstring vformat_string(const wchar_t *format, va_list va_orig)
+{
string_buffer_t buffer;
sb_init(&buffer);
- sb_vprintf(&buffer, format, va);
+ sb_vprintf(&buffer, format, va_orig);
wcstring result = (wchar_t *)buffer.buff;
sb_destroy(&buffer);
- va_end( va );
return result;
}
+
wchar_t *wcsvarname( const wchar_t *str )
{
while( *str )
diff --git a/common.h b/common.h
index 5f6936b0..50d033a0 100644
--- a/common.h
+++ b/common.h
@@ -361,6 +361,7 @@ public:
void append_path_component(wcstring &path, const wcstring &component);
wcstring format_string(const wchar_t *format, ...);
+wcstring vformat_string(const wchar_t *format, va_list va_orig);
/**
Returns a newly allocated wide character string array equivalent of
diff --git a/exec.cpp b/exec.cpp
index 95bb7e43..d987a0c7 100644
--- a/exec.cpp
+++ b/exec.cpp
@@ -950,11 +950,11 @@ void exec( parser_t &parser, job_t *j )
{
if( j->io )
{
- j->io = io_add( io_duplicate( j, parser.block_io), j->io );
+ j->io = io_add( io_duplicate(parser.block_io), j->io );
}
else
{
- j->io=io_duplicate( j, parser.block_io);
+ j->io=io_duplicate(parser.block_io);
}
}
diff --git a/io.cpp b/io.cpp
index bf9776f4..3b30b2ef 100644
--- a/io.cpp
+++ b/io.cpp
@@ -48,8 +48,6 @@ Utilities for io redirection.
#include "common.h"
#include "io.h"
-#include "halloc.h"
-
void io_buffer_read( io_data_t *d )
{
@@ -195,23 +193,15 @@ io_data_t *io_remove( io_data_t *list, io_data_t *element )
return list;
}
-io_data_t *io_duplicate( void *context, io_data_t *l )
+io_data_t *io_duplicate( io_data_t *l )
{
io_data_t *res;
if( l == 0 )
return 0;
- res = (io_data_t *)halloc( context, sizeof( io_data_t) );
-
- if( !res )
- {
- DIE_MEM();
-
- }
-
- memcpy( res, l, sizeof(io_data_t ));
- res->next=io_duplicate( context, l->next );
+ res = new io_data_t(*l);
+ res->next=io_duplicate(l->next );
return res;
}
diff --git a/io.h b/io.h
index c2e2d530..56eba9c0 100644
--- a/io.h
+++ b/io.h
@@ -11,7 +11,7 @@ enum io_mode
;
/** Represents an FD redirection */
-typedef struct io_data
+struct io_data_t
{
/** Type of redirect */
int io_mode;
@@ -41,8 +41,7 @@ typedef struct io_data
buffer_t *out_buffer;
/** Whether to close old_fd for IO_FD */
int close_old;
- } param2
- ;
+ } param2;
/**
Set to true if this is an input io redirection
@@ -50,9 +49,10 @@ typedef struct io_data
int is_input;
/** Pointer to the next IO redirection */
- struct io_data *next;
-}
-io_data_t;
+ io_data_t *next;
+
+ io_data_t() : next(NULL) { }
+};
/**
@@ -66,9 +66,9 @@ io_data_t *io_add( io_data_t *first_chain, io_data_t *decond_chain );
io_data_t *io_remove( io_data_t *list, io_data_t *element );
/**
- Make a copy of the specified chain of redirections. Uses halloc.
+ Make a copy of the specified chain of redirections. Uses operator new.
*/
-io_data_t *io_duplicate( void *context, io_data_t *l );
+io_data_t *io_duplicate( io_data_t *l );
/**
Return the last io redirection in the chain for the specified file descriptor.
diff --git a/parser.cpp b/parser.cpp
index 80bced8e..1263a7dd 100644
--- a/parser.cpp
+++ b/parser.cpp
@@ -361,7 +361,6 @@ parser_t::parser_t(enum parser_type_t type) :
parser_type(type),
error_code(0),
err_pos(0),
- err_buff(NULL),
current_tokenizer(NULL),
lineinfo(NULL),
current_tokenizer_pos(0),
@@ -602,17 +601,11 @@ void parser_t::error( int ec, int p, const wchar_t *str, ... )
CHECK( str, );
- if( !err_buff )
- err_buff = sb_halloc( global_context );
- sb_clear( err_buff );
-
error_code = ec;
err_pos = p;
va_start( va, str );
-
- sb_vprintf( err_buff, str, va );
-
+ err_buff = vformat_string(str, va);
va_end( va );
}
@@ -744,11 +737,11 @@ void parser_t::print_errors( string_buffer_t *target, const wchar_t *prefix )
CHECK( target, );
CHECK( prefix, );
- if( error_code && err_buff )
+ if( error_code && ! err_buff.empty() )
{
int tmp;
- sb_printf( target, L"%ls: %ls\n", prefix, (wchar_t *)err_buff->buff );
+ sb_printf( target, L"%ls: %ls\n", prefix, err_buff.c_str() );
tmp = current_tokenizer_pos;
current_tokenizer_pos = err_pos;
@@ -764,9 +757,9 @@ void parser_t::print_errors( string_buffer_t *target, const wchar_t *prefix )
*/
void parser_t::print_errors_stderr()
{
- if( error_code && err_buff )
+ if( error_code && ! err_buff.empty() )
{
- debug( 0, L"%ls", (wchar_t *)err_buff->buff );
+ debug( 0, L"%ls", err_buff.c_str() );
int tmp;
tmp = current_tokenizer_pos;
@@ -1415,7 +1408,7 @@ void parser_t::parse_job_argument_list( process_t *p,
case TOK_REDIRECT_NOCLOB:
{
int type = tok_last_type( tok );
- io_data_t *new_io;
+ std::auto_ptr<io_data_t> new_io;
wcstring target;
bool has_target = false;
wchar_t *end;
@@ -1440,9 +1433,7 @@ void parser_t::parse_job_argument_list( process_t *p,
break;
}
- new_io = (io_data_t *)halloc( j, sizeof(io_data_t) );
- if( !new_io )
- DIE_MEM();
+ new_io.reset(new io_data_t);
errno = 0;
new_io->fd = wcstol( tok_last( tok ),
@@ -1557,7 +1548,7 @@ void parser_t::parse_job_argument_list( process_t *p,
}
}
- j->io = io_add( j->io, new_io );
+ j->io = io_add( j->io, new_io.release() );
}
break;
diff --git a/parser.h b/parser.h
index 271d7195..10efc69b 100644
--- a/parser.h
+++ b/parser.h
@@ -289,7 +289,7 @@ class parser_t {
int err_pos;
/** Description of last error */
- string_buffer_t *err_buff;
+ wcstring err_buff;
/** Pointer to the current tokenizer */
tokenizer *current_tokenizer;
diff --git a/path.cpp b/path.cpp
index 7b56388a..cffa7bb7 100644
--- a/path.cpp
+++ b/path.cpp
@@ -443,46 +443,6 @@ bool path_can_get_cdpath(const wcstring &in) {
return result;
}
-wchar_t *path_get_config( void *context)
-{
- int done = 0;
- wcstring res;
-
- const env_var_t xdg_dir = env_get_string( L"XDG_CONFIG_HOME" );
- if( ! xdg_dir.missing() )
- {
- res = xdg_dir + L"/fish";
- if( !create_directory( res.c_str() ) )
- {
- done = 1;
- }
- }
- else
- {
- const env_var_t home = env_get_string( L"HOME" );
- if( ! home.missing() )
- {
- res = home + L"/.config/fish";
- if( !create_directory( res.c_str() ) )
- {
- done = 1;
- }
- }
- }
-
- if( done )
- {
- wchar_t *result = wcsdup(res.c_str());
- halloc_register_function( context, &free, result );
- return result;
- }
- else
- {
- debug( 0, _(L"Unable to create a configuration directory for fish. Your personal settings will not be saved. Please set the $XDG_CONFIG_HOME variable to a directory where the current user has write access." ));
- return 0;
- }
-}
-
bool path_get_config(wcstring &path)
{
diff --git a/path.h b/path.h
index 39918382..b46eff43 100644
--- a/path.h
+++ b/path.h
@@ -18,10 +18,9 @@
Returns the user configuration directory for fish. If the directory
or one of it's parents doesn't exist, they are first created.
- \param context the halloc context to use for memory allocations
- \return 0 if the no configuration directory can be located or created, the directory path otherwise.
+ \param path The directory as an out param
+ \return whether the directory was returned successfully
*/
-wchar_t *path_get_config( void *context);
bool path_get_config(wcstring &path);
/**
diff --git a/proc.h b/proc.h
index 92bdc62f..a995af90 100644
--- a/proc.h
+++ b/proc.h
@@ -297,6 +297,12 @@ class job_t
~job_t() {
if (first_process != NULL)
delete first_process;
+ io_data_t *data = this->io;
+ while (data) {
+ io_data_t *tmp = data->next;
+ delete data;
+ data = tmp;
+ }
}
@@ -336,7 +342,7 @@ class job_t
const int job_id;
/**
- List of all IO redirections for this job
+ List of all IO redirections for this job. This linked list is allocated via new, and owned by the object, which should delete them.
*/
io_data_t *io;