From 11d36b60522c66d3e319c23738a8398f72f4ddc6 Mon Sep 17 00:00:00 2001 From: wolf Date: Mon, 5 May 2003 13:49:06 +0000 Subject: [PATCH] Fix a problem that leads to a segfault at the end of the program with gcc3.4 and icc. git-svn-id: https://svn.dealii.org/trunk@7560 0785d39b-7218-0410-832d-ea1e28bc413d --- tests/base/reference.cc | 22 ++++++++++++++++++++++ tests/lac/block_vector.cc | 7 +++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/tests/base/reference.cc b/tests/base/reference.cc index 86a04515b9..114132dc0e 100644 --- a/tests/base/reference.cc +++ b/tests/base/reference.cc @@ -40,7 +40,27 @@ int main() std::ofstream logfile("reference.output"); deallog.attach(logfile); deallog.depth_console(0); + + // we do something rather weird in + // this file: bind the buffer of + // cerr to the log file, so that + // the output of the Assert* macros + // that are written to std::cerr + // end up in the logfiles. + // + // so make sure we store a pointer + // to the old buffer, switch to the + // buffer of the logfile, and at + // the end of main() switch + // back. note that if we don't + // switch back, we get a segfault + // later on in the destruction of + // std::cerr, since it tries to do + // something with its buffer, but + // that is already gone by then + std::basic_streambuf *old_cerr_buf = std::cerr.rdbuf(); std::cerr.rdbuf(logfile.rdbuf()); + Test a("A"); const Test b("B"); SmartPointer r=&a; @@ -71,5 +91,7 @@ int main() Test d("D"); r = &d; } + + std::cerr.rdbuf(old_cerr_buf); } diff --git a/tests/lac/block_vector.cc b/tests/lac/block_vector.cc index 67c3a72e86..09ffa9953f 100644 --- a/tests/lac/block_vector.cc +++ b/tests/lac/block_vector.cc @@ -154,6 +154,10 @@ int main () logfile.precision(3); deallog.attach(logfile); deallog.depth_console(0); + + // do the same weird stuff as in + // tests/base/reference.cc + std::basic_streambuf *old_cerr_buf = std::cerr.rdbuf(); std::cerr.rdbuf(logfile.rdbuf()); try @@ -185,7 +189,6 @@ int main () return 3; }; - - return 0; + std::cerr.rdbuf(old_cerr_buf); } -- 2.39.5