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