# # patch "ChangeLog" # from [b5ce0e31b5552a26f01d17edf46fad8271e87227] # to [dc631b0fd1d9bf355497521d61f0eaa173534dd4] # # patch "configure.ac" # from [df78b3726a6727dc09ca4573281ddb103dc79d56] # to [b2c3219e2a140dbc47379fd23cae0e918e5e71cc] # # patch "ui.cc" # from [956b7c37e04eab186d093e34b39a625b7264849a] # to [c51b1607975f692479563b70efd80c40731ea83a] # ======================================================================== --- ChangeLog b5ce0e31b5552a26f01d17edf46fad8271e87227 +++ ChangeLog dc631b0fd1d9bf355497521d61f0eaa173534dd4 @@ -1,3 +1,10 @@ +2005-11-27 Julio M. Merino Vidal + + * configure.ac, ui.cc: Windows does have sync_with_iostream; the + problem is that it does not behave correctly on some MinGW versions. + Properly detect this condition. Thanks to Matthew Gregan for the + explanation. + 2005-11-27 Matthew Gregan * tests/t_netsync_largish_file.at: Move LARGISH_FILE_CREATE ======================================================================== --- configure.ac df78b3726a6727dc09ca4573281ddb103dc79d56 +++ configure.ac b2c3219e2a140dbc47379fd23cae0e918e5e71cc @@ -471,21 +471,67 @@ AC_CHECK_FUNC(getaddrinfo, [AM_CONDITIONAL(MISSING_GETADDRINFO, false)], [AM_CONDITIONAL(MISSING_GETADDRINFO, true)]) -# Check whether C++ streams support sync_with_stdio. +# Check whether sync_with_stdio(false) run on C++ streams works correctly. +# It causes strange problems (EOF returned too early) on some versions of +# MinGW. +# +# In order to check for this issue, we first generate a large input file +# (over 128KB) and then try to read it (using a buffer size over 512 +# bytes). If the amount of bytes read does not match the generated input, +# the implementation is broken. AC_MSG_CHECKING(whether C++ streams support sync_with_stdio) -AC_LINK_IFELSE([AC_LANG_SOURCE([ +AC_RUN_IFELSE([AC_LANG_SOURCE([ +/* + * Generates the input file. + */ +#include +#include + +int +main(void) +{ + std::ofstream ofs("_conftest.dat"); + for (int i = 0; i < 50000; i++) + ofs << "0123456789\r\n"; + ofs.close(); + + return EXIT_SUCCESS; +} +])]) +AC_RUN_IFELSE([AC_LANG_SOURCE([ +/* + * Reads the input file. + */ +#include +#include #include -int main(void) +int +main(int argc, char * argv[]) { - std::clog.sync_with_stdio(false); - return 0; + if (argc == 1) + return EXIT_SUCCESS; + + std::cin.sync_with_stdio(false); + int length = 0; + while (std::cin.good()) + { + char buffer@<:@1024@:>@; + (void)std::cin.read(buffer, sizeof(buffer)); + length += std::cin.gcount(); + } + + return length == 600000 ? EXIT_SUCCESS : EXIT_FAILURE; } ])], - [AC_MSG_RESULT(yes) - AC_DEFINE(HAVE_SYNC_WITH_STDIO, 1, - [Define to 1 if C++ streams support sync_with_stdio])], - [AC_MSG_RESULT(no)]) + [if ./conftest$ac_exeext check_it_now <_conftest.dat; then + AC_MSG_RESULT(yes) + AC_DEFINE(SYNC_WITH_STDIO_WORKS, 1, + [Define to 1 if sync_with_stdio works fine on C++ streams]) + else + AC_MSG_RESULT(no) + fi + rm -f _conftest.dat]) # allow compiling with different flags/optimisation # for monotone versus libs, useful for testing. ======================================================================== --- ui.cc 956b7c37e04eab186d093e34b39a625b7264849a +++ ui.cc c51b1607975f692479563b70efd80c40731ea83a @@ -263,7 +263,7 @@ t_writer(0) { cout.exceptions(ios_base::badbit); -#ifdef HAVE_SYNC_WITH_STDIO +#ifdef SYNC_WITH_STDIO_WORKS clog.sync_with_stdio(false); #endif clog.unsetf(ios_base::unitbuf);