Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Various cleanups.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Sat, 18 Feb 2023 16:39:33 +0000 (17:39 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Sat, 18 Feb 2023 16:39:33 +0000 (17:39 +0100)
src/mc/api/ActorState.hpp
src/mc/api/RemoteApp.cpp
src/mc/api/State.cpp
src/mc/api/State.hpp
src/mc/remote/AppSide.cpp
src/mc/remote/Channel.cpp

index 1265dca..6af8bcc 100644 (file)
@@ -26,7 +26,6 @@ namespace simgrid::mc {
  * is important in cases
  */
 class ActorState {
-
   /**
    * @brief The transitions that the actor is allowed to execute from this
    * state, viz. those that are enabled for this actor
index 0850297..00f34be 100644 (file)
@@ -168,10 +168,7 @@ void RemoteApp::get_actors_status(std::map<aid_t, ActorState>& whereto) const
   //                    <----- send ACTORS_STATUS_REPLY
   //                    <----- send `N` `s_mc_message_actors_status_one_t` structs
   //                    <----- send `M` `s_mc_message_simcall_probe_one_t` structs
-  s_mc_message_t msg;
-  memset(&msg, 0, sizeof msg);
-  msg.type = simgrid::mc::MessageType::ACTORS_STATUS;
-  model_checker_->channel().send(msg);
+  model_checker_->channel().send(MessageType::ACTORS_STATUS);
 
   s_mc_message_actors_status_answer_t answer;
   ssize_t received = model_checker_->channel().receive(answer);
index e6a1659..dfb48f3 100644 (file)
@@ -14,12 +14,10 @@ namespace simgrid::mc {
 
 long State::expended_states_ = 0;
 
-State::State(const RemoteApp& remote_app) : default_transition(std::make_unique<Transition>()), num_(++expended_states_)
+State::State(const RemoteApp& remote_app) : num_(++expended_states_)
 {
   remote_app.get_actors_status(actors_to_run_);
 
-  transition_ = default_transition.get();
-
   /* Stateful model checking */
   if ((_sg_mc_checkpoint > 0 && (num_ % _sg_mc_checkpoint == 0)) || _sg_mc_termination) {
     system_state_ = std::make_shared<simgrid::mc::Snapshot>(num_);
@@ -33,9 +31,6 @@ std::size_t State::count_todo() const
 
 Transition* State::get_transition() const
 {
-  if (transition_ == nullptr) {
-    return default_transition.get();
-  }
   return transition_;
 }
 
index c36eddc..8a7d97e 100644 (file)
@@ -17,6 +17,11 @@ namespace simgrid::mc {
 class XBT_PRIVATE State : public xbt::Extendable<State> {
   static long expended_states_; /* Count total amount of states, for stats */
 
+  /**
+   * @brief An empty transition that leads to this state by default
+   */
+  const std::unique_ptr<Transition> default_transition_ = std::make_unique<Transition>();
+
   /**
    * @brief The outgoing transition: what was the last transition that
    * we took to leave this state?
@@ -25,12 +30,7 @@ class XBT_PRIVATE State : public xbt::Extendable<State> {
    * or a reference to the internal default transition `Transition()` if no transition has been
    * set
    */
-  Transition* transition_ = nullptr;
-
-  /**
-   * @brief An empty transition that leads to this state by default
-   */
-  const std::unique_ptr<Transition> default_transition;
+  Transition* transition_ = default_transition_.get();
 
   /** Sequential state ID (used for debugging) */
   long num_ = 0;
index 80e4c52..b99400f 100644 (file)
@@ -236,6 +236,8 @@ void AppSide::handle_messages() const
     ssize_t received_size = channel_.receive(message_buffer.data(), message_buffer.size());
 
     xbt_assert(received_size >= 0, "Could not receive commands from the model-checker");
+    xbt_assert(static_cast<size_t>(received_size) >= sizeof(s_mc_message_t), "Cannot handle short message (size=%zd)",
+               received_size);
 
     const s_mc_message_t* message = (s_mc_message_t*)message_buffer.data();
     switch (message->type) {
index 1d3c389..556c9b5 100644 (file)
@@ -33,8 +33,8 @@ int Channel::send(const void* message, size_t size) const
     }
   }
 
-  if (is_valid_MessageType(*(int*)message)) {
-    XBT_DEBUG("Sending %s (%lu bytes sent)", to_c_str(*(MessageType*)message), size);
+  if (is_valid_MessageType(*static_cast<const int*>(message))) {
+    XBT_DEBUG("Sending %s (%lu bytes sent)", to_c_str(*static_cast<const MessageType*>(message)), size);
   } else {
     XBT_DEBUG("Sending bytes directly (from address %p) (%lu bytes sent)", message, size);
   }
@@ -46,8 +46,8 @@ ssize_t Channel::receive(void* message, size_t size, bool block) const
 {
   ssize_t res = recv(this->socket_, message, size, block ? 0 : MSG_DONTWAIT);
   if (res != -1) {
-    if (is_valid_MessageType(*(int*)message)) {
-      XBT_DEBUG("Receive %s (requested %lu; received %ld)", to_c_str(*(MessageType*)message), size, res);
+    if (is_valid_MessageType(*static_cast<int*>(message))) {
+      XBT_DEBUG("Receive %s (requested %lu; received %ld)", to_c_str(*static_cast<MessageType*>(message)), size, res);
     } else {
       XBT_DEBUG("Receive %ld bytes", res);
     }