mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 12:53:13 +00:00
Migrate to std::vector in event class
This commit is contained in:
parent
22a8e57a57
commit
451399b344
5 changed files with 56 additions and 71 deletions
1
common.h
1
common.h
|
@ -21,6 +21,7 @@
|
|||
|
||||
/* Common string type */
|
||||
typedef std::wstring wcstring;
|
||||
typedef std::vector<wcstring> wcstring_list_t;
|
||||
|
||||
/**
|
||||
Maximum number of bytes used by a single utf-8 character
|
||||
|
|
33
env.cpp
33
env.cpp
|
@ -411,12 +411,13 @@ static void universal_callback( int type,
|
|||
ev.param1.variable=name;
|
||||
ev.function_name=0;
|
||||
|
||||
al_init( &ev.arguments );
|
||||
al_push( &ev.arguments, L"VARIABLE" );
|
||||
al_push( &ev.arguments, str );
|
||||
al_push( &ev.arguments, name );
|
||||
ev.arguments = new wcstring_list_t();
|
||||
ev.arguments->push_back(L"VARIABLE");
|
||||
ev.arguments->push_back(str);
|
||||
ev.arguments->push_back(name);
|
||||
event_fire( &ev );
|
||||
al_destroy( &ev.arguments );
|
||||
delete ev.arguments;
|
||||
ev.arguments = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1005,15 +1006,16 @@ int env_set( const wchar_t *key,
|
|||
ev.param1.variable = key;
|
||||
ev.function_name = 0;
|
||||
|
||||
al_init( &ev.arguments );
|
||||
al_push( &ev.arguments, L"VARIABLE" );
|
||||
al_push( &ev.arguments, L"SET" );
|
||||
al_push( &ev.arguments, key );
|
||||
ev.arguments = new wcstring_list_t;
|
||||
ev.arguments->push_back(L"VARIABLE");
|
||||
ev.arguments->push_back(L"SET");
|
||||
ev.arguments->push_back(key);
|
||||
|
||||
// debug( 1, L"env_set: fire events on variable %ls", key );
|
||||
event_fire( &ev );
|
||||
// debug( 1, L"env_set: return from event firing" );
|
||||
al_destroy( &ev.arguments );
|
||||
delete ev.arguments;
|
||||
ev.arguments = NULL;
|
||||
}
|
||||
|
||||
if( is_locale( key ) )
|
||||
|
@ -1110,14 +1112,15 @@ int env_remove( const wchar_t *key, int var_mode )
|
|||
ev.param1.variable=key;
|
||||
ev.function_name=0;
|
||||
|
||||
al_init( &ev.arguments );
|
||||
al_push( &ev.arguments, L"VARIABLE" );
|
||||
al_push( &ev.arguments, L"ERASE" );
|
||||
al_push( &ev.arguments, key );
|
||||
ev.arguments = new wcstring_list_t;
|
||||
ev.arguments->push_back(L"VARIABLE");
|
||||
ev.arguments->push_back(L"ERASE");
|
||||
ev.arguments->push_back(key);
|
||||
|
||||
event_fire( &ev );
|
||||
|
||||
al_destroy( &ev.arguments );
|
||||
delete ev.arguments;
|
||||
ev.arguments = NULL;
|
||||
erased = 1;
|
||||
}
|
||||
}
|
||||
|
|
61
event.cpp
61
event.cpp
|
@ -157,15 +157,10 @@ static event_t *event_copy( event_t *event, int copy_arguments )
|
|||
else if( e->type == EVENT_GENERIC )
|
||||
e->param1.param = wcsdup( e->param1.param );
|
||||
|
||||
al_init( &e->arguments );
|
||||
if( copy_arguments )
|
||||
e->arguments = new wcstring_list_t;
|
||||
if( copy_arguments && event->arguments )
|
||||
{
|
||||
int i;
|
||||
for( i=0; i<al_get_count( &event->arguments ); i++ )
|
||||
{
|
||||
al_push( &e->arguments, wcsdup( (wchar_t *)al_get( &event->arguments, i ) ) );
|
||||
}
|
||||
|
||||
*(e->arguments) = *(event->arguments);
|
||||
}
|
||||
|
||||
return e;
|
||||
|
@ -389,8 +384,7 @@ static int event_is_killed( event_t *e )
|
|||
*/
|
||||
static void event_fire_internal( event_t *event )
|
||||
{
|
||||
int i, j;
|
||||
string_buffer_t *b=0;
|
||||
size_t i, j;
|
||||
event_list_t fire;
|
||||
|
||||
/*
|
||||
|
@ -445,19 +439,16 @@ static void event_fire_internal( event_t *event )
|
|||
/*
|
||||
Fire event
|
||||
*/
|
||||
if( !b )
|
||||
b = sb_new();
|
||||
else
|
||||
sb_clear( b );
|
||||
wcstring buffer = criterion->function_name;
|
||||
|
||||
sb_append( b, criterion->function_name );
|
||||
|
||||
for( j=0; j<al_get_count(&event->arguments); j++ )
|
||||
if (event->arguments)
|
||||
{
|
||||
wchar_t *arg_esc = escape( (wchar_t *)al_get( &event->arguments, j), 1 );
|
||||
sb_append( b, L" " );
|
||||
sb_append( b, arg_esc );
|
||||
free( arg_esc );
|
||||
for( j=0; j< event->arguments->size(); j++ )
|
||||
{
|
||||
wcstring arg_esc = escape_string( event->arguments->at(j), 1 );
|
||||
buffer += L" ";
|
||||
buffer += arg_esc;
|
||||
}
|
||||
}
|
||||
|
||||
// debug( 1, L"Event handler fires command '%ls'", (wchar_t *)b->buff );
|
||||
|
@ -470,18 +461,12 @@ static void event_fire_internal( event_t *event )
|
|||
prev_status = proc_get_last_status();
|
||||
parser_push_block( EVENT );
|
||||
current_block->param1.event = event;
|
||||
eval( (wchar_t *)b->buff, 0, TOP );
|
||||
eval( buffer.c_str(), 0, TOP );
|
||||
parser_pop_block();
|
||||
proc_pop_interactive();
|
||||
proc_set_last_status( prev_status );
|
||||
}
|
||||
|
||||
if( b )
|
||||
{
|
||||
sb_destroy( b );
|
||||
free( b );
|
||||
}
|
||||
|
||||
/*
|
||||
Free killed events
|
||||
*/
|
||||
|
@ -495,7 +480,7 @@ static void event_fire_internal( event_t *event )
|
|||
static void event_fire_delayed()
|
||||
{
|
||||
|
||||
int i;
|
||||
size_t i;
|
||||
|
||||
/*
|
||||
If is_event is one, we are running the event-handler non-recursively.
|
||||
|
@ -528,7 +513,7 @@ static void event_fire_delayed()
|
|||
{
|
||||
signal_list_t *lst;
|
||||
event_t e;
|
||||
al_init( &e.arguments );
|
||||
e.arguments = new wcstring_list_t(1); //one element
|
||||
|
||||
/*
|
||||
Switch signal lists
|
||||
|
@ -553,10 +538,10 @@ static void event_fire_delayed()
|
|||
/*
|
||||
Send all signals in our private list
|
||||
*/
|
||||
for( i=0; i<lst->count; i++ )
|
||||
for( i=0; i<(size_t)lst->count; i++ )
|
||||
{
|
||||
e.param1.signal = lst->signal[i];
|
||||
al_set( &e.arguments, 0, sig2wcs( e.param1.signal ) );
|
||||
e.arguments->at(0) = sig2wcs( e.param1.signal );
|
||||
if( event_is_blocked( &e ) )
|
||||
{
|
||||
blocked.push_back(event_copy(&e, 1));
|
||||
|
@ -567,7 +552,7 @@ static void event_fire_delayed()
|
|||
}
|
||||
}
|
||||
|
||||
al_destroy( &e.arguments );
|
||||
delete e.arguments;
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -635,8 +620,8 @@ void event_free( event_t *e )
|
|||
/*
|
||||
When apropriate, we clear the argument vector
|
||||
*/
|
||||
al_foreach( &e->arguments, &free );
|
||||
al_destroy( &e->arguments );
|
||||
if (e->arguments) delete e->arguments;
|
||||
e->arguments = NULL;
|
||||
|
||||
free( (void *)e->function_name );
|
||||
if( e->type == EVENT_VARIABLE )
|
||||
|
@ -663,15 +648,17 @@ void event_fire_generic_internal(const wchar_t *name, ...)
|
|||
ev.param1.param = name;
|
||||
ev.function_name=0;
|
||||
|
||||
al_init( &ev.arguments );
|
||||
ev.arguments = new wcstring_list_t;
|
||||
va_start( va, name );
|
||||
while( (arg=va_arg(va, wchar_t *) )!= 0 )
|
||||
{
|
||||
al_push( &ev.arguments, arg );
|
||||
ev.arguments->push_back(arg);
|
||||
}
|
||||
va_end( va );
|
||||
|
||||
event_fire( &ev );
|
||||
delete ev.arguments;
|
||||
ev.arguments = NULL;
|
||||
}
|
||||
|
||||
|
||||
|
|
3
event.h
3
event.h
|
@ -12,6 +12,7 @@
|
|||
#ifndef FISH_EVENT_H
|
||||
#define FISH_EVENT_H
|
||||
|
||||
#include "common.h"
|
||||
|
||||
/**
|
||||
The signal number that is used to match any signal
|
||||
|
@ -91,7 +92,7 @@ typedef struct
|
|||
event_fire. In all other situations, the value of this variable
|
||||
is ignored.
|
||||
*/
|
||||
array_list_t arguments;
|
||||
wcstring_list_t *arguments;
|
||||
}
|
||||
event_t;
|
||||
|
||||
|
|
21
proc.cpp
21
proc.cpp
|
@ -132,7 +132,7 @@ void proc_init()
|
|||
{
|
||||
interactive_stack = al_halloc( global_context );
|
||||
proc_push_interactive( 0 );
|
||||
al_init( &event.arguments );
|
||||
event.arguments = new wcstring_list_t;
|
||||
sb_init( &event_pid );
|
||||
sb_init( &event_status );
|
||||
}
|
||||
|
@ -177,7 +177,8 @@ void job_free( job_t * j )
|
|||
|
||||
void proc_destroy()
|
||||
{
|
||||
al_destroy( &event.arguments );
|
||||
delete event.arguments;
|
||||
event.arguments = NULL;
|
||||
sb_destroy( &event_pid );
|
||||
sb_destroy( &event_status );
|
||||
while( first_job )
|
||||
|
@ -535,19 +536,11 @@ void proc_fire_event( const wchar_t *msg, int type, pid_t pid, int status )
|
|||
event.type=type;
|
||||
event.param1.pid = pid;
|
||||
|
||||
al_push( &event.arguments, msg );
|
||||
|
||||
sb_printf( &event_pid, L"%d", pid );
|
||||
al_push( &event.arguments, event_pid.buff );
|
||||
|
||||
sb_printf( &event_status, L"%d", status );
|
||||
al_push( &event.arguments, event_status.buff );
|
||||
|
||||
event.arguments->push_back(msg);
|
||||
event.arguments->push_back(format_val<int>(pid));
|
||||
event.arguments->push_back(format_val<int>(status));
|
||||
event_fire( &event );
|
||||
|
||||
al_truncate( &event.arguments, 0 );
|
||||
sb_clear( &event_pid );
|
||||
sb_clear( &event_status );
|
||||
event.arguments->resize(0);
|
||||
}
|
||||
|
||||
int job_reap( int interactive )
|
||||
|
|
Loading…
Reference in a new issue