diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2022-07-01 14:02:28 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-07-01 11:02:28 -0700 |
| commit | b0ea5ed4da709312910898fa03b4dafc7a27e358 (patch) | |
| tree | 70adea35a369d43bea79d71dcb2f8758772562aa | |
| parent | 65cd44d54cc76d78777cde5f8a02b485056249f3 (diff) | |
Fix for issue with redirecting stdout/err to a file (#2311)
| -rw-r--r-- | source/core/slang-std-writers.h | 16 | ||||
| -rw-r--r-- | source/core/slang-writer.cpp | 9 | ||||
| -rwxr-xr-x | source/slang/slang-compiler.h | 8 | ||||
| -rw-r--r-- | source/slang/slang.cpp | 10 |
4 files changed, 34 insertions, 9 deletions
diff --git a/source/core/slang-std-writers.h b/source/core/slang-std-writers.h index d193bfe0c..84447186a 100644 --- a/source/core/slang-std-writers.h +++ b/source/core/slang-std-writers.h @@ -15,6 +15,9 @@ public: ISlangWriter* getWriter(SlangWriterChannel chan) const { return m_writers[chan]; } void setWriter(SlangWriterChannel chan, ISlangWriter* writer) { m_writers[chan] = writer; } + /// Flush all the set writers + void flushWriters(); + /// Ctor StdWriters() {} @@ -36,6 +39,19 @@ protected: static StdWriters* s_singleton; }; +// -------------------------------------------------------------------------- +inline void StdWriters::flushWriters() +{ + for (Index i = 0; i < Count(SLANG_WRITER_CHANNEL_COUNT_OF); ++i) + { + auto writer = m_writers[i]; + if (writer) + { + writer->flush(); + } + } +} + } #endif diff --git a/source/core/slang-writer.cpp b/source/core/slang-writer.cpp index 849cb2da0..2b00b5853 100644 --- a/source/core/slang-writer.cpp +++ b/source/core/slang-writer.cpp @@ -127,9 +127,14 @@ SlangResult CallbackWriter::write(const char* chars, size_t numChars) FileWriter::~FileWriter() { - if ((m_flags & WriterFlag::IsUnowned) == 0) + if (m_file) { - fclose(m_file); + ::fflush(m_file); + + if ((m_flags & WriterFlag::IsUnowned) == 0) + { + ::fclose(m_file); + } } } diff --git a/source/slang/slang-compiler.h b/source/slang/slang-compiler.h index e7114fc2c..5ba121742 100755 --- a/source/slang/slang-compiler.h +++ b/source/slang/slang-compiler.h @@ -2656,6 +2656,8 @@ namespace Slang EndToEndCompileRequest( Linkage* linkage); + ~EndToEndCompileRequest(); + // What container format are we being asked to generate? // If it's set to a format, the container blob will be calculated during compile ContainerFormat m_containerFormat = ContainerFormat::None; @@ -2761,11 +2763,7 @@ namespace Slang { return m_specializedEntryPoints[index]; } - ~EndToEndCompileRequest() - { - m_linkage = nullptr; - m_frontEndReq = nullptr; - } + void generateOutput(); diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index 13ef0cd81..f2e6c5497 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -1440,8 +1440,14 @@ void TranslationUnitRequest::addSourceFile(SourceFile* sourceFile) } } +EndToEndCompileRequest::~EndToEndCompileRequest() +{ + // Flush any writers associated with the request + m_writers->flushWriters(); -// + m_linkage.setNull(); + m_frontEndReq.setNull(); +} static ISlangWriter* _getDefaultWriter(WriterChannel chan) { @@ -1467,7 +1473,7 @@ void EndToEndCompileRequest::setWriter(WriterChannel chan, ISlangWriter* writer) // If the user passed in null, we will use the default writer on that channel m_writers->setWriter(SlangWriterChannel(chan), writer ? writer : _getDefaultWriter(chan)); - // For diagnostic output, if the user passes in nullptr, we set on mSink.writer as that enables buffering on DiagnosticSink + // For diagnostic output, if the user passes in nullptr, we set on m_sink.writer as that enables buffering on DiagnosticSink if (chan == WriterChannel::Diagnostic) { m_sink.writer = writer; |
