Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[sonar] Use "std::make_unique" to construct "std::unique_ptr".
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Fri, 2 Oct 2020 21:44:42 +0000 (23:44 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Fri, 2 Oct 2020 21:44:42 +0000 (23:44 +0200)
12 files changed:
include/xbt/functional.hpp
src/bindings/python/simgrid_python.cpp
src/mc/Session.cpp
src/mc/VisitedState.cpp
src/mc/checker/CommunicationDeterminismChecker.cpp
src/mc/checker/SafetyChecker.cpp
src/mc/inspect/mc_dwarf.cpp
src/plugins/host_dvfs.cpp
src/s4u/s4u_Comm.cpp
src/s4u/s4u_Exec.cpp
src/simix/libsmx.cpp
src/xbt/random.cpp

index e84506f..b2d1043 100644 (file)
@@ -40,7 +40,7 @@ public:
     std::vector<std::string> args = *args_;
     if (not args.empty()) {
       char noarg[] = {'\0'};
-      std::unique_ptr<char* []> argv(new char*[argc + 1]);
+      auto argv    = std::make_unique<char*[]>(argc + 1);
       for (int i = 0; i != argc; ++i)
         argv[i] = args[i].empty() ? noarg : &args[i].front();
       argv[argc] = nullptr;
index f900c97..c92a795 100644 (file)
@@ -153,7 +153,7 @@ PYBIND11_MODULE(simgrid, m)
       .def(py::init([](std::vector<std::string> args) {
         static char noarg[] = {'\0'};
         int argc            = static_cast<int>(args.size());
-        std::unique_ptr<char* []> argv(new char*[argc + 1]);
+        auto argv           = std::make_unique<char*[]>(argc + 1);
         for (int i = 0; i != argc; ++i)
           argv[i] = args[i].empty() ? noarg : &args[i].front();
         argv[argc] = nullptr;
index 71b28fc..04d40a0 100644 (file)
@@ -85,7 +85,7 @@ Session::Session(const std::function<void()>& code)
 
   xbt_assert(mc_model_checker == nullptr, "Did you manage to start the MC twice in this process?");
 
-  auto process = std::unique_ptr<simgrid::mc::RemoteSimulation>(new simgrid::mc::RemoteSimulation(pid));
+  auto process = std::make_unique<simgrid::mc::RemoteSimulation>(pid);
   model_checker_.reset(new simgrid::mc::ModelChecker(std::move(process), sockets[1]));
 
   mc_model_checker = model_checker_.get();
index 2216f07..1f30705 100644 (file)
@@ -47,8 +47,7 @@ void VisitedStates::prune()
 std::unique_ptr<simgrid::mc::VisitedState>
 VisitedStates::addVisitedState(unsigned long state_number, simgrid::mc::State* graph_state, bool compare_snapshots)
 {
-  std::unique_ptr<simgrid::mc::VisitedState> new_state =
-    std::unique_ptr<simgrid::mc::VisitedState>(new VisitedState(state_number));
+  auto new_state             = std::make_unique<simgrid::mc::VisitedState>(state_number);
   graph_state->system_state_ = new_state->system_state;
   XBT_DEBUG("Snapshot %p of visited state %d (exploration stack state %d)", new_state->system_state.get(),
             new_state->num, graph_state->num_);
index 47eb9a2..002b7a2 100644 (file)
@@ -176,7 +176,7 @@ void CommunicationDeterminismChecker::get_comm_pattern(smx_simcall_t request, e_
   const mc::PatternCommunicationList& initial_pattern          = initial_communications_pattern[issuer->get_pid()];
   const std::vector<PatternCommunication*>& incomplete_pattern = incomplete_communications_pattern[issuer->get_pid()];
 
-  std::unique_ptr<PatternCommunication> pattern(new PatternCommunication());
+  auto pattern   = std::make_unique<PatternCommunication>();
   pattern->index = initial_pattern.index_comm + incomplete_pattern.size();
 
   if (call_type == MC_CALL_TYPE_SEND) {
@@ -333,7 +333,7 @@ void CommunicationDeterminismChecker::prepare()
   initial_communications_pattern.resize(maxpid);
   incomplete_communications_pattern.resize(maxpid);
 
-  std::unique_ptr<State> initial_state(new State(++expanded_states_count_));
+  auto initial_state = std::make_unique<State>(++expanded_states_count_);
 
   XBT_DEBUG("********* Start communication determinism verification *********");
 
@@ -451,7 +451,7 @@ void CommunicationDeterminismChecker::real_run()
       mc_model_checker->wait_for_requests();
 
       /* Create the new expanded state */
-      std::unique_ptr<State> next_state(new State(++expanded_states_count_));
+      auto next_state = std::make_unique<State>(++expanded_states_count_);
 
       /* If comm determinism verification, we cannot stop the exploration if some communications are not finished (at
        * least, data are transferred). These communications  are incomplete and they cannot be analyzed and compared
index e4c42d8..48e2ad3 100644 (file)
@@ -135,7 +135,7 @@ void SafetyChecker::run()
     this->get_session().execute(state->transition_);
 
     /* Create the new expanded state (copy the state of MCed into our MCer data) */
-    std::unique_ptr<State> next_state = std::unique_ptr<State>(new State(++expanded_states_count_));
+    auto next_state = std::make_unique<State>(++expanded_states_count_);
 
     if (_sg_mc_termination)
       this->check_non_termination(next_state.get());
@@ -282,7 +282,7 @@ SafetyChecker::SafetyChecker(Session& s) : Checker(s)
 
   XBT_DEBUG("Starting the safety algorithm");
 
-  std::unique_ptr<State> initial_state = std::unique_ptr<State>(new State(++expanded_states_count_));
+  auto initial_state = std::make_unique<State>(++expanded_states_count_);
 
   XBT_DEBUG("**************************************************");
   XBT_DEBUG("Initial state");
index c1620ec..efd6755 100644 (file)
@@ -658,10 +658,10 @@ static std::unique_ptr<simgrid::mc::Variable> MC_die_to_variable(simgrid::mc::Ob
     // No location: do not add it ?
     return nullptr;
 
-  std::unique_ptr<simgrid::mc::Variable> variable = std::unique_ptr<simgrid::mc::Variable>(new simgrid::mc::Variable());
-  variable->id                                    = dwarf_dieoffset(die);
-  variable->global                                = frame == nullptr; // Can be override base on DW_AT_location
-  variable->object_info                           = info;
+  auto variable         = std::make_unique<simgrid::mc::Variable>();
+  variable->id          = dwarf_dieoffset(die);
+  variable->global      = frame == nullptr; // Can be override base on DW_AT_location
+  variable->object_info = info;
 
   const char* name = MC_dwarf_attr_integrate_string(die, DW_AT_name);
   if (name)
index 8082018..dbadd85 100644 (file)
@@ -386,31 +386,25 @@ static void on_host_added(simgrid::s4u::Host& host)
       boost::algorithm::to_lower(dvfs_governor);
     }
 
-    auto governor = [&dvfs_governor, &daemon_proc]() {
+    auto governor = [&dvfs_governor, &daemon_proc]() -> std::unique_ptr<simgrid::plugin::dvfs::Governor> {
       if (dvfs_governor == "conservative") {
-        return std::unique_ptr<simgrid::plugin::dvfs::Governor>(
-            new simgrid::plugin::dvfs::Conservative(daemon_proc->get_host()));
+        return std::make_unique<simgrid::plugin::dvfs::Conservative>(daemon_proc->get_host());
       } else if (dvfs_governor == "ondemand") {
-        return std::unique_ptr<simgrid::plugin::dvfs::Governor>(
-            new simgrid::plugin::dvfs::OnDemand(daemon_proc->get_host()));
+        return std::make_unique<simgrid::plugin::dvfs::OnDemand>(daemon_proc->get_host());
       }
 #if HAVE_SMPI
       else if (dvfs_governor == "adagio") {
-        return std::unique_ptr<simgrid::plugin::dvfs::Governor>(
-            new simgrid::plugin::dvfs::Adagio(daemon_proc->get_host()));
+        return std::make_unique<simgrid::plugin::dvfs::Adagio>(daemon_proc->get_host());
       }
 #endif
       else if (dvfs_governor == "performance") {
-        return std::unique_ptr<simgrid::plugin::dvfs::Governor>(
-            new simgrid::plugin::dvfs::Performance(daemon_proc->get_host()));
+        return std::make_unique<simgrid::plugin::dvfs::Performance>(daemon_proc->get_host());
       } else if (dvfs_governor == "powersave") {
-        return std::unique_ptr<simgrid::plugin::dvfs::Governor>(
-            new simgrid::plugin::dvfs::Powersave(daemon_proc->get_host()));
+        return std::make_unique<simgrid::plugin::dvfs::Powersave>(daemon_proc->get_host());
       } else {
         XBT_CRITICAL("No governor specified for host %s, falling back to Performance",
                      daemon_proc->get_host()->get_cname());
-        return std::unique_ptr<simgrid::plugin::dvfs::Governor>(
-            new simgrid::plugin::dvfs::Performance(daemon_proc->get_host()));
+        return std::make_unique<simgrid::plugin::dvfs::Performance>(daemon_proc->get_host());
       }
     }();
 
index 9141385..46515ea 100644 (file)
@@ -35,7 +35,7 @@ Comm::~Comm()
 
 int Comm::wait_any_for(const std::vector<CommPtr>* comms, double timeout)
 {
-  std::unique_ptr<kernel::activity::CommImpl* []> rcomms(new kernel::activity::CommImpl*[comms->size()]);
+  auto rcomms = std::make_unique<kernel::activity::CommImpl*[]>(comms->size());
   std::transform(begin(*comms), end(*comms), rcomms.get(),
                  [](const CommPtr& comm) { return static_cast<kernel::activity::CommImpl*>(comm->pimpl_.get()); });
   int changed_pos = simcall_comm_waitany(rcomms.get(), comms->size(), timeout);
@@ -198,7 +198,7 @@ Comm* Comm::wait_for(double timeout)
 
 int Comm::test_any(const std::vector<CommPtr>* comms)
 {
-  std::unique_ptr<kernel::activity::CommImpl* []> rcomms(new kernel::activity::CommImpl*[comms->size()]);
+  auto rcomms = std::make_unique<kernel::activity::CommImpl*[]>(comms->size());
   std::transform(begin(*comms), end(*comms), rcomms.get(),
                  [](const CommPtr& comm) { return static_cast<kernel::activity::CommImpl*>(comm->pimpl_.get()); });
   int changed_pos = simcall_comm_testany(rcomms.get(), comms->size());
index 7908468..0b017de 100644 (file)
@@ -42,7 +42,7 @@ Exec* Exec::wait_for(double timeout)
 
 int Exec::wait_any_for(std::vector<ExecPtr>* execs, double timeout)
 {
-  std::unique_ptr<kernel::activity::ExecImpl* []> rexecs(new kernel::activity::ExecImpl*[execs->size()]);
+  auto rexecs = std::make_unique<kernel::activity::ExecImpl*[]>(execs->size());
   std::transform(begin(*execs), end(*execs), rexecs.get(),
                  [](const ExecPtr& exec) { return static_cast<kernel::activity::ExecImpl*>(exec->pimpl_.get()); });
 
index 86e74da..12b03ff 100644 (file)
@@ -184,7 +184,7 @@ simcall_comm_iprobe(smx_mailbox_t mbox, int type, bool (*match_fun)(void*, void*
 unsigned int simcall_comm_waitany(simgrid::kernel::activity::ActivityImplPtr comms[], size_t count,
                                   double timeout) // XBT_ATTRIB_DEPRECATED_v330
 {
-  std::unique_ptr<simgrid::kernel::activity::CommImpl* []> rcomms(new simgrid::kernel::activity::CommImpl*[count]);
+  auto rcomms = std::make_unique<simgrid::kernel::activity::CommImpl*[]>(count);
   std::transform(comms, comms + count, rcomms.get(), [](const simgrid::kernel::activity::ActivityImplPtr& comm) {
     return static_cast<simgrid::kernel::activity::CommImpl*>(comm.get());
   });
@@ -203,7 +203,7 @@ int simcall_comm_testany(simgrid::kernel::activity::ActivityImplPtr comms[], siz
 {
   if (count == 0)
     return -1;
-  std::unique_ptr<simgrid::kernel::activity::CommImpl* []> rcomms(new simgrid::kernel::activity::CommImpl*[count]);
+  auto rcomms = std::make_unique<simgrid::kernel::activity::CommImpl*[]>(count);
   std::transform(comms, comms + count, rcomms.get(), [](const simgrid::kernel::activity::ActivityImplPtr& comm) {
     return static_cast<simgrid::kernel::activity::CommImpl*>(comm.get());
   });
index 7deb41e..0b552d3 100644 (file)
@@ -103,7 +103,7 @@ double XbtRandom::normal(double mean, double sd)
   return z0 * sd + mean;
 }
 
-static std::unique_ptr<Random> default_random(new XbtRandom);
+static std::unique_ptr<Random> default_random = std::make_unique<XbtRandom>();
 
 void set_implem_xbt()
 {