From: <man...@us...> - 2015-04-23 10:00:21
|
Revision: 4967 http://sourceforge.net/p/modplug/code/4967 Author: manxorist Date: 2015-04-23 10:00:09 +0000 (Thu, 23 Apr 2015) Log Message: ----------- [Ref] Test: Do not rely on C-style varargs in the string formatting tests. [Ref] Move any C-style varargs support to the only remaining user, the old Log() infrastructure, in order to avoid the need to include <cstdarg> and <stdarg.h> everywhere. Modified Paths: -------------- trunk/OpenMPT/common/Logging.cpp trunk/OpenMPT/common/stdafx.h trunk/OpenMPT/common/typedefs.h trunk/OpenMPT/test/test.cpp Modified: trunk/OpenMPT/common/Logging.cpp =================================================================== --- trunk/OpenMPT/common/Logging.cpp 2015-04-23 09:54:10 UTC (rev 4966) +++ trunk/OpenMPT/common/Logging.cpp 2015-04-23 10:00:09 UTC (rev 4967) @@ -18,15 +18,26 @@ #include "version.h" #include <iostream> + +#include <cstdarg> #include <cstring> +#include <stdarg.h> + OPENMPT_NAMESPACE_BEGIN //#define LOG_TO_FILE +#if MPT_COMPILER_MSVC || (MPT_COMPILER_GCC && MPT_GCC_AT_LEAST(4,3,0) && MPT_GCC_BEFORE(4,4,0)) +#ifndef va_copy +#define va_copy(dst, src) do { (dst) = (src); } while (0) +#endif +#endif + + namespace mpt { namespace log Modified: trunk/OpenMPT/common/stdafx.h =================================================================== --- trunk/OpenMPT/common/stdafx.h 2015-04-23 09:54:10 UTC (rev 4966) +++ trunk/OpenMPT/common/stdafx.h 2015-04-23 10:00:09 UTC (rev 4967) @@ -48,7 +48,6 @@ // <memory> // <new> // <type_traits> // if available -// <cstdarg> // <cstdint> // <stdint.h> Modified: trunk/OpenMPT/common/typedefs.h =================================================================== --- trunk/OpenMPT/common/typedefs.h 2015-04-23 09:54:10 UTC (rev 4966) +++ trunk/OpenMPT/common/typedefs.h 2015-04-23 10:00:09 UTC (rev 4967) @@ -297,18 +297,7 @@ #endif -OPENMPT_NAMESPACE_END -#include <cstdarg> -#include <stdarg.h> -OPENMPT_NAMESPACE_BEGIN -#if MPT_COMPILER_MSVC || (MPT_COMPILER_GCC && MPT_GCC_AT_LEAST(4,3,0) && MPT_GCC_BEFORE(4,4,0)) -#ifndef va_copy -#define va_copy(dst, src) do { (dst) = (src); } while (0) -#endif -#endif - - #if (MPT_COMPILER_MSVC && MPT_MSVC_BEFORE(2010,0)) || (MPT_COMPILER_GCC && MPT_GCC_BEFORE(4,3,0)) OPENMPT_NAMESPACE_END Modified: trunk/OpenMPT/test/test.cpp =================================================================== --- trunk/OpenMPT/test/test.cpp 2015-04-23 09:54:10 UTC (rev 4966) +++ trunk/OpenMPT/test/test.cpp 2015-04-23 10:00:09 UTC (rev 4967) @@ -282,30 +282,19 @@ // 4. Formatting of floating point values depends on the currently set C locale. // A library is not allowed to mock with that and thus cannot influence the behavior in this case. -static std::string MPT_PRINTF_FUNC(1,2) StringFormat(const char * format, ...); - -static std::string StringFormat(const char *format, ...) +template <typename T> +static std::string StringFormat(const char *format, T x) { #if MPT_COMPILER_MSVC - va_list argList; - va_start(argList, format); - // Count the needed array size. - const size_t nCount = _vscprintf(format, argList); // null character not included. + const size_t nCount = _scprintf(format, x); // null character not included. std::vector<char> buf(nCount + 1); // + 1 is for null terminator. - vsprintf_s(&(buf[0]), buf.size(), format, argList); - - va_end(argList); + sprintf_s(&(buf[0]), buf.size(), format, x); return &(buf[0]); #else - va_list argList; - va_start(argList, format); - int size = vsnprintf(NULL, 0, format, argList); // get required size, requires c99 compliant vsnprintf which msvc does not have - va_end(argList); + int size = snprintf(NULL, 0, format, x); // get required size, requires c99 compliant snprintf which msvc does not have std::vector<char> temp(size + 1); - va_start(argList, format); - vsnprintf(&(temp[0]), size + 1, format, argList); - va_end(argList); + snprintf(&(temp[0]), size + 1, format, x); return &(temp[0]); #endif } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |