[cmake-developers] [PATCH v4 4/4] For Windows encode process output to internally used encoding

Dāvis Mosāns davispuh at gmail.com
Thu Jul 21 13:36:27 EDT 2016


2016-07-18 17:04 GMT+03:00 Brad King <brad.king at kitware.com>:
> On 07/07/2016 05:54 PM, Dāvis Mosāns wrote:
>> Typically Windows applications (eg. MSVC compiler) use current console's
>> codepage for output to pipes so we need to encode that to internally used
>> encoding (KWSYS_ENCODING_DEFAULT_CODEPAGE).
> [snip]
>>    while ((p = cmsysProcess_WaitForData(cp, &data, &length, CM_NULLPTR), p)) {
>> +    cmsysProcess_DecodeTextOutput(cp, &data, &length);
> [snip]
>>    while ((p = cmsysProcess_WaitForData(cp, &data, &length, CM_NULLPTR), p)) {
>> +    cmsysProcess_DecodeTextOutput(cp, &data, &length);
>
> Unfortunately I don't think that pattern will work reliably because
> a multi-byte character could be split across a buffering boundary
> and therefore not decoded correctly.  We may need the consuming
> contexts to collect the whole output before converting.
>

That's true, but only for MBCS code pages, it will work fine for SBCS and DBCS
(if buffer size is even). I think this issue would appear very rarely.
Anyway I improved this in places where it was easy, but in some places it's
more complicated...

For example

   while ((p = cmsysProcess_WaitForData(cp, &data, &length, CM_NULLPTR), p)) {
     // Put the output in the right place.
     if (p == cmsysProcess_Pipe_STDOUT && !output_quiet) {
       if (output_variable.empty()) {
         cmSystemTools::Stdout(data, length);

Here we output buffer immediately.

 while ((out || err) &&
          (p = cmsysProcess_WaitForData(cp, &data, &length, CM_NULLPTR), p)) {
     if (out && p == cmsysProcess_Pipe_STDOUT) {
       if (!out->Process(data, length)) {

and also here we process buffer immediately.


More information about the cmake-developers mailing list