From 0a3ef7b4ae02983ea3f986ba8211e7c6af9d254b Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Mon, 21 Jan 2019 15:33:59 -0500 Subject: 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. --- tools/render-test/render-test-main.cpp | 6 +++++- .../slang-reflection-test-main.cpp | 7 ++++++- tools/slang-test/slang-test-main.cpp | 2 +- tools/slang-test/unit-test-path.cpp | 22 +++++++++++++++++++++- 4 files changed, 33 insertions(+), 4 deletions(-) (limited to 'tools') diff --git a/tools/render-test/render-test-main.cpp b/tools/render-test/render-test-main.cpp index 7cf303631..7dde38ae6 100644 --- a/tools/render-test/render-test-main.cpp +++ b/tools/render-test/render-test-main.cpp @@ -670,8 +670,12 @@ SLANG_TEST_TOOL_API SlangResult innerMain(Slang::StdWriters* stdWriters, SlangSe int main(int argc, char** argv) { + using namespace Slang; SlangSession* session = spCreateSession(nullptr); - SlangResult res = innerMain(Slang::StdWriters::initDefault(), session, argc, argv); + + auto stdWriters = StdWriters::initDefaultSingleton(); + + SlangResult res = innerMain(stdWriters, session, argc, argv); spDestroySession(session); return SLANG_FAILED(res) ? 1 : 0; diff --git a/tools/slang-reflection-test/slang-reflection-test-main.cpp b/tools/slang-reflection-test/slang-reflection-test-main.cpp index 3ae614b22..209528927 100644 --- a/tools/slang-reflection-test/slang-reflection-test-main.cpp +++ b/tools/slang-reflection-test/slang-reflection-test-main.cpp @@ -963,8 +963,13 @@ int main( int argc, char** argv) { + using namespace Slang; + SlangSession* session = spCreateSession(nullptr); - SlangResult res = innerMain(Slang::StdWriters::initDefault(), session, argc, argv); + + auto stdWriters = StdWriters::initDefaultSingleton(); + + SlangResult res = innerMain(stdWriters, session, argc, argv); spDestroySession(session); return SLANG_FAILED(res) ? 1 : 0; diff --git a/tools/slang-test/slang-test-main.cpp b/tools/slang-test/slang-test-main.cpp index 06c2aaf67..d0da4fc61 100644 --- a/tools/slang-test/slang-test-main.cpp +++ b/tools/slang-test/slang-test-main.cpp @@ -1818,7 +1818,7 @@ void runTestsInDirectory( SlangResult innerMain(int argc, char** argv) { - StdWriters::initDefault(); + auto stdWriters = StdWriters::initDefaultSingleton(); // The context holds useful things used during testing TestContext context; diff --git a/tools/slang-test/unit-test-path.cpp b/tools/slang-test/unit-test-path.cpp index e9cfbe2e3..712453e23 100644 --- a/tools/slang-test/unit-test-path.cpp +++ b/tools/slang-test/unit-test-path.cpp @@ -35,7 +35,27 @@ static void pathUnitTest() SLANG_CHECK(Path::Simplify("a:\\what\\..\\.\\..\\is\\.\\..\\this\\.\\") == "a:/../this"); + SLANG_CHECK(Path::Simplify("tests/preprocessor/.\\pragma-once-a.h") == "tests/preprocessor/pragma-once-a.h"); + + + SLANG_CHECK(Path::IsRelative(".")); + SLANG_CHECK(Path::IsRelative("..")); + SLANG_CHECK(Path::IsRelative("blah/..")); + + SLANG_CHECK(Path::IsRelative("blah/.././a")); + SLANG_CHECK(Path::IsRelative("a") == false); + SLANG_CHECK(Path::IsRelative("blah/a") == false); + SLANG_CHECK(Path::IsRelative("a:\\blah/a") == false); + + + SLANG_CHECK(Path::IsRelative("a:/what/.././../is/./../this/.")); + + SLANG_CHECK(Path::IsRelative("a:/what/.././../is/./../this/./")); + + SLANG_CHECK(Path::IsRelative("a:\\what\\..\\.\\..\\is\\.\\..\\this\\.\\")); + + } } -SLANG_UNIT_TEST("Path", pathUnitTest); \ No newline at end of file +SLANG_UNIT_TEST("Path", pathUnitTest); -- cgit v1.2.3