Skip to content

Commit a31b5a1

Browse files
authored
Apply fix
1 parent ac9e233 commit a31b5a1

File tree

2 files changed

+8
-26
lines changed

2 files changed

+8
-26
lines changed

lib/Interpreter/Compatibility.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
#include "clang/Basic/Version.h"
1111
#include "clang/Config/config.h"
1212

13+
#ifdef _WIN32
14+
#define dup _dup
15+
#define dup2 _dup2
16+
#define close _close
17+
#endif
18+
1319
#if CLANG_VERSION_MAJOR < 19
1420
#define Template_Deduction_Result Sema::TemplateDeductionResult
1521
#define Template_Deduction_Result_Success \

lib/Interpreter/CppInterOp.cpp

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3290,23 +3290,9 @@ namespace Cpp {
32903290
}(),
32913291
std::fclose),
32923292
m_FD(FD) {
3293-
if (!m_TempFile) {
3294-
perror("StreamCaptureInfo: Unable to create temp file");
3295-
return;
3296-
}
3297-
3298-
m_DupFD = _dup(FD);
3299-
3300-
// Flush now or can drop the buffer when dup2 is called with Fd later.
3301-
// This seems only neccessary when piping stdout or stderr, but do it
3302-
// for ttys to avoid over complicated code for minimal benefit.
3303-
::fflush(FD == STDOUT_FILENO ? stdout : stderr);
3304-
if (_dup2(_fileno(m_TempFile.get()), FD) < 0)
3305-
perror("StreamCaptureInfo:");
3306-
}
33073293
#else
33083294
StreamCaptureInfo(int FD) : m_TempFile(tmpfile(), std::fclose), m_FD(FD) {
3309-
3295+
#endif
33103296
if (!m_TempFile) {
33113297
perror("StreamCaptureInfo: Unable to create temp file");
33123298
return;
@@ -3318,11 +3304,9 @@ namespace Cpp {
33183304
// This seems only neccessary when piping stdout or stderr, but do it
33193305
// for ttys to avoid over complicated code for minimal benefit.
33203306
::fflush(FD == STDOUT_FILENO ? stdout : stderr);
3321-
if (dup2(fileno(m_TempFile.get()), FD) < 0)
3307+
if (dup2(_fileno(m_TempFile.get()), FD) < 0)
33223308
perror("StreamCaptureInfo:");
33233309
}
3324-
#endif
3325-
33263310
StreamCaptureInfo(const StreamCaptureInfo&) = delete;
33273311
StreamCaptureInfo& operator=(const StreamCaptureInfo&) = delete;
33283312
StreamCaptureInfo(StreamCaptureInfo&&) = delete;
@@ -3336,11 +3320,7 @@ namespace Cpp {
33363320
assert(m_DupFD != -1 && "Multiple calls to GetCapturedString");
33373321

33383322
fflush(nullptr);
3339-
#if defined(_WIN32)
3340-
if (_dup2(m_DupFD, m_FD) < 0)
3341-
#else
33423323
if (dup2(m_DupFD, m_FD) < 0)
3343-
#endif
33443324
perror("StreamCaptureInfo:");
33453325
// Go to the end of the file.
33463326
if (fseek(m_TempFile.get(), 0L, SEEK_END) != 0)
@@ -3367,11 +3347,7 @@ namespace Cpp {
33673347
content[newLen++] = '\0'; // Just to be safe.
33683348

33693349
std::string result = content.get();
3370-
#if defined(_WIN32)
3371-
_close(m_DupFD);
3372-
#else
33733350
close(m_DupFD);
3374-
#endif
33753351
m_DupFD = -1;
33763352
return result;
33773353
}

0 commit comments

Comments
 (0)