Yet more un-hallocing

This commit is contained in:
ridiculousfish 2012-01-30 02:23:58 -08:00
parent 316f81119f
commit 79e0405f6a
5 changed files with 31 additions and 22 deletions

View file

@ -907,15 +907,11 @@ static void complete_strings( std::vector<completion_t> &comp_out,
std::vector<completion_t> &possible_comp, std::vector<completion_t> &possible_comp,
int flags ) int flags )
{ {
wchar_t *wc, *tmp; wcstring tmp = wc_escaped;
if (! expand_one(tmp, EXPAND_SKIP_CMDSUBST | EXPAND_SKIP_WILDCARDS))
tmp = expand_one( 0, return;
wcsdup(wc_escaped), EXPAND_SKIP_CMDSUBST | EXPAND_SKIP_WILDCARDS);
if(!tmp) const wchar_t *wc = parse_util_unescape_wildcards( tmp.c_str() );
return;
wc = parse_util_unescape_wildcards( tmp );
free(tmp);
for( size_t i=0; i< possible_comp.size(); i++ ) for( size_t i=0; i< possible_comp.size(); i++ )
{ {
@ -928,7 +924,7 @@ static void complete_strings( std::vector<completion_t> &comp_out,
} }
} }
free( wc ); free( (void *)wc );
} }
/** /**

View file

@ -2585,7 +2585,7 @@ int expand_string( void *context,
} }
*/ */
wchar_t *expand_one( void *context, wchar_t *string, int flags ) wchar_t *expand_one( void *context, const wchar_t *string, int flags )
{ {
std::vector<completion_t> l; std::vector<completion_t> l;
int res; int res;
@ -2595,8 +2595,8 @@ wchar_t *expand_one( void *context, wchar_t *string, int flags )
if( (!(flags & ACCEPT_INCOMPLETE)) && expand_is_clean( string ) ) if( (!(flags & ACCEPT_INCOMPLETE)) && expand_is_clean( string ) )
{ {
halloc_register( context, string ); halloc_register( context, (void *)string );
return string; return (wchar_t *)string;
} }
// al_init( &l ); // al_init( &l );
@ -2625,5 +2625,17 @@ wchar_t *expand_one( void *context, wchar_t *string, int flags )
halloc_register( context, one ); halloc_register( context, one );
return one; return one;
} }
bool expand_one( wcstring &in, int flag ) {
bool result = false;
wchar_t *res = expand_one(NULL, in.c_str(), flag);
if (res) {
in = res;
free(res);
result = true;
}
return result;
}

View file

@ -165,7 +165,10 @@ __warn_unused int expand_string2( const wcstring &input, std::vector<completion_
\param flag Specifies if any expansion pass should be skipped. Legal values are any combination of EXPAND_SKIP_CMDSUBST EXPAND_SKIP_VARIABLES and EXPAND_SKIP_WILDCARDS \param flag Specifies if any expansion pass should be skipped. Legal values are any combination of EXPAND_SKIP_CMDSUBST EXPAND_SKIP_VARIABLES and EXPAND_SKIP_WILDCARDS
\return The expanded parameter, or 0 on failiure \return The expanded parameter, or 0 on failiure
*/ */
wchar_t *expand_one( void *context, wchar_t *in, int flag ); wchar_t *expand_one( void *context, const wchar_t *in, int flag );
/** expand_one for a wcstring. Modifies the string in-place, returning true on success and false on failure */
bool expand_one( wcstring &inout_str, int flag );
/** /**
Convert the variable value to a human readable form, i.e. escape things, handle arrays, etc. Suitable for pretty-printing. The result must be free'd! Convert the variable value to a human readable form, i.e. escape things, handle arrays, etc. Suitable for pretty-printing. The result must be free'd!

View file

@ -605,11 +605,10 @@ void tokenize( const wchar_t * const buff, int * const color, const int pos, arr
if( cmd && (wcscmp( cmd, L"cd" ) == 0) ) if( cmd && (wcscmp( cmd, L"cd" ) == 0) )
{ {
wchar_t *dir = expand_one( context, wcstring dir_str = tok_last( &tok );
wcsdup(tok_last( &tok )), if (expand_one(dir_str, EXPAND_SKIP_CMDSUBST))
EXPAND_SKIP_CMDSUBST );
if( dir )
{ {
const wchar_t *dir = dir_str.c_str();
int is_long_help = wcsncmp(dir,L"--help", wcslen(dir) ); int is_long_help = wcsncmp(dir,L"--help", wcslen(dir) );
int is_short_help = wcsncmp(dir,L"-h", wcslen(dir) ); int is_short_help = wcsncmp(dir,L"-h", wcslen(dir) );

View file

@ -1969,7 +1969,7 @@ int parser_t::parse_job( process_t *p,
*/ */
if( wcschr( cmd, L'=' ) ) if( wcschr( cmd, L'=' ) )
{ {
wchar_t *cpy = halloc_wcsdup( j, cmd ); wchar_t *cpy = wcsdup( cmd );
wchar_t *valpart = wcschr( cpy, L'=' ); wchar_t *valpart = wcschr( cpy, L'=' );
*valpart++=0; *valpart++=0;
@ -1978,6 +1978,7 @@ int parser_t::parse_job( process_t *p,
cmd, cmd,
cpy, cpy,
valpart); valpart);
free(cpy);
} }
else if(cmd[0]==L'$') else if(cmd[0]==L'$')
@ -2112,9 +2113,7 @@ int parser_t::parse_job( process_t *p,
{ {
int end_pos = end-tok_string( tok ); int end_pos = end-tok_string( tok );
wchar_t *sub_block= halloc_wcsndup( j, const wcstring sub_block(tok_string( tok ) + current_tokenizer_pos, end_pos - current_tokenizer_pos);
tok_string( tok ) + current_tokenizer_pos,
end_pos - current_tokenizer_pos);
p->type = INTERNAL_BLOCK; p->type = INTERNAL_BLOCK;
completion_t data_to_push; completion_t data_to_push;