Do not buffer builtin output if avoidable

builtins output to stdout and stderr via io_streams_t. Prior to this fix, it
contained an output_stream_t which just wraps a buffer. So all builtin output
went to this buffer (except for eval).

Switch output_stream_t to become a new abstract class which can output to a
buffer, file descriptor, or nowhere. This allows for example `string` to stream
its output as it is produced, instead of buffering it.
This commit is contained in:
ridiculousfish
2020-07-29 16:03:29 -07:00
parent 68092c5d21
commit bcfc54fdaa
7 changed files with 174 additions and 51 deletions

View File

@@ -388,11 +388,14 @@ end_execution_reason_t parse_execution_context_t::run_function_statement(
return result;
}
trace_if_enabled(*parser, L"function", arguments);
io_streams_t streams(0); // no limit on the amount of output from builtin_function()
// no limit on the amount of output from builtin_function()
buffered_output_stream_t outs(0);
buffered_output_stream_t errs(0);
io_streams_t streams(outs, errs);
int err = builtin_function(*parser, streams, arguments, pstree, statement);
parser->set_last_statuses(statuses_t::just(err));
wcstring errtext = streams.err.contents();
wcstring errtext = errs.contents();
if (!errtext.empty()) {
return this->report_error(err, header, L"%ls", errtext.c_str());
}