From 9275d965a6952d44035fd0502ee0d3991352c460 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 26 Aug 2024 21:00:08 +1000 Subject: Do not gather full input data in a single string when piping Refactor ShellManager and pipe to feed lines from the buffer directly, this should reduce memory use when piping big chunks of buffers. The pipe output is still provided as a single big buffer. --- src/shell_manager.hh | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src/shell_manager.hh') diff --git a/src/shell_manager.hh b/src/shell_manager.hh index f6ef38a4..3dc62e0a 100644 --- a/src/shell_manager.hh +++ b/src/shell_manager.hh @@ -58,10 +58,20 @@ public: friend constexpr bool with_bit_ops(Meta::Type) { return true; } std::pair eval(StringView cmdline, const Context& context, - StringView input = {}, + FunctionRef stdin_generator, Flags flags = Flags::WaitForStdout, const ShellContext& shell_context = {}); + std::pair eval(StringView cmdline, const Context& context, + StringView stdin, + Flags flags = Flags::WaitForStdout, + const ShellContext& shell_context = {}) + { + return eval(cmdline, context, + [stdin]() mutable { return std::exchange(stdin, StringView{}); }, + flags, shell_context); + } + Shell spawn(StringView cmdline, const Context& context, bool open_stdin, -- cgit v1.2.3 From b4b3ddae0d93fbd652d1440f87541b81315838aa Mon Sep 17 00:00:00 2001 From: Chris Webb Date: Tue, 17 Sep 2024 13:35:08 +0100 Subject: Avoid stdin as a function parameter name 9275d96 introduces a use of stdin as a function parameter name, but POSIX allows stdin to be a macro, which will conflict with this. This breaks the build on musl systems. Rename in the same way as the previous fix for this in c7d887d. --- src/shell_manager.hh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/shell_manager.hh') diff --git a/src/shell_manager.hh b/src/shell_manager.hh index 3dc62e0a..5b42d644 100644 --- a/src/shell_manager.hh +++ b/src/shell_manager.hh @@ -63,12 +63,12 @@ public: const ShellContext& shell_context = {}); std::pair eval(StringView cmdline, const Context& context, - StringView stdin, + StringView in, Flags flags = Flags::WaitForStdout, const ShellContext& shell_context = {}) { return eval(cmdline, context, - [stdin]() mutable { return std::exchange(stdin, StringView{}); }, + [in]() mutable { return std::exchange(in, StringView{}); }, flags, shell_context); } -- cgit v1.2.3