summaryrefslogtreecommitdiffstats
path: root/source/core/slang-std-writers.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2019-01-21 15:33:59 -0500
committerTim Foley <tfoleyNV@users.noreply.github.com>2019-01-21 12:33:59 -0800
commit0a3ef7b4ae02983ea3f986ba8211e7c6af9d254b (patch)
tree86c84c7b20be86827c047cd82918f7f47537a338 /source/core/slang-std-writers.cpp
parentc55b462bf993dcd65ec17ffeeab97ac138e6d206 (diff)
Path simplification/hash mode, plus bug fixes (#788)
* * Fix memory bug around expanding va_args - needed buffer to have space for terminating 0 * Fix problem with FileWriter defaults being globals, as memory they allocate, will only be freed after return from main - work around by making StdWriters RefObject derived, and kept in scope such the writers are destroyed before checks for leaks is found * Added SimplifyPathAndHash mode for CacheFileSystem - will simplify the path and see if simplified path is in cache before reading file (limiting amout of underlying file requests) * * Added calcReplaceChar * Renamed DefaultFileSystem to OSFileSystem * Made OSFileSystem convert windows \ to / on linux * Simplified logic for caching in CacheFileSystem. * Added pragma-once-c to add extra test, but also so there is an 'include' directory in preprocessor tests. * Small fixes in pragma once test. * Simplified cache handling path, so that paths/simplified paths area always added. * Improve naming of methods for different caches.
Diffstat (limited to 'source/core/slang-std-writers.cpp')
-rw-r--r--source/core/slang-std-writers.cpp33
1 files changed, 16 insertions, 17 deletions
diff --git a/source/core/slang-std-writers.cpp b/source/core/slang-std-writers.cpp
index 963af9ef5..8b2f6f604 100644
--- a/source/core/slang-std-writers.cpp
+++ b/source/core/slang-std-writers.cpp
@@ -6,29 +6,28 @@ namespace Slang
/* static */StdWriters* StdWriters::s_singleton = nullptr;
-/* static */StdWriters* StdWriters::getDefault()
+/* static */RefPtr<StdWriters> StdWriters::createDefault()
{
- static StdWriters* s_context = nullptr;
+ RefPtr<StdWriters> stdWriters(new StdWriters);
- if (!s_context)
- {
- static FileWriter s_stdError(stderr, WriterFlag::IsStatic | WriterFlag::IsUnowned | WriterFlag::AutoFlush);
- static FileWriter s_stdOut(stdout, WriterFlag::IsStatic | WriterFlag::IsUnowned | WriterFlag::AutoFlush);
-
- static StdWriters s_contextVar;
- s_context = &s_contextVar;
+ RefPtr<FileWriter> stdError(new FileWriter(stderr, WriterFlag::AutoFlush));
+ RefPtr<FileWriter> stdOut(new FileWriter(stdout, WriterFlag::AutoFlush));
- s_context->setWriter(SLANG_WRITER_CHANNEL_STD_ERROR, &s_stdError);
- s_context->setWriter(SLANG_WRITER_CHANNEL_STD_OUTPUT, &s_stdOut);
- }
- return s_context;
+ stdWriters->setWriter(SLANG_WRITER_CHANNEL_STD_ERROR, stdError);
+ stdWriters->setWriter(SLANG_WRITER_CHANNEL_STD_OUTPUT, stdOut);
+
+ return stdWriters;
}
-/* static */StdWriters* StdWriters::initDefault()
+/* static */RefPtr<StdWriters> StdWriters::initDefaultSingleton()
{
- StdWriters* context = getDefault();
- setSingleton(context);
- return context;
+ if (s_singleton)
+ {
+ return s_singleton;
+ }
+ auto defaults = createDefault();
+ setSingleton(defaults);
+ return defaults;
}
void StdWriters::setRequestWriters(SlangCompileRequest* request)