Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
More uses of std::make_unique.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Mon, 5 Oct 2020 19:53:43 +0000 (21:53 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Mon, 5 Oct 2020 20:48:32 +0000 (22:48 +0200)
Clang-tidy enabled checks:
    modernize-make-shared
    modernize-make-unique

14 files changed:
src/kernel/context/ContextSwapped.cpp
src/mc/Session.cpp
src/mc/remote/AppSide.cpp
src/mc/remote/RemoteSimulation.cpp
src/mc/sosp/PageStore_test.cpp
src/mc/sosp/Snapshot_test.cpp
src/plugins/file_system/s4u_FileSystem.cpp
src/simix/smx_global.cpp
src/smpi/bindings/smpi_pmpi_coll.cpp
src/smpi/colls/smpi_mpich_selector.cpp
src/smpi/colls/smpi_openmpi_selector.cpp
src/surf/cpu_ti.cpp
src/xbt/PropertyHolder.cpp
src/xbt/random.cpp

index a0d7a4c..bbebfa6 100644 (file)
@@ -12,6 +12,8 @@
 
 #include "src/kernel/context/ContextSwapped.hpp"
 
+#include <memory>
+
 #ifdef _WIN32
 #include <malloc.h>
 #include <windows.h>
@@ -212,8 +214,8 @@ void SwappedContextFactory::run_all()
   if (SIMIX_context_is_parallel()) {
     // We lazily create the parmap so that all options are actually processed when doing so.
     if (parmap_ == nullptr)
-      parmap_.reset(
-          new simgrid::xbt::Parmap<smx_actor_t>(SIMIX_context_get_nthreads(), SIMIX_context_get_parallel_mode()));
+      parmap_ = std::make_unique<simgrid::xbt::Parmap<smx_actor_t>>(SIMIX_context_get_nthreads(),
+                                                                    SIMIX_context_get_parallel_mode());
 
     // Usually, Parmap::apply() executes the provided function on all elements of the array.
     // Here, the executed function does not return the control to the parmap before all the array is processed:
index 04d40a0..0dd3710 100644 (file)
@@ -15,6 +15,8 @@
 #include "xbt/log.h"
 #include "xbt/system_error.hpp"
 
+#include <memory>
+
 #include <fcntl.h>
 #ifdef __linux__
 #include <sys/prctl.h>
@@ -86,7 +88,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::make_unique<simgrid::mc::RemoteSimulation>(pid);
-  model_checker_.reset(new simgrid::mc::ModelChecker(std::move(process), sockets[1]));
+  model_checker_ = std::make_unique<simgrid::mc::ModelChecker>(std::move(process), sockets[1]);
 
   mc_model_checker = model_checker_.get();
   model_checker_->start();
index 21fa56b..6e08bdf 100644 (file)
@@ -10,6 +10,7 @@
 #include <cerrno>
 #include <cstdlib>
 #include <cstring>
+#include <memory>
 #include <sys/ptrace.h>
 #include <sys/socket.h>
 #include <sys/types.h>
@@ -48,7 +49,7 @@ AppSide* AppSide::initialize()
   xbt_assert(type == SOCK_SEQPACKET, "Unexpected socket type %i", type);
   XBT_DEBUG("Model-checked application found expected socket type");
 
-  instance_.reset(new simgrid::mc::AppSide(fd));
+  instance_ = std::make_unique<simgrid::mc::AppSide>(fd);
 
   // Wait for the model-checker:
   errno = 0;
index 078e3ad..b9238aa 100644 (file)
@@ -16,6 +16,8 @@
 #include <libunwind-ptrace.h>
 #include <sys/mman.h> // PROT_*
 
+#include <memory>
+
 using simgrid::mc::remote;
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_process, mc, "MC process information");
@@ -259,7 +261,7 @@ void RemoteSimulation::refresh_heap()
 {
   // Read/dereference/refresh the std_heap pointer:
   if (not this->heap)
-    this->heap.reset(new s_xbt_mheap_t());
+    this->heap = std::make_unique<s_xbt_mheap_t>();
   this->read_bytes(this->heap.get(), sizeof(mdesc), remote(this->heap_address));
   this->cache_flags_ |= RemoteSimulation::cache_heap;
 }
index 4888385..99ff03a 100644 (file)
@@ -49,7 +49,7 @@ int helper_tests::value                        = 0;
 void helper_tests::Init()
 {
   pagesize = (size_t)getpagesize();
-  store.reset(new simgrid::mc::PageStore(50));
+  store    = std::make_unique<simgrid::mc::PageStore>(50);
   data     = mmap(nullptr, getpagesize(), PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
   REQUIRE(store->size() == 0);
 }
index 79b9485..63c114c 100644 (file)
@@ -8,6 +8,7 @@
 #include "src/mc/sosp/Snapshot.hpp"
 
 #include <cstddef>
+#include <memory>
 #include <sys/mman.h>
 #include <xbt/random.hpp>
 
@@ -56,7 +57,7 @@ void snap_test_helper::Init()
   REQUIRE(xbt_pagesize == getpagesize());
   REQUIRE(1 << xbt_pagebits == xbt_pagesize);
 
-  process.reset(new simgrid::mc::RemoteSimulation(getpid()));
+  process = std::make_unique<simgrid::mc::RemoteSimulation>(getpid());
   process->init();
   mc_model_checker = new ::simgrid::mc::ModelChecker(std::move(process), -1);
 }
index 7bdd4ef..628c813 100644 (file)
@@ -16,6 +16,7 @@
 #include <boost/algorithm/string/join.hpp>
 #include <boost/algorithm/string/split.hpp>
 #include <fstream>
+#include <memory>
 #include <numeric>
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_file, s4u, "S4U files");
@@ -107,7 +108,7 @@ File::File(const std::string& fullpath, sg_host_t host, void* userdata) : fullpa
     // assign a file descriptor id to the newly opened File
     FileDescriptorHostExt* ext = host->extension<simgrid::s4u::FileDescriptorHostExt>();
     if (ext->file_descriptor_table == nullptr) {
-      ext->file_descriptor_table.reset(new std::vector<int>(sg_storage_max_file_descriptors));
+      ext->file_descriptor_table = std::make_unique<std::vector<int>>(sg_storage_max_file_descriptors);
       std::iota(ext->file_descriptor_table->rbegin(), ext->file_descriptor_table->rend(), 0); // Fill with ..., 1, 0.
     }
     xbt_assert(not ext->file_descriptor_table->empty(), "Too much files are opened! Some have to be closed.");
index 63bdd27..164ddca 100644 (file)
@@ -24,6 +24,7 @@
 #include "src/mc/remote/AppSide.hpp"
 #endif
 
+#include <memory>
 
 XBT_LOG_NEW_CATEGORY(simix, "All SIMIX categories");
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_kernel, simix, "Logging specific to SIMIX (kernel)");
@@ -285,7 +286,7 @@ void SIMIX_global_init(int *argc, char **argv)
   if (simix_global == nullptr) {
     surf_init(argc, argv); /* Initialize SURF structures */
 
-    simix_global.reset(new simgrid::simix::Global());
+    simix_global           = std::make_unique<simgrid::simix::Global>();
     simix_global->maestro_ = nullptr;
     SIMIX_context_mod_init();
 
index 8df1ea1..f51ad83 100644 (file)
 #include "smpi_op.hpp"
 #include "src/smpi/include/smpi_actor.hpp"
 
+#include <memory>
+
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(smpi_pmpi);
 
   static const void* smpi_get_in_place_buf(const void* inplacebuf, const void* otherbuf,std::unique_ptr<unsigned char[]>& tmp_sendbuf, int count, MPI_Datatype datatype){
   if (inplacebuf == MPI_IN_PLACE) {
-      tmp_sendbuf.reset(new unsigned char[count * datatype->get_extent()]);
-      simgrid::smpi::Datatype::copy(otherbuf, count, datatype, tmp_sendbuf.get(), count, datatype);
+    tmp_sendbuf = std::make_unique<unsigned char[]>(count * datatype->get_extent());
+    simgrid::smpi::Datatype::copy(otherbuf, count, datatype, tmp_sendbuf.get(), count, datatype);
     return tmp_sendbuf.get();
   }else{
     return inplacebuf;
@@ -753,10 +755,10 @@ int PMPI_Ialltoallv(const void* sendbuf, const int* sendcounts, const int* sendd
   std::unique_ptr<int[]> tmp_senddispls;
   const void* real_sendbuf = smpi_get_in_place_buf(sendbuf, recvbuf, tmp_sendbuf, maxsize, MPI_CHAR);
   if (sendbuf == MPI_IN_PLACE) {
-    tmp_sendcounts.reset(new int[size]);
+    tmp_sendcounts = std::make_unique<int[]>(size);
     std::copy(recvcounts, recvcounts + size, tmp_sendcounts.get());
     real_sendcounts = tmp_sendcounts.get();
-    tmp_senddispls.reset(new int[size]);
+    tmp_senddispls  = std::make_unique<int[]>(size);
     std::copy(recvdispls, recvdispls + size, tmp_senddispls.get());
     real_senddispls = tmp_senddispls.get();
     real_sendtype  = recvtype;
@@ -849,13 +851,13 @@ int PMPI_Ialltoallw(const void* sendbuf, const int* sendcounts, const int* sendd
   std::unique_ptr<MPI_Datatype[]> tmp_sendtypes;
   const void* real_sendbuf = smpi_get_in_place_buf(sendbuf, recvbuf, tmp_sendbuf, maxsize, MPI_CHAR);
   if (sendbuf == MPI_IN_PLACE) {
-    tmp_sendcounts.reset(new int[size]);
+    tmp_sendcounts = std::make_unique<int[]>(size);
     std::copy(recvcounts, recvcounts + size, tmp_sendcounts.get());
     real_sendcounts = tmp_sendcounts.get();
-    tmp_senddispls.reset(new int[size]);
+    tmp_senddispls  = std::make_unique<int[]>(size);
     std::copy(recvdispls, recvdispls + size, tmp_senddispls.get());
     real_senddispls = tmp_senddispls.get();
-    tmp_sendtypes.reset(new MPI_Datatype[size]);
+    tmp_sendtypes   = std::make_unique<MPI_Datatype[]>(size);
     std::copy(recvtypes, recvtypes + size, tmp_sendtypes.get());
     real_sendtypes = tmp_sendtypes.get();
   }
index e877a88..ada8d41 100644 (file)
@@ -8,6 +8,8 @@
 
 #include "colls_private.hpp"
 
+#include <memory>
+
 /* This is the default implementation of allreduce. The algorithm is:
 
    Algorithm: MPI_Allreduce
@@ -695,7 +697,7 @@ int scatter__mpich(const void *sbuf, int scount,
 {
   std::unique_ptr<unsigned char[]> tmp_buf;
   if(comm->rank()!=root){
-    tmp_buf.reset(new unsigned char[rcount * rdtype->get_extent()]);
+    tmp_buf = std::make_unique<unsigned char[]>(rcount * rdtype->get_extent());
     sbuf   = tmp_buf.get();
     scount = rcount;
     sdtype = rdtype;
index e5f5e92..ffbcae7 100644 (file)
@@ -8,6 +8,8 @@
 
 #include "colls_private.hpp"
 
+#include <memory>
+
 namespace simgrid {
 namespace smpi {
 
@@ -565,7 +567,7 @@ int scatter__ompi(const void *sbuf, int scount,
         (block_size < small_block_size)) {
       std::unique_ptr<unsigned char[]> tmp_buf;
       if (rank != root) {
-        tmp_buf.reset(new unsigned char[rcount * rdtype->get_extent()]);
+        tmp_buf = std::make_unique<unsigned char[]>(rcount * rdtype->get_extent());
         sbuf   = tmp_buf.get();
         scount = rcount;
         sdtype = rdtype;
index f4035b7..36f54ff 100644 (file)
@@ -10,6 +10,7 @@
 #include "surf/surf.hpp"
 
 #include <algorithm>
+#include <memory>
 
 constexpr double EPSILON = 0.000000001;
 
@@ -238,7 +239,7 @@ CpuTiTmgr::CpuTiTmgr(kernel::profile::Profile* speed_profile, double value) : sp
   for (auto const& val : speed_profile->event_list)
     total_time += val.date_;
 
-  profile_.reset(new CpuTiProfile(speed_profile));
+  profile_   = std::make_unique<CpuTiProfile>(speed_profile);
   last_time_ = total_time;
   total_     = profile_->integrate_simple(0, total_time);
 
index 92f2ff8..cc5a7b4 100644 (file)
@@ -6,6 +6,7 @@
 #include <xbt/PropertyHolder.hpp>
 
 #include <map>
+#include <memory>
 
 namespace simgrid {
 namespace xbt {
@@ -23,7 +24,7 @@ const char* PropertyHolder::get_property(const std::string& key) const
 void PropertyHolder::set_property(const std::string& key, const std::string& value)
 {
   if (not properties_)
-    properties_.reset(new std::unordered_map<std::string, std::string>);
+    properties_ = std::make_unique<std::unordered_map<std::string, std::string>>();
   (*properties_)[key] = value;
 }
 
@@ -31,7 +32,7 @@ void PropertyHolder::set_property(const std::string& key, const std::string& val
 const std::unordered_map<std::string, std::string>* PropertyHolder::get_properties()
 {
   if (not properties_)
-    properties_.reset(new std::unordered_map<std::string, std::string>);
+    properties_ = std::make_unique<std::unordered_map<std::string, std::string>>();
   return properties_.get();
 }
 
@@ -39,7 +40,7 @@ const std::unordered_map<std::string, std::string>* PropertyHolder::get_properti
 template <class Assoc> void PropertyHolder::set_properties(const Assoc& properties)
 {
   if (not properties_)
-    properties_.reset(new std::unordered_map<std::string, std::string>);
+    properties_ = std::make_unique<std::unordered_map<std::string, std::string>>();
   std::unordered_map<std::string, std::string> props(properties.cbegin(), properties.cend());
 #if __cplusplus >= 201703L
   props.merge(properties_);
index 0b552d3..5160ba3 100644 (file)
@@ -107,11 +107,11 @@ static std::unique_ptr<Random> default_random = std::make_unique<XbtRandom>();
 
 void set_implem_xbt()
 {
-  default_random.reset(new XbtRandom);
+  default_random = std::make_unique<XbtRandom>();
 }
 void set_implem_std()
 {
-  default_random.reset(new StdRandom);
+  default_random = std::make_unique<StdRandom>();
 }
 
 void set_mersenne_seed(int seed)