Merge pull request #3244 from laanwj/2013_11_mingw_c99_printf
Use C99 printf statements in mingw
This commit is contained in:
commit
5ce4361077
|
@ -221,7 +221,7 @@ case $host in
|
||||||
AC_MSG_ERROR("windres not found")
|
AC_MSG_ERROR("windres not found")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
CPPFLAGS="$CPPFLAGS -D_MT -DWIN32 -D_WINDOWS -DBOOST_THREAD_USE_LIB"
|
CPPFLAGS="$CPPFLAGS -D_MT -DWIN32 -D_WINDOWS -DBOOST_THREAD_USE_LIB -D__USE_MINGW_ANSI_STDIO"
|
||||||
LEVELDB_TARGET_FLAGS="TARGET_OS=OS_WINDOWS_CROSSCOMPILE"
|
LEVELDB_TARGET_FLAGS="TARGET_OS=OS_WINDOWS_CROSSCOMPILE"
|
||||||
CXXFLAGS="$CXXFLAGS -w"
|
CXXFLAGS="$CXXFLAGS -w"
|
||||||
;;
|
;;
|
||||||
|
|
|
@ -303,4 +303,31 @@ BOOST_AUTO_TEST_CASE(util_TimingResistantEqual)
|
||||||
BOOST_CHECK(!TimingResistantEqual(std::string("abc"), std::string("aba")));
|
BOOST_CHECK(!TimingResistantEqual(std::string("abc"), std::string("aba")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Test strprintf formatting directives.
|
||||||
|
* Put a string before and after to ensure sanity of element sizes on stack. */
|
||||||
|
#define B "check_prefix"
|
||||||
|
#define E "check_postfix"
|
||||||
|
BOOST_AUTO_TEST_CASE(strprintf_numbers)
|
||||||
|
{
|
||||||
|
int64_t s64t = -9223372036854775807LL; /* signed 64 bit test value */
|
||||||
|
uint64_t u64t = 18446744073709551615ULL; /* unsigned 64 bit test value */
|
||||||
|
BOOST_CHECK(strprintf("%s %"PRId64" %s", B, s64t, E) == B" -9223372036854775807 "E);
|
||||||
|
BOOST_CHECK(strprintf("%s %"PRIu64" %s", B, u64t, E) == B" 18446744073709551615 "E);
|
||||||
|
BOOST_CHECK(strprintf("%s %"PRIx64" %s", B, u64t, E) == B" ffffffffffffffff "E);
|
||||||
|
|
||||||
|
size_t st = 12345678; /* unsigned size_t test value */
|
||||||
|
ssize_t sst = -12345678; /* signed size_t test value */
|
||||||
|
BOOST_CHECK(strprintf("%s %"PRIszd" %s", B, sst, E) == B" -12345678 "E);
|
||||||
|
BOOST_CHECK(strprintf("%s %"PRIszu" %s", B, st, E) == B" 12345678 "E);
|
||||||
|
BOOST_CHECK(strprintf("%s %"PRIszx" %s", B, st, E) == B" bc614e "E);
|
||||||
|
|
||||||
|
ptrdiff_t pt = 87654321; /* positive ptrdiff_t test value */
|
||||||
|
ptrdiff_t spt = -87654321; /* negative ptrdiff_t test value */
|
||||||
|
BOOST_CHECK(strprintf("%s %"PRIpdd" %s", B, spt, E) == B" -87654321 "E);
|
||||||
|
BOOST_CHECK(strprintf("%s %"PRIpdu" %s", B, pt, E) == B" 87654321 "E);
|
||||||
|
BOOST_CHECK(strprintf("%s %"PRIpdx" %s", B, pt, E) == B" 5397fb1 "E);
|
||||||
|
}
|
||||||
|
#undef B
|
||||||
|
#undef E
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE_END()
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
|
|
@ -336,11 +336,7 @@ string vstrprintf(const char *format, va_list ap)
|
||||||
{
|
{
|
||||||
va_list arg_ptr;
|
va_list arg_ptr;
|
||||||
va_copy(arg_ptr, ap);
|
va_copy(arg_ptr, ap);
|
||||||
#ifdef WIN32
|
|
||||||
ret = _vsnprintf(p, limit, format, arg_ptr);
|
|
||||||
#else
|
|
||||||
ret = vsnprintf(p, limit, format, arg_ptr);
|
ret = vsnprintf(p, limit, format, arg_ptr);
|
||||||
#endif
|
|
||||||
va_end(arg_ptr);
|
va_end(arg_ptr);
|
||||||
if (ret >= 0 && ret < limit)
|
if (ret >= 0 && ret < limit)
|
||||||
break;
|
break;
|
||||||
|
|
17
src/util.h
17
src/util.h
|
@ -44,26 +44,13 @@ static const int64_t CENT = 1000000;
|
||||||
#define UEND(a) ((unsigned char*)&((&(a))[1]))
|
#define UEND(a) ((unsigned char*)&((&(a))[1]))
|
||||||
#define ARRAYLEN(array) (sizeof(array)/sizeof((array)[0]))
|
#define ARRAYLEN(array) (sizeof(array)/sizeof((array)[0]))
|
||||||
|
|
||||||
/* Format characters for (s)size_t and ptrdiff_t */
|
/* Format characters for (s)size_t and ptrdiff_t (C99 standard) */
|
||||||
#if defined(_MSC_VER) || defined(__MSVCRT__)
|
|
||||||
/* (s)size_t and ptrdiff_t have the same size specifier in MSVC:
|
|
||||||
http://msdn.microsoft.com/en-us/library/tcxf1dw6%28v=vs.100%29.aspx
|
|
||||||
*/
|
|
||||||
#define PRIszx "Ix"
|
|
||||||
#define PRIszu "Iu"
|
|
||||||
#define PRIszd "Id"
|
|
||||||
#define PRIpdx "Ix"
|
|
||||||
#define PRIpdu "Iu"
|
|
||||||
#define PRIpdd "Id"
|
|
||||||
#else /* C99 standard */
|
|
||||||
#define PRIszx "zx"
|
#define PRIszx "zx"
|
||||||
#define PRIszu "zu"
|
#define PRIszu "zu"
|
||||||
#define PRIszd "zd"
|
#define PRIszd "zd"
|
||||||
#define PRIpdx "tx"
|
#define PRIpdx "tx"
|
||||||
#define PRIpdu "tu"
|
#define PRIpdu "tu"
|
||||||
#define PRIpdd "td"
|
#define PRIpdd "td"
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
// This is needed because the foreach macro can't get over the comma in pair<t1, t2>
|
// This is needed because the foreach macro can't get over the comma in pair<t1, t2>
|
||||||
#define PAIRTYPE(t1, t2) std::pair<t1, t2>
|
#define PAIRTYPE(t1, t2) std::pair<t1, t2>
|
||||||
|
@ -117,7 +104,7 @@ inline void MilliSleep(int64_t n)
|
||||||
* Parameters count from 1.
|
* Parameters count from 1.
|
||||||
*/
|
*/
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
#define ATTR_WARN_PRINTF(X,Y) __attribute__((format(printf,X,Y)))
|
#define ATTR_WARN_PRINTF(X,Y) __attribute__((format(gnu_printf,X,Y)))
|
||||||
#else
|
#else
|
||||||
#define ATTR_WARN_PRINTF(X,Y)
|
#define ATTR_WARN_PRINTF(X,Y)
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue