mirror of
https://github.com/fish-shell/fish-shell
synced 2024-11-10 23:24:39 +00:00
Some initial work on removing buffer_t from io_data_t
This commit is contained in:
parent
baa813c46f
commit
27f374a38b
5 changed files with 26 additions and 29 deletions
18
exec.cpp
18
exec.cpp
|
@ -82,7 +82,7 @@
|
|||
static std::vector<bool> open_fds;
|
||||
|
||||
// Called in a forked child
|
||||
static void exec_write_and_exit( int fd, char *buff, size_t count, int status )
|
||||
static void exec_write_and_exit( int fd, const char *buff, size_t count, int status )
|
||||
{
|
||||
if( write_loop(fd, buff, count) == -1 )
|
||||
{
|
||||
|
@ -1039,7 +1039,7 @@ void exec( parser_t &parser, job_t *j )
|
|||
|
||||
io_buffer_read( io_buffer );
|
||||
|
||||
if( io_buffer->param2.out_buffer->used != 0 )
|
||||
if( io_buffer->out_buffer->used != 0 )
|
||||
{
|
||||
/* We don't have to drain threads here because our child process is simple */
|
||||
pid = execute_fork(false);
|
||||
|
@ -1053,8 +1053,8 @@ void exec( parser_t &parser, job_t *j )
|
|||
setup_child_process( j, p );
|
||||
|
||||
exec_write_and_exit(io_buffer->fd,
|
||||
io_buffer->param2.out_buffer->buff,
|
||||
io_buffer->param2.out_buffer->used,
|
||||
io_buffer->out_buffer->buff,
|
||||
io_buffer->out_buffer->used,
|
||||
status);
|
||||
}
|
||||
else
|
||||
|
@ -1102,8 +1102,8 @@ void exec( parser_t &parser, job_t *j )
|
|||
setup_child_process( j, p );
|
||||
|
||||
exec_write_and_exit( 1,
|
||||
input_redirect->param2.out_buffer->buff,
|
||||
input_redirect->param2.out_buffer->used,
|
||||
input_redirect->out_buffer->buff,
|
||||
input_redirect->out_buffer->used,
|
||||
0);
|
||||
}
|
||||
else
|
||||
|
@ -1157,7 +1157,7 @@ void exec( parser_t &parser, job_t *j )
|
|||
( buffer_stdout ) )
|
||||
{
|
||||
std::string res = wcs2string( get_stdout_buffer() );
|
||||
b_append( io->param2.out_buffer, res.c_str(), res.size() );
|
||||
b_append( io->out_buffer, res.c_str(), res.size() );
|
||||
skip_fork = 1;
|
||||
}
|
||||
|
||||
|
@ -1378,9 +1378,9 @@ static int exec_subshell_internal( const wcstring &cmd, wcstring_list_t *lst )
|
|||
|
||||
is_subshell = prev_subshell;
|
||||
|
||||
b_append( io_buffer->param2.out_buffer, &z, 1 );
|
||||
b_append( io_buffer->out_buffer, &z, 1 );
|
||||
|
||||
begin=end=io_buffer->param2.out_buffer->buff;
|
||||
begin=end=io_buffer->out_buffer->buff;
|
||||
|
||||
if( lst )
|
||||
{
|
||||
|
|
20
io.cpp
20
io.cpp
|
@ -91,7 +91,7 @@ void io_buffer_read( io_data_t *d )
|
|||
}
|
||||
else
|
||||
{
|
||||
b_append( d->param2.out_buffer, b, l );
|
||||
b_append( d->out_buffer, b, l );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -100,21 +100,20 @@ void io_buffer_read( io_data_t *d )
|
|||
|
||||
io_data_t *io_buffer_create( int is_input )
|
||||
{
|
||||
io_data_t *buffer_redirect = new io_data_t();
|
||||
std::auto_ptr<io_data_t> buffer_redirect(new io_data_t());
|
||||
|
||||
buffer_redirect->io_mode=IO_BUFFER;
|
||||
buffer_redirect->next=0;
|
||||
buffer_redirect->param2.out_buffer= (buffer_t *)malloc( sizeof(buffer_t));
|
||||
buffer_redirect->out_buffer= (buffer_t *)malloc( sizeof(buffer_t));
|
||||
buffer_redirect->is_input = is_input;
|
||||
b_init( buffer_redirect->param2.out_buffer );
|
||||
b_init( buffer_redirect->out_buffer );
|
||||
buffer_redirect->fd=is_input?0:1;
|
||||
|
||||
if( exec_pipe( buffer_redirect->param1.pipe_fd ) == -1 )
|
||||
{
|
||||
debug( 1, PIPE_ERROR );
|
||||
wperror (L"pipe");
|
||||
free( buffer_redirect->param2.out_buffer );
|
||||
free( buffer_redirect );
|
||||
free( buffer_redirect->out_buffer );
|
||||
return 0;
|
||||
}
|
||||
else if( fcntl( buffer_redirect->param1.pipe_fd[0],
|
||||
|
@ -123,11 +122,10 @@ io_data_t *io_buffer_create( int is_input )
|
|||
{
|
||||
debug( 1, PIPE_ERROR );
|
||||
wperror( L"fcntl" );
|
||||
free( buffer_redirect->param2.out_buffer );
|
||||
free( buffer_redirect );
|
||||
free( buffer_redirect->out_buffer );
|
||||
return 0;
|
||||
}
|
||||
return buffer_redirect;
|
||||
return buffer_redirect.release();
|
||||
}
|
||||
|
||||
void io_buffer_destroy( io_data_t *io_buffer )
|
||||
|
@ -149,9 +147,9 @@ void io_buffer_destroy( io_data_t *io_buffer )
|
|||
calling exec_read_io_buffer on the buffer
|
||||
*/
|
||||
|
||||
b_destroy( io_buffer->param2.out_buffer );
|
||||
b_destroy( io_buffer->out_buffer );
|
||||
|
||||
free( io_buffer->param2.out_buffer );
|
||||
free( io_buffer->out_buffer );
|
||||
delete io_buffer;
|
||||
}
|
||||
|
||||
|
|
9
io.h
9
io.h
|
@ -38,15 +38,14 @@ struct io_data_t
|
|||
{
|
||||
/** file creation flags to send to open for IO_FILE */
|
||||
int flags;
|
||||
/** buffer to save output in for IO_BUFFER */
|
||||
buffer_t *out_buffer;
|
||||
/** Whether to close old_fd for IO_FD */
|
||||
int close_old;
|
||||
} param2;
|
||||
|
||||
/**
|
||||
Set to true if this is an input io redirection
|
||||
*/
|
||||
/** buffer to save output in for IO_BUFFER */
|
||||
buffer_t *out_buffer;
|
||||
|
||||
/** Set to true if this is an input io redirection */
|
||||
int is_input;
|
||||
|
||||
/** Pointer to the next IO redirection */
|
||||
|
|
2
proc.cpp
2
proc.cpp
|
@ -881,7 +881,7 @@ static void read_try( job_t *j )
|
|||
}
|
||||
else
|
||||
{
|
||||
b_append( buff->param2.out_buffer, b, l );
|
||||
b_append( buff->out_buffer, b, l );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1174,7 +1174,7 @@ static void run_pager( wchar_t *prefix, int is_quoted, const std::vector<complet
|
|||
free( escaped_separator );
|
||||
|
||||
foo = wcs2str(msg.c_str());
|
||||
b_append( in->param2.out_buffer, foo, strlen(foo) );
|
||||
b_append( in->out_buffer, foo, strlen(foo) );
|
||||
free( foo );
|
||||
|
||||
term_donate();
|
||||
|
@ -1190,10 +1190,10 @@ static void run_pager( wchar_t *prefix, int is_quoted, const std::vector<complet
|
|||
io_buffer_read( out );
|
||||
|
||||
int nil=0;
|
||||
b_append( out->param2.out_buffer, &nil, 1 );
|
||||
b_append( out->out_buffer, &nil, 1 );
|
||||
|
||||
wchar_t *tmp;
|
||||
wchar_t *str = str2wcs((char *)out->param2.out_buffer->buff);
|
||||
wchar_t *str = str2wcs((char *)out->out_buffer->buff);
|
||||
|
||||
if( str )
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue