mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-12 13:08:49 +00:00
Excised some halloc
This commit is contained in:
parent
399c78fbf7
commit
c0e783eb6e
6 changed files with 39 additions and 87 deletions
|
@ -555,8 +555,6 @@ static int builtin_complete( parser_t &parser, wchar_t **argv )
|
||||||
{
|
{
|
||||||
recursion_level++;
|
recursion_level++;
|
||||||
|
|
||||||
// comp = al_halloc( 0 );
|
|
||||||
|
|
||||||
complete( do_complete, comp );
|
complete( do_complete, comp );
|
||||||
|
|
||||||
for( size_t i=0; i< comp.size() ; i++ )
|
for( size_t i=0; i< comp.size() ; i++ )
|
||||||
|
@ -585,7 +583,6 @@ static int builtin_complete( parser_t &parser, wchar_t **argv )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// halloc_free( comp );
|
|
||||||
recursion_level--;
|
recursion_level--;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
28
complete.cpp
28
complete.cpp
|
@ -215,36 +215,10 @@ void completion_allocate(std::vector<completion_t> &completions, const wcstring
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Destroys various structures used for tab-completion and free()s the memory used by them.
|
The init function for the completion code. Does nothing.
|
||||||
*/
|
|
||||||
static void complete_destroy()
|
|
||||||
{
|
|
||||||
complete_entry_t *i=first_entry, *prev;
|
|
||||||
|
|
||||||
while( i )
|
|
||||||
{
|
|
||||||
prev = i;
|
|
||||||
i=i->next;
|
|
||||||
complete_free_entry( prev );
|
|
||||||
}
|
|
||||||
first_entry = 0;
|
|
||||||
|
|
||||||
completion_autoloader.unload_all();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
The init function for the completion code. Currently, all it really
|
|
||||||
does is make sure complete_destroy is called on exit.
|
|
||||||
*/
|
*/
|
||||||
static void complete_init()
|
static void complete_init()
|
||||||
{
|
{
|
||||||
static int is_init = 0;
|
|
||||||
if( !is_init )
|
|
||||||
{
|
|
||||||
is_init = 1;
|
|
||||||
halloc_register_function_void( global_context, &complete_destroy );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
15
env.cpp
15
env.cpp
|
@ -769,15 +769,12 @@ int env_set( const wchar_t *key,
|
||||||
|
|
||||||
if( val && contains( key, L"PWD", L"HOME" ) )
|
if( val && contains( key, L"PWD", L"HOME" ) )
|
||||||
{
|
{
|
||||||
void *context = halloc( 0, 0 );
|
/* Canoncalize our path; if it changes, recurse and try again. */
|
||||||
const wchar_t *val_canonical = path_make_canonical( context, val );
|
wcstring val_canonical = val;
|
||||||
if( wcscmp( val_canonical, val ) )
|
path_make_canonical(val_canonical);
|
||||||
{
|
if (val != val_canonical) {
|
||||||
int res = env_set( key, val_canonical, var_mode );
|
return env_set( key, val_canonical.c_str(), var_mode );
|
||||||
halloc_free( context );
|
}
|
||||||
return res;
|
|
||||||
}
|
|
||||||
halloc_free( context );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if( (var_mode & ENV_USER ) && is_read_only(key) )
|
if( (var_mode & ENV_USER ) && is_read_only(key) )
|
||||||
|
|
|
@ -752,18 +752,13 @@ static void test_path()
|
||||||
{
|
{
|
||||||
say( L"Testing path functions" );
|
say( L"Testing path functions" );
|
||||||
|
|
||||||
void *context = halloc( 0, 0 );
|
wcstring path = L"//foo//////bar/";
|
||||||
|
wcstring canon = path;
|
||||||
|
path_make_canonical(canon);
|
||||||
wchar_t *can = path_make_canonical( context, L"//foo//////bar/" );
|
if( canon != L"/foo/bar" ) )
|
||||||
|
|
||||||
if( wcscmp( can, L"/foo/bar" ) )
|
|
||||||
{
|
{
|
||||||
err( L"Bug in canonical PATH code" );
|
err( L"Bug in canonical PATH code" );
|
||||||
}
|
}
|
||||||
|
|
||||||
halloc_free( context );
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
56
path.cpp
56
path.cpp
|
@ -514,38 +514,30 @@ bool path_get_config(wcstring &path)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wchar_t *path_make_canonical( void *context, const wchar_t *path )
|
static void replace_all(wcstring &str, const wchar_t *needle, const wchar_t *replacement)
|
||||||
{
|
{
|
||||||
wchar_t *res = halloc_wcsdup( context, path );
|
size_t needle_len = wcslen(needle);
|
||||||
wchar_t *in, *out;
|
size_t offset = 0;
|
||||||
|
while((offset = str.find(needle, offset)) != wcstring::npos)
|
||||||
in = out = res;
|
{
|
||||||
|
str.replace(offset, needle_len, replacement);
|
||||||
while( *in )
|
offset += needle_len;
|
||||||
{
|
}
|
||||||
if( *in == L'/' )
|
}
|
||||||
{
|
|
||||||
while( *(in+1) == L'/' )
|
void path_make_canonical( wcstring &path )
|
||||||
{
|
{
|
||||||
in++;
|
|
||||||
}
|
/* Remove double slashes */
|
||||||
}
|
replace_all(path, L"//", L"/");
|
||||||
*out = *in;
|
|
||||||
|
/* Remove trailing slashes */
|
||||||
out++;
|
size_t size = path.size();
|
||||||
in++;
|
while (size--) {
|
||||||
}
|
if (path.at(size) != L'/')
|
||||||
|
break;
|
||||||
while( 1 )
|
}
|
||||||
{
|
/* Now size is either -1 (if the entire string was slashes) or is the index of the last non-slash character. Either way this will set it to the correct size. */
|
||||||
if( out == res )
|
path.resize(size+1);
|
||||||
break;
|
|
||||||
if( *(out-1) != L'/' )
|
|
||||||
break;
|
|
||||||
out--;
|
|
||||||
}
|
|
||||||
*out = 0;
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
9
path.h
9
path.h
|
@ -57,13 +57,10 @@ bool path_can_get_cdpath(const wcstring &in);
|
||||||
bool path_get_cdpath_string(const wcstring &in, wcstring &out, const env_vars &vars);
|
bool path_get_cdpath_string(const wcstring &in, wcstring &out, const env_vars &vars);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Remove doulbe slashes and trailing slashes from a path,
|
Remove double slashes and trailing slashes from a path,
|
||||||
e.g. transform foo//bar/ into foo/bar.
|
e.g. transform foo//bar/ into foo/bar. The string is modified in-place.
|
||||||
|
|
||||||
The returned string is allocated using the specified halloc
|
|
||||||
context.
|
|
||||||
*/
|
*/
|
||||||
wchar_t *path_make_canonical( void *context, const wchar_t *path );
|
void path_make_canonical( wcstring &path );
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue