From: kanschat Date: Mon, 5 May 2008 22:26:09 +0000 (+0000) Subject: fix problems with segmentation fault in tests X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cb155aa1ecda093cff30fe9f944275d0e811c034;p=dealii-svn.git fix problems with segmentation fault in tests git-svn-id: https://svn.dealii.org/trunk@16030 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/base/source/subscriptor.cc b/deal.II/base/source/subscriptor.cc index 36369372f7..3ea93b90de 100644 --- a/deal.II/base/source/subscriptor.cc +++ b/deal.II/base/source/subscriptor.cc @@ -120,6 +120,11 @@ Subscriptor::~Subscriptor () << std::endl; } } + // In case we do not abort + // on error, this will tell + // do_unsubscribe below that the + // object is unused now. + counter = 0; #endif } @@ -160,12 +165,16 @@ void Subscriptor::do_unsubscribe (const char* id) const { #ifdef DEBUG Assert (counter>0, ExcNotUsed()); + // This is for the case that we do + // not abort after the exception + if (counter == 0) + return; + Threads::ThreadMutex::ScopedLock lock (subscription_lock); --counter; #if DEAL_USE_MT == 0 const char* name = (id != 0) ? id : unknown_subscriber; - map_iterator it = counter_map.find(name); Assert (it != counter_map.end(), ExcNoSubscriber(object_info->name(), name)); Assert (it->second > 0, ExcNoSubscriber(object_info->name(), name)); diff --git a/tests/base/reference.cc b/tests/base/reference.cc index 0e18087593..eb6eacd22c 100644 --- a/tests/base/reference.cc +++ b/tests/base/reference.cc @@ -2,7 +2,7 @@ // $Id$ // Version: $Name$ // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 by the deal.II authors +// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2008 by the deal.II authors // // This file is subject to QPL and may not be distributed // without copyright and license information. Please refer @@ -23,7 +23,13 @@ #include #include #include +#include +#include +// Provide memory for objects of type T such that access to a deleted +// object does not cause a segmentation fault +std::vector memory(10000); +int next = 0; class Test : public Subscriptor { @@ -47,7 +53,8 @@ int main() if (true) { Test a("A"); - const Test b("B"); + const Test& b("B"); + SmartPointer r(&a, "Test R"); SmartPointer s(&a, "const Test S"); // SmartPointer t=&b; // this one should not work @@ -74,6 +81,9 @@ int main() r = &c; Test d("D"); r = &d; + // Destruction of "Test R" will + // cause a spurious ExcNotUsed + // here, since D was deleted first } } diff --git a/tests/base/reference/cmp/generic b/tests/base/reference/cmp/generic index 63bebc7caa..9850c9b96e 100644 --- a/tests/base/reference/cmp/generic +++ b/tests/base/reference/cmp/generic @@ -12,7 +12,6 @@ DEAL::Construct D DEAL::Destruct D DEAL::ExcInUse (counter, object_info->name(), infostring) DEAL::Destruct C -DEAL::ExcNoSubscriber(object_info->name(), name) -DEAL::ExcNoSubscriber(object_info->name(), name) +DEAL::ExcNotUsed() DEAL::Destruct B DEAL::Destruct A diff --git a/tests/base/reference/cmp/i686-pc-linux-gnu+gcc3.4 b/tests/base/reference/cmp/i686-pc-linux-gnu+gcc3.4 deleted file mode 100644 index f6cb28670f..0000000000 --- a/tests/base/reference/cmp/i686-pc-linux-gnu+gcc3.4 +++ /dev/null @@ -1,16 +0,0 @@ - -DEAL::Construct A -DEAL::Construct B -DEAL::a mutable -DEAL::b const -DEAL::r mutable -DEAL::s const -DEAL::t mutable -DEAL::u const -DEAL::Construct C -DEAL::Construct D -DEAL::Destruct D -DEAL::ExcInUse(counter, object_info->name(), infostring) -DEAL::Destruct C -DEAL::Destruct B -DEAL::Destruct A diff --git a/tests/base/reference/cmp/i686-pc-linux-gnu+icc7.1 b/tests/base/reference/cmp/i686-pc-linux-gnu+icc7.1 deleted file mode 100644 index f6cb28670f..0000000000 --- a/tests/base/reference/cmp/i686-pc-linux-gnu+icc7.1 +++ /dev/null @@ -1,16 +0,0 @@ - -DEAL::Construct A -DEAL::Construct B -DEAL::a mutable -DEAL::b const -DEAL::r mutable -DEAL::s const -DEAL::t mutable -DEAL::u const -DEAL::Construct C -DEAL::Construct D -DEAL::Destruct D -DEAL::ExcInUse(counter, object_info->name(), infostring) -DEAL::Destruct C -DEAL::Destruct B -DEAL::Destruct A diff --git a/tests/base/reference/cmp/mips-sgi-irix6.5+MIPSpro7.4 b/tests/base/reference/cmp/mips-sgi-irix6.5+MIPSpro7.4 deleted file mode 100644 index f6cb28670f..0000000000 --- a/tests/base/reference/cmp/mips-sgi-irix6.5+MIPSpro7.4 +++ /dev/null @@ -1,16 +0,0 @@ - -DEAL::Construct A -DEAL::Construct B -DEAL::a mutable -DEAL::b const -DEAL::r mutable -DEAL::s const -DEAL::t mutable -DEAL::u const -DEAL::Construct C -DEAL::Construct D -DEAL::Destruct D -DEAL::ExcInUse(counter, object_info->name(), infostring) -DEAL::Destruct C -DEAL::Destruct B -DEAL::Destruct A diff --git a/tests/base/reference/cmp/x86_64-unknown-linux-gnu+gcc3.3 b/tests/base/reference/cmp/x86_64-unknown-linux-gnu+gcc3.3 deleted file mode 100644 index 03931e2d24..0000000000 --- a/tests/base/reference/cmp/x86_64-unknown-linux-gnu+gcc3.3 +++ /dev/null @@ -1,18 +0,0 @@ - -DEAL::Construct A -DEAL::Construct B -DEAL::a mutable -DEAL::b const -DEAL::r mutable -DEAL::s const -DEAL::t mutable -DEAL::u const -DEAL::Construct C -DEAL::Construct D -DEAL::Destruct D -DEAL::ExcInUse(counter, object_info->name(), infostring) -DEAL::Destruct C -DEAL::ExcNoSubscriber(object_info->name(), name) -DEAL::ExcNoSubscriber(object_info->name(), name) -DEAL::Destruct B -DEAL::Destruct A diff --git a/tests/base/reference/cmp/x86_64-unknown-linux-gnu+gcc4.0 b/tests/base/reference/cmp/x86_64-unknown-linux-gnu+gcc4.0 deleted file mode 100644 index f6cb28670f..0000000000 --- a/tests/base/reference/cmp/x86_64-unknown-linux-gnu+gcc4.0 +++ /dev/null @@ -1,16 +0,0 @@ - -DEAL::Construct A -DEAL::Construct B -DEAL::a mutable -DEAL::b const -DEAL::r mutable -DEAL::s const -DEAL::t mutable -DEAL::u const -DEAL::Construct C -DEAL::Construct D -DEAL::Destruct D -DEAL::ExcInUse(counter, object_info->name(), infostring) -DEAL::Destruct C -DEAL::Destruct B -DEAL::Destruct A diff --git a/tests/base/reference/cmp/x86_64-unknown-linux-gnu+icc9 b/tests/base/reference/cmp/x86_64-unknown-linux-gnu+icc9 deleted file mode 100644 index bc95b82dd3..0000000000 --- a/tests/base/reference/cmp/x86_64-unknown-linux-gnu+icc9 +++ /dev/null @@ -1,49 +0,0 @@ - -DEAL::Construct A -DEAL::Construct B -DEAL::a mutable -DEAL::b const -DEAL::r mutable -DEAL::s const -DEAL::t mutable -DEAL::u const -DEAL::Construct C -DEAL::Construct D -DEAL::Destruct D --------------------------------------------------------- -An error occurred in file in function - Subscriptor::~Subscriptor() -The violated condition was: - counter == 0 -The name and call sequence of the exception was: - ExcInUse(counter, object_info->name(), infostring) -Additional Information: -Object of class 4Test is still used by 1 other objects. - from Subscriber Test R --------------------------------------------------------- -DEAL::Abort!!! -DEAL::Destruct C --------------------------------------------------------- -An error occurred in file in function - void Subscriptor::unsubscribe(const char *) const -The violated condition was: - it != counter_map.end() -The name and call sequence of the exception was: - ExcNoSubscriber(object_info->name(), name) -Additional Information: -No subscriber with identifier "Test R" did subscribe to this object of class 4Test --------------------------------------------------------- -DEAL::Abort!!! --------------------------------------------------------- -An error occurred in file in function - void Subscriptor::unsubscribe(const char *) const -The violated condition was: - it->second > 0 -The name and call sequence of the exception was: - ExcNoSubscriber(object_info->name(), name) -Additional Information: -No subscriber with identifier "Test R" did subscribe to this object of class 4Test --------------------------------------------------------- -DEAL::Abort!!! -DEAL::Destruct B -DEAL::Destruct A