Excised some more halloc

This commit is contained in:
ridiculousfish 2012-01-29 23:22:42 -08:00
parent 8d016040ab
commit 316f81119f
10 changed files with 27 additions and 30 deletions

View file

@ -3810,7 +3810,7 @@ void builtin_destroy()
hash_destroy( &builtin );
}
int builtin_exists( wchar_t *cmd )
int builtin_exists( const wchar_t *cmd )
{
CHECK( cmd, 0 );

View file

@ -123,7 +123,7 @@ void builtin_destroy();
/**
Is there a builtin command with the given name?
*/
int builtin_exists( wchar_t *cmd );
int builtin_exists( const wchar_t *cmd );
/**
Execute a builtin command

View file

@ -607,7 +607,7 @@ static void parse_cmd_string( void *context,
wchar_t *cmd, *path;
/* Get the path of the command */
path = path_get_path( context, str );
path = (wchar_t *)halloc_register(context, path_get_path( str ));
if( path == 0 )
{
/**
@ -937,7 +937,6 @@ static void complete_strings( std::vector<completion_t> &comp_out,
*/
static void complete_cmd_desc( const wchar_t *cmd, std::vector<completion_t> &comp )
{
int i;
const wchar_t *cmd_start;
int cmd_len;
wchar_t *lookup_cmd=0;
@ -973,7 +972,7 @@ static void complete_cmd_desc( const wchar_t *cmd, std::vector<completion_t> &co
skip = 1;
for( i=0; i< comp.size(); i++ )
for( size_t i=0; i< comp.size(); i++ )
{
const completion_t &c = comp.at ( i );
@ -1017,7 +1016,7 @@ static void complete_cmd_desc( const wchar_t *cmd, std::vector<completion_t> &co
Should be reasonably fast, since no memory allocations are needed.
*/
for( i=0; i<al_get_count( &list); i++ )
for( int i=0; i<al_get_count( &list); i++ )
{
wchar_t *el = (wchar_t *)al_get( &list, i );
wchar_t *key, *key_end, *val_begin;
@ -1051,7 +1050,7 @@ static void complete_cmd_desc( const wchar_t *cmd, std::vector<completion_t> &co
This needs to do a reallocation for every description added, but
there shouldn't be that many completions, so it should be ok.
*/
for( i=0; i<comp.size(); i++ )
for( size_t i=0; i<comp.size(); i++ )
{
completion_t &c = comp.at( i );
// const wchar_t *el = c.completion.empty()?NULL:c.completion.c_str();
@ -1144,8 +1143,7 @@ static void complete_cmd( const wchar_t *cmd,
nxt_path != 0;
nxt_path = wcstok( 0, ARRAY_SEP_STR, &state) )
{
int prev_count;
int i;
size_t prev_count;
int path_len = wcslen(nxt_path);
int add_slash;
@ -1169,7 +1167,7 @@ static void complete_cmd( const wchar_t *cmd,
ACCEPT_INCOMPLETE |
EXECUTABLES_ONLY ) != EXPAND_ERROR )
{
for( i=prev_count; i< comp.size(); i++ )
for( size_t i=prev_count; i< comp.size(); i++ )
{
completion_t &c = comp.at( i );
if(c.flags & COMPLETE_NO_CASE )

View file

@ -554,7 +554,7 @@ static void launch_process( process_t *p )
res[i+1] = 0;
p->set_argv(res);
p->actual_cmd = sh_command;
p->actual_cmd = wcsdup(sh_command);
res_real = wcsv2strv( (const wchar_t **) res);

View file

@ -723,7 +723,7 @@ static int expand_pid( wchar_t *in,
}
}
int prev = out.size();
size_t prev = out.size();
if( !find_process( in+1, flags, out ) )
return 0;

View file

@ -54,12 +54,11 @@ static int has_xsel()
static int res = 0;
if (!called) {
void *context = halloc(0, 0);
wchar_t *path = path_get_path( context, L"xsel" );
wchar_t *path = path_get_path( L"xsel" );
res = !!path;
halloc_free( context );
free(path);
called = 1;
}
}
return res;
}

View file

@ -1884,7 +1884,7 @@ int parser_t::parse_job( process_t *p,
if( !p->type )
{
if( use_builtin &&
builtin_exists( const_cast<wchar_t*>(args->at(0).completion.c_str()) ) )
builtin_exists(args->at(0).completion.c_str()))
{
p->type = INTERNAL_BUILTIN;
is_new_block |= parser_keywords_is_block( args->at( 0 ).completion.c_str() );
@ -1899,19 +1899,18 @@ int parser_t::parse_job( process_t *p,
*/
if( current_block->skip )
{
p->actual_cmd = L"";
p->actual_cmd = wcsdup(L"");
}
else
{
int err;
p->actual_cmd = path_get_path( j, args->at(0).completion.c_str() );
p->actual_cmd = path_get_path( args->at(0).completion.c_str() );
err = errno;
/*
Check if the specified command exists
*/
if( p->actual_cmd == 0 )
if( p->actual_cmd == NULL )
{
/*

View file

@ -128,7 +128,7 @@ bool path_get_path_string(const wcstring &cmd_str, wcstring &output, const env_v
}
wchar_t *path_get_path( void *context, const wchar_t *cmd )
wchar_t *path_get_path( const wchar_t *cmd )
{
int err = ENOENT;
@ -147,7 +147,7 @@ wchar_t *path_get_path( void *context, const wchar_t *cmd )
}
if( S_ISREG(buff.st_mode) )
return halloc_wcsdup( context, cmd );
return wcsdup( cmd );
else
{
errno = EACCES;
@ -180,7 +180,7 @@ wchar_t *path_get_path( void *context, const wchar_t *cmd )
/*
Allocate string long enough to hold the whole command
*/
wchar_t *new_cmd = (wchar_t *)halloc( context, sizeof(wchar_t)*(wcslen(cmd)+path.size()+2) );
wchar_t *new_cmd = (wchar_t *)calloc(wcslen(cmd)+path.size()+2, sizeof(wchar_t) );
/*
We tokenize a copy of the path, since strtok modifies

4
path.h
View file

@ -28,9 +28,9 @@ wchar_t *path_get_config( void *context);
\param cmd The name of the executable.
\param context the halloc context to use for memory allocations
\return 0 if the command can not be found, the path of the command otherwise.
\return 0 if the command can not be found, the path of the command otherwise. The result should be freed with free().
*/
wchar_t *path_get_path( void *context, const wchar_t *cmd );
wchar_t *path_get_path( const wchar_t *cmd );
class env_vars;
bool path_get_path_string(const wcstring &cmd, wcstring &output, const env_vars &vars);

5
proc.h
View file

@ -166,6 +166,7 @@ class process_t
if (this->next != NULL)
delete this->next;
this->free_argv();
free((void *)actual_cmd); //may be NULL
}
/**
@ -178,7 +179,6 @@ class process_t
/** Sets argv */
void set_argv(wchar_t **argv) {
free_argv();
#if 0
// argv must be a malloc'd array of malloc'd strings. This bit of nonsense below can help catch if someone doesn't pass us something from malloc.
@ -191,6 +191,7 @@ class process_t
}
#endif
free_argv();
this->argv_array = argv;
}
@ -203,7 +204,7 @@ class process_t
/** Returns argv[idx] */
const wchar_t *argv(size_t idx) const { return argv_array[idx]; }
/** actual command to pass to exec in case of EXTERNAL or INTERNAL_EXEC */
/** actual command to pass to exec in case of EXTERNAL or INTERNAL_EXEC. malloc'd! */
const wchar_t *actual_cmd;
/** process ID */