]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
fix problems with segmentation fault in tests
authorkanschat <kanschat@0785d39b-7218-0410-832d-ea1e28bc413d>
Mon, 5 May 2008 22:26:09 +0000 (22:26 +0000)
committerkanschat <kanschat@0785d39b-7218-0410-832d-ea1e28bc413d>
Mon, 5 May 2008 22:26:09 +0000 (22:26 +0000)
git-svn-id: https://svn.dealii.org/trunk@16030 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/base/source/subscriptor.cc
tests/base/reference.cc
tests/base/reference/cmp/generic
tests/base/reference/cmp/i686-pc-linux-gnu+gcc3.4 [deleted file]
tests/base/reference/cmp/i686-pc-linux-gnu+icc7.1 [deleted file]
tests/base/reference/cmp/mips-sgi-irix6.5+MIPSpro7.4 [deleted file]
tests/base/reference/cmp/x86_64-unknown-linux-gnu+gcc3.3 [deleted file]
tests/base/reference/cmp/x86_64-unknown-linux-gnu+gcc4.0 [deleted file]
tests/base/reference/cmp/x86_64-unknown-linux-gnu+icc9 [deleted file]

index 36369372f77f6e459127a6786cd6a9f43a285489..3ea93b90dead5066b6ed5b10caddf2cebfbfed32 100644 (file)
@@ -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));
index 0e180875933872f8e4c32e0691da65a25b72b9f4..eb6eacd22c85e3f002213ace383f82b212afd276 100644 (file)
@@ -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
 #include <base/smartpointer.h>
 #include <base/logstream.h>
 #include <iomanip>
+#include <iostream>
+#include <vector>
 
+// Provide memory for objects of type T such that access to a deleted
+// object does not cause a segmentation fault
+std::vector<char> 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<Test>       r(&a, "Test R");
       SmartPointer<const Test> s(&a, "const Test S");
 //  SmartPointer<Test>       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
     }
 }
 
index 63bebc7caad9db08bbb7516072808fcc022d7d28..9850c9b96e1b6b8918a2aa175f33a632f21c9527 100644 (file)
@@ -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 (file)
index f6cb286..0000000
+++ /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 (file)
index f6cb286..0000000
+++ /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 (file)
index f6cb286..0000000
+++ /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 (file)
index 03931e2..0000000
+++ /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 (file)
index f6cb286..0000000
+++ /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 (file)
index bc95b82..0000000
+++ /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 <subscriptor.cc> 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 <subscriptor.cc> 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 <subscriptor.cc> 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

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.