From e63c67321577f0816604fe730cd0bc856970454d Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Mon, 5 Oct 2020 21:53:43 +0200 Subject: [PATCH] More uses of std::make_unique. Clang-tidy enabled checks: modernize-make-shared modernize-make-unique --- src/kernel/context/ContextSwapped.cpp | 6 ++++-- src/mc/Session.cpp | 4 +++- src/mc/remote/AppSide.cpp | 3 ++- src/mc/remote/RemoteSimulation.cpp | 4 +++- src/mc/sosp/PageStore_test.cpp | 2 +- src/mc/sosp/Snapshot_test.cpp | 3 ++- src/plugins/file_system/s4u_FileSystem.cpp | 3 ++- src/simix/smx_global.cpp | 3 ++- src/smpi/bindings/smpi_pmpi_coll.cpp | 16 +++++++++------- src/smpi/colls/smpi_mpich_selector.cpp | 4 +++- src/smpi/colls/smpi_openmpi_selector.cpp | 4 +++- src/surf/cpu_ti.cpp | 3 ++- src/xbt/PropertyHolder.cpp | 7 ++++--- src/xbt/random.cpp | 4 ++-- 14 files changed, 42 insertions(+), 24 deletions(-) diff --git a/src/kernel/context/ContextSwapped.cpp b/src/kernel/context/ContextSwapped.cpp index a0d7a4cd98..bbebfa6c31 100644 --- a/src/kernel/context/ContextSwapped.cpp +++ b/src/kernel/context/ContextSwapped.cpp @@ -12,6 +12,8 @@ #include "src/kernel/context/ContextSwapped.hpp" +#include + #ifdef _WIN32 #include #include @@ -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(SIMIX_context_get_nthreads(), SIMIX_context_get_parallel_mode())); + parmap_ = std::make_unique>(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: diff --git a/src/mc/Session.cpp b/src/mc/Session.cpp index 04d40a0eb0..0dd371035a 100644 --- a/src/mc/Session.cpp +++ b/src/mc/Session.cpp @@ -15,6 +15,8 @@ #include "xbt/log.h" #include "xbt/system_error.hpp" +#include + #include #ifdef __linux__ #include @@ -86,7 +88,7 @@ Session::Session(const std::function& code) xbt_assert(mc_model_checker == nullptr, "Did you manage to start the MC twice in this process?"); auto process = std::make_unique(pid); - model_checker_.reset(new simgrid::mc::ModelChecker(std::move(process), sockets[1])); + model_checker_ = std::make_unique(std::move(process), sockets[1]); mc_model_checker = model_checker_.get(); model_checker_->start(); diff --git a/src/mc/remote/AppSide.cpp b/src/mc/remote/AppSide.cpp index 21fa56bb9e..6e08bdfa3d 100644 --- a/src/mc/remote/AppSide.cpp +++ b/src/mc/remote/AppSide.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -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(fd); // Wait for the model-checker: errno = 0; diff --git a/src/mc/remote/RemoteSimulation.cpp b/src/mc/remote/RemoteSimulation.cpp index 078e3ad37b..b9238aad60 100644 --- a/src/mc/remote/RemoteSimulation.cpp +++ b/src/mc/remote/RemoteSimulation.cpp @@ -16,6 +16,8 @@ #include #include // PROT_* +#include + 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(); this->read_bytes(this->heap.get(), sizeof(mdesc), remote(this->heap_address)); this->cache_flags_ |= RemoteSimulation::cache_heap; } diff --git a/src/mc/sosp/PageStore_test.cpp b/src/mc/sosp/PageStore_test.cpp index 4888385a72..99ff03aef3 100644 --- a/src/mc/sosp/PageStore_test.cpp +++ b/src/mc/sosp/PageStore_test.cpp @@ -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(50); data = mmap(nullptr, getpagesize(), PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); REQUIRE(store->size() == 0); } diff --git a/src/mc/sosp/Snapshot_test.cpp b/src/mc/sosp/Snapshot_test.cpp index 79b9485b8c..63c114cdde 100644 --- a/src/mc/sosp/Snapshot_test.cpp +++ b/src/mc/sosp/Snapshot_test.cpp @@ -8,6 +8,7 @@ #include "src/mc/sosp/Snapshot.hpp" #include +#include #include #include @@ -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(getpid()); process->init(); mc_model_checker = new ::simgrid::mc::ModelChecker(std::move(process), -1); } diff --git a/src/plugins/file_system/s4u_FileSystem.cpp b/src/plugins/file_system/s4u_FileSystem.cpp index 7bdd4efe37..628c813a7c 100644 --- a/src/plugins/file_system/s4u_FileSystem.cpp +++ b/src/plugins/file_system/s4u_FileSystem.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include 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(); if (ext->file_descriptor_table == nullptr) { - ext->file_descriptor_table.reset(new std::vector(sg_storage_max_file_descriptors)); + ext->file_descriptor_table = std::make_unique>(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."); diff --git a/src/simix/smx_global.cpp b/src/simix/smx_global.cpp index 63bdd27ace..164ddcac32 100644 --- a/src/simix/smx_global.cpp +++ b/src/simix/smx_global.cpp @@ -24,6 +24,7 @@ #include "src/mc/remote/AppSide.hpp" #endif +#include 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(); simix_global->maestro_ = nullptr; SIMIX_context_mod_init(); diff --git a/src/smpi/bindings/smpi_pmpi_coll.cpp b/src/smpi/bindings/smpi_pmpi_coll.cpp index 8df1ea1303..f51ad833d6 100644 --- a/src/smpi/bindings/smpi_pmpi_coll.cpp +++ b/src/smpi/bindings/smpi_pmpi_coll.cpp @@ -11,12 +11,14 @@ #include "smpi_op.hpp" #include "src/smpi/include/smpi_actor.hpp" +#include + XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(smpi_pmpi); static const void* smpi_get_in_place_buf(const void* inplacebuf, const void* otherbuf,std::unique_ptr& 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(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 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(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(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 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(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(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(size); std::copy(recvtypes, recvtypes + size, tmp_sendtypes.get()); real_sendtypes = tmp_sendtypes.get(); } diff --git a/src/smpi/colls/smpi_mpich_selector.cpp b/src/smpi/colls/smpi_mpich_selector.cpp index e877a88155..ada8d418a0 100644 --- a/src/smpi/colls/smpi_mpich_selector.cpp +++ b/src/smpi/colls/smpi_mpich_selector.cpp @@ -8,6 +8,8 @@ #include "colls_private.hpp" +#include + /* 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 tmp_buf; if(comm->rank()!=root){ - tmp_buf.reset(new unsigned char[rcount * rdtype->get_extent()]); + tmp_buf = std::make_unique(rcount * rdtype->get_extent()); sbuf = tmp_buf.get(); scount = rcount; sdtype = rdtype; diff --git a/src/smpi/colls/smpi_openmpi_selector.cpp b/src/smpi/colls/smpi_openmpi_selector.cpp index e5f5e92e7f..ffbcae7657 100644 --- a/src/smpi/colls/smpi_openmpi_selector.cpp +++ b/src/smpi/colls/smpi_openmpi_selector.cpp @@ -8,6 +8,8 @@ #include "colls_private.hpp" +#include + namespace simgrid { namespace smpi { @@ -565,7 +567,7 @@ int scatter__ompi(const void *sbuf, int scount, (block_size < small_block_size)) { std::unique_ptr tmp_buf; if (rank != root) { - tmp_buf.reset(new unsigned char[rcount * rdtype->get_extent()]); + tmp_buf = std::make_unique(rcount * rdtype->get_extent()); sbuf = tmp_buf.get(); scount = rcount; sdtype = rdtype; diff --git a/src/surf/cpu_ti.cpp b/src/surf/cpu_ti.cpp index f4035b7603..36f54ff726 100644 --- a/src/surf/cpu_ti.cpp +++ b/src/surf/cpu_ti.cpp @@ -10,6 +10,7 @@ #include "surf/surf.hpp" #include +#include 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(speed_profile); last_time_ = total_time; total_ = profile_->integrate_simple(0, total_time); diff --git a/src/xbt/PropertyHolder.cpp b/src/xbt/PropertyHolder.cpp index 92f2ff88ad..cc5a7b4b77 100644 --- a/src/xbt/PropertyHolder.cpp +++ b/src/xbt/PropertyHolder.cpp @@ -6,6 +6,7 @@ #include #include +#include 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); + properties_ = std::make_unique>(); (*properties_)[key] = value; } @@ -31,7 +32,7 @@ void PropertyHolder::set_property(const std::string& key, const std::string& val const std::unordered_map* PropertyHolder::get_properties() { if (not properties_) - properties_.reset(new std::unordered_map); + properties_ = std::make_unique>(); return properties_.get(); } @@ -39,7 +40,7 @@ const std::unordered_map* PropertyHolder::get_properti template void PropertyHolder::set_properties(const Assoc& properties) { if (not properties_) - properties_.reset(new std::unordered_map); + properties_ = std::make_unique>(); std::unordered_map props(properties.cbegin(), properties.cend()); #if __cplusplus >= 201703L props.merge(properties_); diff --git a/src/xbt/random.cpp b/src/xbt/random.cpp index 0b552d3aed..5160ba3c7f 100644 --- a/src/xbt/random.cpp +++ b/src/xbt/random.cpp @@ -107,11 +107,11 @@ static std::unique_ptr default_random = std::make_unique(); void set_implem_xbt() { - default_random.reset(new XbtRandom); + default_random = std::make_unique(); } void set_implem_std() { - default_random.reset(new StdRandom); + default_random = std::make_unique(); } void set_mersenne_seed(int seed) -- 2.20.1