Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
std::array...
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 26 Nov 2020 08:22:37 +0000 (09:22 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 26 Nov 2020 08:22:37 +0000 (09:22 +0100)
src/mc/ModelChecker.cpp
src/mc/remote/AppSide.cpp
src/mc/remote/mc_protocol.h

index 93400ed..e5c642f 100644 (file)
@@ -208,14 +208,15 @@ bool ModelChecker::handle_message(const char* buffer, ssize_t size)
       xbt_assert(size == sizeof(message), "Broken message");
       memcpy(&message, buffer, sizeof(message));
       xbt_assert(not message.callback, "Support for client-side function proposition is not implemented.");
-      XBT_DEBUG("Received symbol: %s", message.name);
+      XBT_DEBUG("Received symbol: %s", message.name.data());
 
       if (property_automaton == nullptr)
         property_automaton = xbt_automaton_new();
 
       const RemoteSimulation* process = &this->get_remote_simulation();
       RemotePtr<int> address          = remote((int*)message.data);
-      xbt::add_proposition(property_automaton, message.name, [process, address]() { return process->read(address); });
+      xbt::add_proposition(property_automaton, message.name.data(),
+                           [process, address]() { return process->read(address); });
 
       break;
     }
index 829a2c7..5dfd6fd 100644 (file)
@@ -208,9 +208,9 @@ void AppSide::declare_symbol(const char* name, int* value) const
 {
   s_mc_message_register_symbol_t message;
   message.type = MessageType::REGISTER_SYMBOL;
-  if (strlen(name) + 1 > sizeof(message.name))
+  if (strlen(name) + 1 > message.name.size())
     xbt_die("Symbol is too long");
-  strncpy(message.name, name, sizeof(message.name));
+  strncpy(message.name.data(), name, message.name.size());
   message.callback = nullptr;
   message.data     = value;
   if (channel_.send(message))
index e620fc6..6afc2a0 100644 (file)
 
 #ifdef __cplusplus
 
-#include "cstdint"
 #include "mc/datatypes.h"
 #include "simgrid/forward.h" // aid_t
+#include <array>
+#include <cstdint>
 
 // ***** Messages
 namespace simgrid {
@@ -44,7 +45,7 @@ enum class MessageType {
 } // namespace mc
 } // namespace simgrid
 
-#define MC_MESSAGE_LENGTH 512
+constexpr unsigned MC_MESSAGE_LENGTH = 512;
 
 /** Basic structure for a MC message
  *
@@ -88,7 +89,7 @@ struct s_mc_message_stack_region_t {
 
 struct s_mc_message_register_symbol_t {
   simgrid::mc::MessageType type;
-  char name[128];
+  std::array<char, 128> name;
   int (*callback)(void*);
   void* data;
 };