Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Deprecate legacy xbt_ex; kill xbt_errcat_t.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Tue, 2 Jul 2019 13:47:05 +0000 (15:47 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Tue, 2 Jul 2019 14:12:21 +0000 (16:12 +0200)
12 files changed:
include/simgrid/Exception.hpp
include/xbt/ex.h
src/kernel/activity/CommImpl.cpp
src/plugins/vm/VmLiveMigration.cpp
src/s4u/s4u_Engine.cpp
src/simgrid/Exception.cpp
src/simix/smx_deployment.cpp
src/smpi/mpi/smpi_request.cpp
src/xbt/exception.cpp
src/xbt/mmalloc/mfree.c
src/xbt/xbt_replay.cpp
teshsuite/xbt/mmalloc/mmalloc_test.cpp

index a6d40e8..200eb19 100644 (file)
@@ -78,124 +78,80 @@ public:
       : std::runtime_error(std::move(message)), throwpoint_(std::move(throwpoint))
   {
   }
+  ~Exception(); // DO NOT define it here -- see Exception.cpp for a rationale
 
   /** Return the information about where the exception was thrown */
   xbt::ThrowPoint const& throw_point() const { return throwpoint_; }
 
   std::string const resolve_backtrace() const { return throwpoint_.backtrace_.resolve(); }
 
+  /** Allow to carry a value (used by waitall/waitany) */
+  int value = 0;
+
 private:
   xbt::ThrowPoint throwpoint_;
 };
 
-} // namespace simgrid
-
-/** A legacy exception
- *
- *  It is defined by a category and a value within that category (as well as
- *  an optional error message).
- *
- *  This used to be a structure for C exceptions but it has been retrofitted
- *  as a C++ exception and some of its data has been moved in the
- *  @ref WithContextException base class. We should deprecate it and replace it
- *  with either C++ different exceptions or `std::system_error` which already
- *  provides this (category + error code) logic.
- *  TODO ^^
- *
- *  @ingroup XBT_ex_c
- */
-class XBT_PUBLIC xbt_ex : public simgrid::Exception {
-public:
-  /**
-   *
-   * @param throwpoint Throw point (use XBT_THROW_POINT)
-   * @param message    Exception message
-   */
-  xbt_ex(simgrid::xbt::ThrowPoint&& throwpoint, std::string&& message)
-      : simgrid::Exception(std::move(throwpoint), std::move(message))
-  {
-  }
-
-  xbt_ex(const xbt_ex&) = default;
-
-  ~xbt_ex(); // DO NOT define it here -- see ex.cpp for a rationale
-
-  /** Category (what went wrong) */
-  xbt_errcat_t category = unknown_error;
-
-  /** Why did it went wrong */
-  int value = 0;
-};
-
-namespace simgrid {
-
 /** Exception raised when a timeout elapsed */
-class TimeoutError : public xbt_ex {
+class TimeoutError : public Exception {
 public:
   TimeoutError(simgrid::xbt::ThrowPoint&& throwpoint, std::string&& message)
-      : xbt_ex(std::move(throwpoint), std::move(message))
+      : Exception(std::move(throwpoint), std::move(message))
   {
-    category = timeout_error;
   }
 };
 
 /** Exception raised when a host fails */
-class HostFailureException : public xbt_ex {
+class HostFailureException : public Exception {
 public:
   HostFailureException(simgrid::xbt::ThrowPoint&& throwpoint, std::string&& message)
-      : xbt_ex(std::move(throwpoint), std::move(message))
+      : Exception(std::move(throwpoint), std::move(message))
   {
-    category = host_error;
   }
 };
 
 /** Exception raised when a communication fails because of the network or because of the remote host */
-class NetworkFailureException : public xbt_ex {
+class NetworkFailureException : public Exception {
 public:
   NetworkFailureException(simgrid::xbt::ThrowPoint&& throwpoint, std::string&& message)
-      : xbt_ex(std::move(throwpoint), std::move(message))
+      : Exception(std::move(throwpoint), std::move(message))
   {
-    category = network_error;
   }
 };
 
 /** Exception raised when a storage fails */
-class StorageFailureException : public xbt_ex {
+class StorageFailureException : public Exception {
 public:
   StorageFailureException(simgrid::xbt::ThrowPoint&& throwpoint, std::string&& message)
-      : xbt_ex(std::move(throwpoint), std::move(message))
+      : Exception(std::move(throwpoint), std::move(message))
   {
-    category = io_error;
   }
 };
 
 /** Exception raised when a VM fails */
-class VmFailureException : public xbt_ex {
+class VmFailureException : public Exception {
 public:
   VmFailureException(simgrid::xbt::ThrowPoint&& throwpoint, std::string&& message)
-      : xbt_ex(std::move(throwpoint), std::move(message))
+      : Exception(std::move(throwpoint), std::move(message))
   {
-    category = vm_error;
   }
 };
 
 /** Exception raised when something got canceled before completion */
-class CancelException : public xbt_ex {
+class CancelException : public Exception {
 public:
   CancelException(simgrid::xbt::ThrowPoint&& throwpoint, std::string&& message)
-      : xbt_ex(std::move(throwpoint), std::move(message))
+      : Exception(std::move(throwpoint), std::move(message))
   {
-    category = cancel_error;
   }
 };
 
 /** Exception raised when something is going wrong during the simulation tracing */
-class TracingError : public xbt_ex {
+class TracingError : public Exception {
 public:
   TracingError(simgrid::xbt::ThrowPoint&& throwpoint, std::string&& message)
-      : xbt_ex(std::move(throwpoint), std::move(message))
+      : Exception(std::move(throwpoint), std::move(message))
   {
-    category = tracing_error;
   }
 };
 
@@ -239,4 +195,6 @@ private:
 
 } // namespace simgrid
 
+XBT_ATTRIB_DEPRECATED_v327("Please use simgrid::Exception") typedef simgrid::Exception xbt_ex;
+
 #endif
index c37ff47..0cbbb9d 100644 (file)
  *  exactly play nicely together.
  */
 
-/** Categories of errors
- *
- *  This very similar to std::error_catgory and should probably be replaced
- *  by this in the future.
- *
- *  @ingroup XBT_ex_c
- */
-typedef enum {
-  unknown_error = 0,            /**< unknown error */
-  arg_error,                    /**< Invalid argument */
-  bound_error,                  /**< Out of bounds argument */
-  mismatch_error,               /**< The provided ID does not match */
-  not_found_error,              /**< The searched element was not found */
-  system_error,                 /**< a syscall did fail */
-  network_error,                /**< error while sending/receiving data */
-  timeout_error,                /**< not quick enough, dude */
-  cancel_error,                 /**< an action was canceled */
-  thread_error,                 /**< error while [un]locking */
-  host_error,                   /**< host failed */
-  tracing_error,                /**< error during the simulation tracing */
-  io_error,                     /**< disk or file error */
-  vm_error                      /**< vm  error */
-} xbt_errcat_t;
-
 SG_BEGIN_DECL()
 
-/** Get the name of a category
- *  @ingroup XBT_ex_c
- */
-XBT_PUBLIC const char* xbt_ex_catname(xbt_errcat_t cat);
-
 /** Helper function used to throw exceptions in C */
-XBT_ATTRIB_NORETURN XBT_PUBLIC void _xbt_throw(char* message, xbt_errcat_t errcat, int value, const char* file,
-                                               int line, const char* func);
+XBT_ATTRIB_NORETURN XBT_PUBLIC void _xbt_throw(char* message, int value, const char* file, int line, const char* func);
 
 /** Builds and throws an exception
  *  @ingroup XBT_ex_c
  *  @hideinitializer
  */
-#define THROW(c, v)             { _xbt_throw(NULL, (xbt_errcat_t) c, v, __FILE__, __LINE__, __func__); }
+#define THROW(v) _xbt_throw(NULL, v, __FILE__, __LINE__, __func__)
 
 /** Builds and throws an exception with a printf-like formatted message
  *  @ingroup XBT_ex_c
  *  @hideinitializer
  */
-#define THROWF(c, v, ...)       _xbt_throw(bprintf(__VA_ARGS__), (xbt_errcat_t) c, v, __FILE__, __LINE__, __func__)
+#define THROWF(v, ...) _xbt_throw(bprintf(__VA_ARGS__), v, __FILE__, __LINE__, __func__)
 
 XBT_ATTRIB_NORETURN void xbt_throw_impossible(const char* file, int line, const char* func);
 /** Throw an exception because something impossible happened
index bff989f..9031e83 100644 (file)
@@ -691,13 +691,7 @@ void CommImpl::finish()
       // In order to modify the exception we have to rethrow it:
       try {
         std::rethrow_exception(simcall->issuer->exception_);
-      } catch (simgrid::TimeoutError& e) {
-        e.value                     = rank;
-        simcall->issuer->exception_ = std::make_exception_ptr(e);
-      } catch (simgrid::NetworkFailureException& e) {
-        e.value                     = rank;
-        simcall->issuer->exception_ = std::make_exception_ptr(e);
-      } catch (simgrid::CancelException& e) {
+      } catch (simgrid::Exception& e) {
         e.value                     = rank;
         simcall->issuer->exception_ = std::make_exception_ptr(e);
       }
index 08add03..90b5553 100644 (file)
@@ -107,7 +107,7 @@ sg_size_t MigrationTx::sendMigrationData(sg_size_t size, int stage, int stage2_r
       comm = mbox->put_init(msg, size)->set_rate(mig_speed)->wait_for(timeout);
     else
       comm = mbox->put_async(msg, size)->wait_for(timeout);
-  } catch (const xbt_ex&) {
+  } catch (const Exception&) {
     if (comm) {
       sg_size_t remaining = static_cast<sg_size_t>(comm->get_remaining());
       XBT_VERB("timeout (%lf s) in sending_migration_data, remaining %llu bytes of %llu", timeout, remaining, size);
@@ -182,7 +182,7 @@ void MigrationTx::operator()()
     } else if (sent > ramsize)
       XBT_CRITICAL("bug");
 
-  } catch (const xbt_ex&) {
+  } catch (const Exception&) {
     // hostfailure (if you want to know whether this is the SRC or the DST check directly in send_migration_data code)
     // Stop the dirty page tracking an return (there is no memory space to release)
     sg_vm_stop_dirty_page_tracking(vm_);
@@ -222,7 +222,7 @@ void MigrationTx::operator()()
       try {
         XBT_DEBUG("Stage 2, gonna send %llu", updated_size);
         sent = sendMigrationData(updated_size, 2, stage2_round, mig_speed, mig_timeout);
-      } catch (const xbt_ex&) {
+      } catch (const Exception&) {
         // hostfailure (if you want to know whether this is the SRC or the DST check directly in send_migration_data
         // code)
         // Stop the dirty page tracking an return (there is no memory space to release)
@@ -266,7 +266,7 @@ void MigrationTx::operator()()
   try {
     XBT_DEBUG("Stage 3: Gonna send %zu bytes", remaining_size);
     sendMigrationData(remaining_size, 3, 0, mig_speed, -1);
-  } catch (const xbt_ex&) {
+  } catch (const Exception&) {
     // hostfailure (if you want to know whether this is the SRC or the DST check directly in send_migration_data code)
     // Stop the dirty page tracking an return (there is no memory space to release)
     vm_->resume();
index 70e3043..0c124e0 100644 (file)
@@ -89,7 +89,7 @@ void Engine::load_platform(const std::string& platf)
   double start = xbt_os_time();
   try {
     parse_platform_file(platf);
-  } catch (xbt_ex& e) {
+  } catch (const Exception& e) {
     xbt_die("Error while loading %s: %s", platf.c_str(), e.what());
   }
 
index d59d487..ed0a7e9 100644 (file)
@@ -9,6 +9,11 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_context);
 
 namespace simgrid {
 
+// DO NOT define destructors for exceptions in Exception.hpp.
+// Defining it here ensures that the exceptions are defined only in libsimgrid, but not in libsimgrid-java.
+// Doing otherwise naturally breaks things (at least on freebsd with clang).
+
+Exception::~Exception()                         = default;
 ForcefulKillException::~ForcefulKillException() = default;
 
 void ForcefulKillException::do_throw()
index 8468165..422f0a8 100644 (file)
@@ -48,7 +48,7 @@ void SIMIX_launch_application(const std::string& file)
     parse_status = surf_parse();
     surf_parse_close();
     xbt_assert(not parse_status, "Parse error at %s:%d", file.c_str(), surf_parse_lineno);
-  } catch (const xbt_ex&) {
+  } catch (const simgrid::Exception&) {
     XBT_ERROR(
         "Unrecoverable error at %s:%d. The full exception stack follows, in case it helps you to diagnose the problem.",
         file.c_str(), surf_parse_lineno);
index f0a08cc..692567a 100644 (file)
@@ -548,7 +548,7 @@ int Request::test(MPI_Request * request, MPI_Status * status, int* flag) {
     if ((*request)->action_ != nullptr){
       try{
         *flag = simcall_comm_test((*request)->action_);
-      } catch (const xbt_ex&) {
+      } catch (const Exception&) {
         *flag = 0;
         return ret;
       }
@@ -639,7 +639,7 @@ int Request::testany(int count, MPI_Request requests[], int *index, int* flag, M
       simcall_process_sleep(nsleeps*smpi_test_sleep);
     try{
       i = simcall_comm_testany(comms.data(), comms.size()); // The i-th element in comms matches!
-    } catch (const xbt_ex&) {
+    } catch (const Exception&) {
       XBT_DEBUG("Exception in testany");
       return 0;
     }
@@ -905,7 +905,7 @@ int Request::wait(MPI_Request * request, MPI_Status * status)
       try{
         // this is not a detached send
         simcall_comm_wait((*request)->action_, -1.0);
-      } catch (const xbt_ex&) {
+      } catch (const Exception&) {
         XBT_VERB("Request cancelled");
       }
   }
@@ -968,7 +968,7 @@ int Request::waitany(int count, MPI_Request requests[], MPI_Status * status)
       try{
         // this is not a detached send
         i = simcall_comm_waitany(comms.data(), comms.size(), -1);
-      } catch (const xbt_ex&) {
+      } catch (const Exception&) {
         XBT_INFO("request %d cancelled ", i);
         return i;
       }
index b3f4c51..94661db 100644 (file)
 XBT_LOG_EXTERNAL_CATEGORY(xbt);
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_exception, xbt, "Exceptions");
 
-// DO NOT define ~xbt_ex() in exception.hpp.
-// Defining it here ensures that xbt_ex is defined only in libsimgrid, but not in libsimgrid-java.
-// Doing otherwise naturally breaks things (at least on freebsd with clang).
-
-xbt_ex::~xbt_ex() = default;
-
-void _xbt_throw(char* message, xbt_errcat_t errcat, int value, const char* file, int line, const char* func)
+void _xbt_throw(char* message, int value, const char* file, int line, const char* func)
 {
-  xbt_ex e(simgrid::xbt::ThrowPoint(file, line, func, simgrid::xbt::Backtrace(), xbt_procname(), xbt_getpid()),
-           message);
+  simgrid::Exception e(
+      simgrid::xbt::ThrowPoint(file, line, func, simgrid::xbt::Backtrace(), xbt_procname(), xbt_getpid()),
+      message ? message : "");
   xbt_free(message);
-  e.category = errcat;
   e.value    = value;
   throw e;
 }
 
-/** @brief returns a short name for the given exception category */
-const char* xbt_ex_catname(xbt_errcat_t cat)
-{
-  switch (cat) {
-    case unknown_error:
-      return "unknown error";
-    case arg_error:
-      return "invalid argument";
-    case bound_error:
-      return "out of bounds";
-    case mismatch_error:
-      return "mismatch";
-    case not_found_error:
-      return "not found";
-    case system_error:
-      return "system error";
-    case network_error:
-      return "network error";
-    case timeout_error:
-      return "timeout";
-    case cancel_error:
-      return "action canceled";
-    case thread_error:
-      return "thread error";
-    case host_error:
-      return "host failed";
-    case tracing_error:
-      return "tracing error";
-    case io_error:
-      return "io error";
-    case vm_error:
-      return "vm error";
-    default:
-      return "INVALID ERROR";
-  }
-}
-
 namespace simgrid {
 namespace xbt {
 
index e08aba3..411ca29 100644 (file)
@@ -39,12 +39,12 @@ void mfree(struct mdesc *mdp, void *ptr)
   switch (type) {
   case MMALLOC_TYPE_HEAPINFO:
     UNLOCK(mdp);
-    THROWF(system_error, 0, "Asked to free a fragment in a heapinfo block. I'm confused.\n");
+    THROWF(0, "Asked to free a fragment in a heapinfo block. I'm confused.\n");
     break;
 
   case MMALLOC_TYPE_FREE: /* Already free */
     UNLOCK(mdp);
-    THROWF(system_error, 0, "Asked to free a fragment in a block that is already free. I'm puzzled.\n");
+    THROWF(0, "Asked to free a fragment in a block that is already free. I'm puzzled.\n");
     break;
 
   case MMALLOC_TYPE_UNFRAGMENTED:
@@ -163,7 +163,7 @@ void mfree(struct mdesc *mdp, void *ptr)
 
     if( mdp->heapinfo[block].busy_frag.frag_size[frag_nb] == -1){
       UNLOCK(mdp);
-      THROWF(system_error, 0, "Asked to free a fragment that is already free. I'm puzzled\n");
+      THROWF(0, "Asked to free a fragment that is already free. I'm puzzled\n");
     }
 
     if (MC_is_active() && mdp->heapinfo[block].busy_frag.ignore[frag_nb] > 0)
index 7af9758..2c51d9d 100644 (file)
@@ -102,7 +102,7 @@ static void handle_action(ReplayAction& action)
   action_fun function = action_funs.at(action.at(1));
   try {
     function(action);
-  } catch (xbt_ex& e) {
+  } catch (const Exception& e) {
     action.clear();
     xbt_die("Replay error:\n %s", e.what());
   }
index e5ddf72..9b11df4 100644 (file)
@@ -75,7 +75,7 @@ int main(int argc, char**argv)
     mfree(heapA, pointers[i]);
     try {
       mfree(heapA, pointers[i]);
-    } catch (const xbt_ex&) {
+    } catch (const simgrid::Exception&) {
       gotit = true;
     }
     if (not gotit)
@@ -87,7 +87,7 @@ int main(int argc, char**argv)
     bool gotit = false;
     try {
       mfree(heapA, pointers[i]);
-    } catch (const xbt_ex&) {
+    } catch (const simgrid::Exception&) {
       gotit = true;
     }
     if (not gotit)