From 49ed6b60d662906f290578f802f80b0ead1a2b9d Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Wed, 12 Dec 2018 08:57:48 -0500 Subject: Running tests in slang-test process (#740) * First pass at having an interface to write text to that can be replaced. Simplifed and made more rigerous the interface used to write formatted strings. * Added AppContext to simplify setting up and parsing around of streams. * Added more simplified way to get the std error/out from AppContext. * Work in progress using dll for tools to speed up testing. * First pass at ISlangWriter interface. * Added support for writing VaArgs. Added NullWriter. * Use ISlangWriter for output. * Use ISlangWriter for output - replacing OutputCallback. Make IRDump go to ISlangWriter * SlangWriterTargetType -> SlangWriterChannel Improvements around AppContext * Shared library working with slang-reflection-test. * Dll testing working for render-test. * Include va_list definintion from header. * Fix errors from clang. * Fix typo for linux. * Added -usexes option * Fix typo. * Fix arguments problem on linux. * Fix typo for linux. * Add windows tool shared library projects. * Fix warning from x86 win build. Fix signed warning from slang-test/main.cpp * First attempt at getting premake to work on travis, and run tests. * Try moving build out into script. * Invoke bash scripts so they don't have to be executable. * Drive configuration/tests from env parameters set by travis * Try using source to run travis tests. * Remove the build.linux directory - but doing so will overwrite Makefile. * Made -fno-delete-null-pointer-checks gcc only. * Try to fix warning from -fno-delete-null-pointer-checks * Turn of warnings for unknown switches. * Try to make premake choose the correct tooling. * Disabled missing braces warning. * Disable -Wundefined-var-template on clang. * -Wunused-function disabled for clang. * Fix typo due to SlangBool. * Remove this nullptr tests. * "-Wno-unused-private-field" for clang. * Added "-Wno-undefined-bool-conversion" * Add DominatorList::end fix. * Split scripts into travis_build.sh travis_test.sh * Fix gcc/clang template pre-declaration issue around QualType. * Fix premake to build such that pthread correctly links with slang-glslang --- source/core/slang-string-util.cpp | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) (limited to 'source/core/slang-string-util.cpp') diff --git a/source/core/slang-string-util.cpp b/source/core/slang-string-util.cpp index 6d0d896a1..cb5709759 100644 --- a/source/core/slang-string-util.cpp +++ b/source/core/slang-string-util.cpp @@ -39,32 +39,39 @@ static const Guid IID_ISlangBlob = SLANG_UUID_ISlangBlob; } } - -/* static */void StringUtil::append(const char* format, va_list args, StringBuilder& buf) +/* static */size_t StringUtil::calcFormattedSize(const char* format, va_list args) { - int numChars = 0; +#if SLANG_WINDOWS_FAMILY + return _vscprintf(format, args); +#else + return vsnprintf(nullptr, 0, format, args); +#endif +} +/* static */void StringUtil::calcFormatted(const char* format, va_list args, size_t numChars, char* dst) +{ #if SLANG_WINDOWS_FAMILY - numChars = _vscprintf(format, args); + vsnprintf_s(dst, numChars + 1, _TRUNCATE, format, args); #else + vsnprintf(dst, numChars + 1, format, args); +#endif +} + +/* static */void StringUtil::append(const char* format, va_list args, StringBuilder& buf) +{ + // Calculate the size + size_t numChars; { + // Create a copy of args, as will be consumed by calcFormattedSize va_list argsCopy; va_copy(argsCopy, args); - numChars = vsnprintf(nullptr, 0, format, argsCopy); + numChars = calcFormattedSize(format, argsCopy); va_end(argsCopy); } -#endif - - List chars; - chars.SetSize(numChars + 1); - -#if SLANG_WINDOWS_FAMILY - vsnprintf_s(chars.Buffer(), numChars + 1, _TRUNCATE, format, args); -#else - vsnprintf(chars.Buffer(), numChars + 1, format, args); -#endif - buf.Append(chars.Buffer(), numChars); + char* dst = buf.prepareForAppend(numChars + 1); + calcFormatted(format, args, numChars, dst); + buf.appendInPlace(dst, numChars); } /* static */void StringUtil::appendFormat(StringBuilder& buf, const char* format, ...) -- cgit v1.2.3