Просмотр исходного кода

Merge topic 'ctest-libuv-output-decode'

a6e9b9c9 CTest: Fix process output read error cases
c10119df CTest: Fix decoding of MBCS character split by buffering

Acked-by: Kitware Robot <[email protected]>
Merge-request: !1667
Brad King 8 лет назад
Родитель
Сommit
84e2a7e58a
2 измененных файлов с 15 добавлено и 9 удалено
  1. 12 8
      Source/CTest/cmProcess.cxx
  2. 3 1
      Source/CTest/cmProcess.h

+ 12 - 8
Source/CTest/cmProcess.cxx

@@ -5,19 +5,19 @@
 #include "cmCTest.h"
 #include "cmCTestRunTest.h"
 #include "cmCTestTestHandler.h"
-#include "cmProcessOutput.h"
 #include "cmsys/Process.h"
 
 #include <algorithm>
 #include <fcntl.h>
 #include <iostream>
 #include <signal.h>
-#include <stdint.h>
 #include <string>
 #if !defined(_WIN32)
 #include <unistd.h>
 #endif
 
+#define CM_PROCESS_BUF_SIZE 65536
+
 #if defined(_WIN32) && !defined(__CYGWIN__)
 #include <io.h>
 
@@ -60,6 +60,7 @@ static int cmProcessGetPipes(int* fds)
 
 cmProcess::cmProcess(cmCTestRunTest& runner)
   : Runner(runner)
+  , Conv(cmProcessOutput::UTF8, CM_PROCESS_BUF_SIZE)
 {
   this->Timeout = std::chrono::duration<double>::zero();
   this->TotalTime = std::chrono::duration<double>::zero();
@@ -232,9 +233,7 @@ void cmProcess::OnRead(ssize_t nread, const uv_buf_t* buf)
   std::string line;
   if (nread > 0) {
     std::string strdata;
-    cmProcessOutput processOutput(cmProcessOutput::UTF8,
-                                  static_cast<unsigned int>(buf->len));
-    processOutput.DecodeText(buf->base, static_cast<size_t>(nread), strdata);
+    this->Conv.DecodeText(buf->base, static_cast<size_t>(nread), strdata);
     this->Output.insert(this->Output.end(), strdata.begin(), strdata.end());
 
     while (this->Output.GetLine(line)) {
@@ -245,6 +244,10 @@ void cmProcess::OnRead(ssize_t nread, const uv_buf_t* buf)
     return;
   }
 
+  if (nread == 0) {
+    return;
+  }
+
   // The process will provide no more data.
   if (nread != UV_EOF) {
     auto error = static_cast<int>(nread);
@@ -258,6 +261,7 @@ void cmProcess::OnRead(ssize_t nread, const uv_buf_t* buf)
   }
 
   this->ReadHandleClosed = true;
+  this->PipeReader.reset();
   if (this->ProcessHandleClosed) {
     uv_timer_stop(this->Timer);
     this->Runner.FinalizeTest();
@@ -271,10 +275,10 @@ void cmProcess::OnAllocateCB(uv_handle_t* handle, size_t suggested_size,
   self->OnAllocate(suggested_size, buf);
 }
 
-void cmProcess::OnAllocate(size_t suggested_size, uv_buf_t* buf)
+void cmProcess::OnAllocate(size_t /*suggested_size*/, uv_buf_t* buf)
 {
-  if (this->Buf.size() < suggested_size) {
-    this->Buf.resize(suggested_size);
+  if (this->Buf.size() != CM_PROCESS_BUF_SIZE) {
+    this->Buf.resize(CM_PROCESS_BUF_SIZE);
   }
 
   *buf =

+ 3 - 1
Source/CTest/cmProcess.h

@@ -5,13 +5,14 @@
 
 #include "cmConfigure.h" // IWYU pragma: keep
 
+#include "cmProcessOutput.h"
 #include "cmUVHandlePtr.h"
 #include "cm_uv.h"
 
 #include <chrono>
 #include <stddef.h>
+#include <stdint.h>
 #include <string>
-#include <sys/types.h>
 #include <vector>
 
 class cmCTestRunTest;
@@ -80,6 +81,7 @@ private:
   std::vector<char> Buf;
 
   cmCTestRunTest& Runner;
+  cmProcessOutput Conv;
   int Signal = 0;
   cmProcess::State ProcessState = cmProcess::State::Starting;