Skip to content

Commit cec11e1

Browse files
committed
Pass commandvec by reference and small fixes
This changes to pass the vector of strings for the piped_process command by reference instead of by value. Also add some doxygen and static keyword
1 parent f60acac commit cec11e1

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/util/piped_process.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,13 @@
102102
# define BUFSIZE 2048
103103

104104
#ifdef _WIN32
105-
std::wstring process_windows_args(const std::vector<std::string> commandvec)
105+
/// This function prepares a single wide string for the windows command
106+
/// line.
107+
/// \param commandvec: A vector of strings that contain the command and
108+
/// arguments to the command.
109+
/// \returns A single wide string of the command appropriate for windows
110+
static std::wstring
111+
prepare_windows_command_line(const std::vector<std::string> &commandvec)
106112
{
107113
std::wstring result = widen(commandvec[0]);
108114
for(int i = 1; i < commandvec.size(); i++)
@@ -114,7 +120,7 @@ std::wstring process_windows_args(const std::vector<std::string> commandvec)
114120
}
115121
#endif
116122

117-
piped_processt::piped_processt(const std::vector<std::string> commandvec)
123+
piped_processt::piped_processt(const std::vector<std::string> &commandvec)
118124
{
119125
# ifdef _WIN32
120126
// Security attributes for pipe creation
@@ -204,7 +210,7 @@ piped_processt::piped_processt(const std::vector<std::string> commandvec)
204210
start_info.hStdOutput = child_std_OUT_Wr;
205211
start_info.hStdInput = child_std_IN_Rd;
206212
start_info.dwFlags |= STARTF_USESTDHANDLES;
207-
const std::wstring cmdline = process_windows_args(commandvec);
213+
const std::wstring cmdline = prepare_windows_command_line(commandvec);
208214
// Note that we do NOT free this since it becomes part of the child
209215
// and causes heap corruption in Windows if we free!
210216
const BOOL success = CreateProcessW(

src/util/piped_process.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class piped_processt
7878
/// Initiate a new subprocess with pipes supporting communication
7979
/// between the parent (this process) and the child.
8080
/// \param commandvec The command and arguments to create the process
81-
explicit piped_processt(const std::vector<std::string> commandvec);
81+
explicit piped_processt(const std::vector<std::string> &commandvec);
8282

8383
// Deleted due to declaring an explicit destructor and not wanting copy
8484
// constructors to be implemented.

0 commit comments

Comments
 (0)