Skip to content

Commit 59feb53

Browse files
nibochjasnell
authored andcommittedOct 17, 2018
src: changed stdio_pipes_ to std::vector
PR-URL: #23615 Reviewed-By: Sam Ruby <rubys@intertwingly.net> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Refael Ackermann <refack@gmail.com>
1 parent 934eb7e commit 59feb53

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed
 

‎src/spawn_sync.cc

+12-14
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,6 @@ SyncProcessRunner::SyncProcessRunner(Environment* env)
390390

391391
stdio_count_(0),
392392
uv_stdio_containers_(nullptr),
393-
stdio_pipes_(nullptr),
394393
stdio_pipes_initialized_(false),
395394

396395
uv_process_options_(),
@@ -421,7 +420,7 @@ SyncProcessRunner::SyncProcessRunner(Environment* env)
421420
SyncProcessRunner::~SyncProcessRunner() {
422421
CHECK_EQ(lifecycle_, kHandlesClosed);
423422

424-
stdio_pipes_.reset();
423+
stdio_pipes_.clear();
425424
delete[] file_buffer_;
426425
delete[] args_buffer_;
427426
delete[] cwd_buffer_;
@@ -500,10 +499,9 @@ Maybe<bool> SyncProcessRunner::TryInitializeAndRunLoop(Local<Value> options) {
500499
}
501500
uv_process_.data = this;
502501

503-
for (uint32_t i = 0; i < stdio_count_; i++) {
504-
SyncProcessStdioPipe* h = stdio_pipes_[i].get();
505-
if (h != nullptr) {
506-
r = h->Start();
502+
for (const auto& pipe : stdio_pipes_) {
503+
if (pipe != nullptr) {
504+
r = pipe->Start();
507505
if (r < 0) {
508506
SetPipeError(r);
509507
return Just(false);
@@ -563,12 +561,12 @@ void SyncProcessRunner::CloseStdioPipes() {
563561
CHECK_LT(lifecycle_, kHandlesClosed);
564562

565563
if (stdio_pipes_initialized_) {
566-
CHECK(stdio_pipes_);
564+
CHECK(!stdio_pipes_.empty());
567565
CHECK_NOT_NULL(uv_loop_);
568566

569-
for (uint32_t i = 0; i < stdio_count_; i++) {
570-
if (stdio_pipes_[i])
571-
stdio_pipes_[i]->Close();
567+
for (const auto& pipe : stdio_pipes_) {
568+
if (pipe)
569+
pipe->Close();
572570
}
573571

574572
stdio_pipes_initialized_ = false;
@@ -723,13 +721,13 @@ Local<Object> SyncProcessRunner::BuildResultObject() {
723721

724722
Local<Array> SyncProcessRunner::BuildOutputArray() {
725723
CHECK_GE(lifecycle_, kInitialized);
726-
CHECK(stdio_pipes_);
724+
CHECK(!stdio_pipes_.empty());
727725

728726
EscapableHandleScope scope(env()->isolate());
729727
Local<Context> context = env()->context();
730728
Local<Array> js_output = Array::New(env()->isolate(), stdio_count_);
731729

732-
for (uint32_t i = 0; i < stdio_count_; i++) {
730+
for (uint32_t i = 0; i < stdio_pipes_.size(); i++) {
733731
SyncProcessStdioPipe* h = stdio_pipes_[i].get();
734732
if (h != nullptr && h->writable())
735733
js_output->Set(context, i, h->GetOutputAsBuffer(env())).FromJust();
@@ -857,8 +855,8 @@ int SyncProcessRunner::ParseStdioOptions(Local<Value> js_value) {
857855
stdio_count_ = js_stdio_options->Length();
858856
uv_stdio_containers_ = new uv_stdio_container_t[stdio_count_];
859857

860-
stdio_pipes_.reset(
861-
new std::unique_ptr<SyncProcessStdioPipe>[stdio_count_]());
858+
stdio_pipes_.clear();
859+
stdio_pipes_.resize(stdio_count_);
862860
stdio_pipes_initialized_ = true;
863861

864862
for (uint32_t i = 0; i < stdio_count_; i++) {

‎src/spawn_sync.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ class SyncProcessRunner {
203203

204204
uint32_t stdio_count_;
205205
uv_stdio_container_t* uv_stdio_containers_;
206-
std::unique_ptr<std::unique_ptr<SyncProcessStdioPipe>[]> stdio_pipes_;
206+
std::vector<std::unique_ptr<SyncProcessStdioPipe>> stdio_pipes_;
207207
bool stdio_pipes_initialized_;
208208

209209
uv_process_options_t uv_process_options_;

0 commit comments

Comments
 (0)