]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Do not store unnecessary variables. 12695/head
authorWolfgang Bangerth <bangerth@colostate.edu>
Fri, 20 Aug 2021 23:11:54 +0000 (17:11 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Sat, 21 Aug 2021 02:46:19 +0000 (20:46 -0600)
include/deal.II/base/exceptions.h
source/base/exceptions.cc

index a30b345155057a3f6732960e5f33a358c1c8c9a5..9dd446d2573f4b5f9b9010cbbc0f557a93c4d491 100644 (file)
@@ -61,7 +61,7 @@ public:
   /**
    * Destructor.
    */
-  virtual ~ExceptionBase() noexcept override;
+  virtual ~ExceptionBase() noexcept override = default;
 
   /**
    * Copy operator. This operator is deleted since exception objects
@@ -142,13 +142,7 @@ protected:
   const char *exc;
 
   /**
-   * A backtrace to the position where the problem happened, if the system
-   * supports this.
-   */
-  mutable char **stacktrace;
-
-  /**
-   * The number of stacktrace frames that are stored in the previous variable.
+   * The number of stacktrace frames that are stored in the following variable.
    * Zero if the system does not support stack traces.
    */
   int n_stacktrace_frames;
index b04ef3588203b605f841314ddedab102f4f5fcee..37c85104b9916c38038b79505647b1f02a93b84b 100644 (file)
@@ -92,7 +92,6 @@ ExceptionBase::ExceptionBase()
   , function("")
   , cond("")
   , exc("")
-  , stacktrace(nullptr)
   , n_stacktrace_frames(0)
   , what_str("")
 {
@@ -109,7 +108,6 @@ ExceptionBase::ExceptionBase(const ExceptionBase &exc)
   , function(exc.function)
   , cond(exc.cond)
   , exc(exc.exc)
-  , stacktrace(nullptr)
   , n_stacktrace_frames(exc.n_stacktrace_frames)
   , what_str("") // don't copy the error message, it gets generated dynamically
                  // by what()
@@ -126,14 +124,6 @@ ExceptionBase::ExceptionBase(const ExceptionBase &exc)
 
 
 
-ExceptionBase::~ExceptionBase() noexcept
-{
-  free(stacktrace); // free(nullptr) is allowed
-  stacktrace = nullptr;
-}
-
-
-
 void
 ExceptionBase::set_fields(const char *f,
                           const int   l,
@@ -164,19 +154,7 @@ ExceptionBase::what() const noexcept
 {
   // If no error c_string was generated so far, do it now:
   if (what_str.empty())
-    {
-#ifdef DEAL_II_HAVE_GLIBC_STACKTRACE
-      // We have deferred the symbol lookup to this point to avoid costly
-      // runtime penalties due to linkage of external libraries by
-      // backtrace_symbols.
-
-      // first delete old stacktrace if necessary
-      free(stacktrace); // free(nullptr) is allowed
-      stacktrace = backtrace_symbols(raw_stacktrace, n_stacktrace_frames);
-#endif
-
-      generate_message();
-    }
+    generate_message();
 
   return what_str.c_str();
 }
@@ -240,6 +218,15 @@ ExceptionBase::print_stack_trace(std::ostream &out) const
   if (deal_II_exceptions::internals::show_stacktrace == false)
     return;
 
+  char **stacktrace = nullptr;
+#ifdef DEAL_II_HAVE_GLIBC_STACKTRACE
+  // We have deferred the symbol lookup to this point to avoid costly
+  // runtime penalties due to linkage of external libraries by
+  // backtrace_symbols.
+  stacktrace = backtrace_symbols(raw_stacktrace, n_stacktrace_frames);
+#endif
+
+
   // if there is a stackframe stored, print it
   out << std::endl;
   out << "Stacktrace:" << std::endl << "-----------" << std::endl;
@@ -316,6 +303,9 @@ ExceptionBase::print_stack_trace(std::ostream &out) const
       if (functionname == "main")
         break;
     }
+
+  free(stacktrace); // free(nullptr) is allowed
+  stacktrace = nullptr;
 }
 
 

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.