From 7dd253f0ff4dda733dd0f7c924a25df4b777f0d0 Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Mon, 23 Dec 2019 23:46:44 +0100 Subject: [PATCH] [sonar] Constify pointer and reference local variables in src/kernel/. --- src/kernel/activity/IoImpl.cpp | 2 +- src/kernel/activity/MailboxImpl.cpp | 2 +- src/kernel/activity/SleepImpl.cpp | 2 +- src/kernel/context/ContextRaw.cpp | 6 +++--- src/kernel/context/ContextSwapped.cpp | 2 +- src/kernel/context/ContextUnix.cpp | 6 +++--- src/kernel/lmm/fair_bottleneck.cpp | 8 ++++---- src/kernel/lmm/maxmin.cpp | 6 +++--- src/kernel/resource/profile/Profile.cpp | 2 +- src/kernel/routing/ClusterZone.cpp | 4 ++-- src/kernel/routing/DijkstraZone.cpp | 10 +++++----- src/kernel/routing/FloydZone.cpp | 2 +- src/kernel/routing/FullZone.cpp | 2 +- src/kernel/routing/NetZoneImpl.cpp | 10 +++++----- src/kernel/routing/RoutedZone.cpp | 6 +++--- 15 files changed, 35 insertions(+), 35 deletions(-) diff --git a/src/kernel/activity/IoImpl.cpp b/src/kernel/activity/IoImpl.cpp index 8472157856..d9d5719ed2 100644 --- a/src/kernel/activity/IoImpl.cpp +++ b/src/kernel/activity/IoImpl.cpp @@ -134,7 +134,7 @@ void IoImpl::post() void IoImpl::finish() { while (not simcalls_.empty()) { - smx_simcall_t simcall = simcalls_.front(); + const s_smx_simcall* simcall = simcalls_.front(); simcalls_.pop_front(); switch (state_) { case State::DONE: diff --git a/src/kernel/activity/MailboxImpl.cpp b/src/kernel/activity/MailboxImpl.cpp index 8915ec71de..855b3546f5 100644 --- a/src/kernel/activity/MailboxImpl.cpp +++ b/src/kernel/activity/MailboxImpl.cpp @@ -130,7 +130,7 @@ CommImplPtr MailboxImpl::find_matching_comm(CommImpl::Type type, bool (*match_fu auto& comm_queue = done ? done_comm_queue_ : comm_queue_; for (auto it = comm_queue.begin(); it != comm_queue.end(); it++) { - CommImplPtr& comm = *it; + const CommImplPtr& comm = *it; if (comm->type_ == CommImpl::Type::SEND) { other_user_data = comm->src_data_; diff --git a/src/kernel/activity/SleepImpl.cpp b/src/kernel/activity/SleepImpl.cpp index 8a3eb18588..9b5be40734 100644 --- a/src/kernel/activity/SleepImpl.cpp +++ b/src/kernel/activity/SleepImpl.cpp @@ -55,7 +55,7 @@ void SleepImpl::post() void SleepImpl::finish() { while (not simcalls_.empty()) { - smx_simcall_t simcall = simcalls_.front(); + const s_smx_simcall* simcall = simcalls_.front(); simcalls_.pop_front(); simcall->issuer_->waiting_synchro = nullptr; diff --git a/src/kernel/context/ContextRaw.cpp b/src/kernel/context/ContextRaw.cpp index d493caec6e..09e9560d83 100644 --- a/src/kernel/context/ContextRaw.cpp +++ b/src/kernel/context/ContextRaw.cpp @@ -224,10 +224,10 @@ void RawContext::wrapper(RawContext* context) void RawContext::swap_into(SwappedContext* to_) { - RawContext* to = static_cast(to_); + const RawContext* to = static_cast(to_); ASAN_ONLY(void* fake_stack = nullptr); - ASAN_ONLY(to->asan_ctx_ = this); - ASAN_START_SWITCH(this->asan_stop_ ? nullptr : &fake_stack, to->asan_stack_, to->asan_stack_size_); + ASAN_ONLY(to_->asan_ctx_ = this); + ASAN_START_SWITCH(this->asan_stop_ ? nullptr : &fake_stack, to_->asan_stack_, to_->asan_stack_size_); raw_swapcontext(&this->stack_top_, to->stack_top_); ASAN_FINISH_SWITCH(fake_stack, &this->asan_ctx_->asan_stack_, &this->asan_ctx_->asan_stack_size_); } diff --git a/src/kernel/context/ContextSwapped.cpp b/src/kernel/context/ContextSwapped.cpp index a629281d3f..e2ca4165ff 100644 --- a/src/kernel/context/ContextSwapped.cpp +++ b/src/kernel/context/ContextSwapped.cpp @@ -172,7 +172,7 @@ void SwappedContextFactory::run_all() return; /* maestro is already saved in the first slot of workers_context_ */ - smx_actor_t first_actor = simix_global->actors_to_run.front(); + const actor::ActorImpl* first_actor = simix_global->actors_to_run.front(); process_index_ = 1; /* execute the first actor; it will chain to the others when using suspend() */ static_cast(first_actor->context_.get())->resume(); diff --git a/src/kernel/context/ContextUnix.cpp b/src/kernel/context/ContextUnix.cpp index fba49bf5e5..3cacf6dc67 100644 --- a/src/kernel/context/ContextUnix.cpp +++ b/src/kernel/context/ContextUnix.cpp @@ -91,10 +91,10 @@ UContext::UContext(std::function&& code, actor::ActorImpl* actor, Swappe void UContext::swap_into(SwappedContext* to_) { - UContext* to = static_cast(to_); + const UContext* to = static_cast(to_); ASAN_ONLY(void* fake_stack = nullptr); - ASAN_ONLY(to->asan_ctx_ = this); - ASAN_START_SWITCH(this->asan_stop_ ? nullptr : &fake_stack, to->asan_stack_, to->asan_stack_size_); + ASAN_ONLY(to_->asan_ctx_ = this); + ASAN_START_SWITCH(this->asan_stop_ ? nullptr : &fake_stack, to_->asan_stack_, to_->asan_stack_size_); swapcontext(&this->uc_, &to->uc_); ASAN_FINISH_SWITCH(fake_stack, &this->asan_ctx_->asan_stack_, &this->asan_ctx_->asan_stack_size_); } diff --git a/src/kernel/lmm/fair_bottleneck.cpp b/src/kernel/lmm/fair_bottleneck.cpp index 1db07048bf..e19ef33a17 100644 --- a/src/kernel/lmm/fair_bottleneck.cpp +++ b/src/kernel/lmm/fair_bottleneck.cpp @@ -67,7 +67,7 @@ void simgrid::kernel::lmm::FairBottleneck::bottleneck_solve() int nb = 0; XBT_DEBUG("Processing cnst %p ", &cnst); cnst.usage_ = 0.0; - for (Element& elem : cnst.enabled_element_set_) { + for (const Element& elem : cnst.enabled_element_set_) { xbt_assert(elem.variable->sharing_penalty_ > 0); if (elem.consumption_weight > 0 && elem.variable->saturated_variable_set_hook_.is_linked()) nb++; @@ -108,14 +108,14 @@ void simgrid::kernel::lmm::FairBottleneck::bottleneck_solve() Constraint& cnst = *iter; XBT_DEBUG("Updating cnst %p ", &cnst); if (cnst.sharing_policy_ != s4u::Link::SharingPolicy::FATPIPE) { - for (Element& elem : cnst.enabled_element_set_) { + for (const Element& elem : cnst.enabled_element_set_) { xbt_assert(elem.variable->sharing_penalty_ > 0); XBT_DEBUG("\tUpdate constraint %p (%g) with variable %p by %g", &cnst, cnst.remaining_, elem.variable, elem.variable->mu_); double_update(&cnst.remaining_, elem.consumption_weight * elem.variable->mu_, sg_maxmin_precision); } } else { - for (Element& elem : cnst.enabled_element_set_) { + for (const Element& elem : cnst.enabled_element_set_) { xbt_assert(elem.variable->sharing_penalty_ > 0); XBT_DEBUG("\tNon-Shared variable. Update constraint usage of %p (%g) with variable %p by %g", &cnst, cnst.usage_, elem.variable, elem.variable->mu_); @@ -130,7 +130,7 @@ void simgrid::kernel::lmm::FairBottleneck::bottleneck_solve() XBT_DEBUG("\tGet rid of constraint %p", &cnst); iter = cnst_list.erase(iter); - for (Element& elem : cnst.enabled_element_set_) { + for (const Element& elem : cnst.enabled_element_set_) { if (elem.variable->sharing_penalty_ <= 0) break; if (elem.consumption_weight > 0 && elem.variable->saturated_variable_set_hook_.is_linked()) { diff --git a/src/kernel/lmm/maxmin.cpp b/src/kernel/lmm/maxmin.cpp index d0a9f1f01e..b082826fcc 100644 --- a/src/kernel/lmm/maxmin.cpp +++ b/src/kernel/lmm/maxmin.cpp @@ -227,7 +227,7 @@ void System::expand(Constraint* cnst, Variable* var, double consumption_weight) // If it does, subtract it from the required slack int current_share = 0; if (var->concurrency_share_ > 1) { - for (Element& elem : var->cnsts_) { + for (const Element& elem : var->cnsts_) { if (elem.constraint == cnst && elem.enabled_element_set_hook.is_linked()) current_share += elem.get_concurrency(); } @@ -402,7 +402,7 @@ static inline void saturated_variable_set_update(ConstraintLight* cnst_light_tab /* Add active variables (i.e. variables that need to be set) from the set of constraints to saturate * (cnst_light_tab)*/ for (int const& saturated_cnst : saturated_constraints) { - ConstraintLight& cnst = cnst_light_tab[saturated_cnst]; + const ConstraintLight& cnst = cnst_light_tab[saturated_cnst]; for (Element const& elem : cnst.cnst->active_element_set_) { xbt_assert(elem.variable->sharing_penalty_ > 0); // All elements of active_element_set should be active if (elem.consumption_weight > 0 && not elem.variable->saturated_variable_set_hook_.is_linked()) @@ -607,7 +607,7 @@ template void System::lmm_solve(CnstList& cnst_list) // Remember: non-shared constraints only require that max(elem.value * var.value) < cnst->bound cnst->usage_ = 0.0; elem.make_inactive(); - for (Element& elem2 : cnst->enabled_element_set_) { + for (const Element& elem2 : cnst->enabled_element_set_) { xbt_assert(elem2.variable->sharing_penalty_ > 0); if (elem2.variable->value_ > 0) continue; diff --git a/src/kernel/resource/profile/Profile.cpp b/src/kernel/resource/profile/Profile.cpp index 482ee82d3c..6b882039db 100644 --- a/src/kernel/resource/profile/Profile.cpp +++ b/src/kernel/resource/profile/Profile.cpp @@ -117,7 +117,7 @@ Profile* Profile::from_file(const std::string& path) xbt_assert(not path.empty(), "Cannot parse a trace from an empty filename"); xbt_assert(trace_list.find(path) == trace_list.end(), "Refusing to define trace %s twice", path.c_str()); - std::ifstream* f = surf_ifsopen(path); + const std::ifstream* f = surf_ifsopen(path); xbt_assert(not f->fail(), "Cannot open file '%s' (path=%s)", path.c_str(), (boost::join(surf_path, ":")).c_str()); std::stringstream buffer; diff --git a/src/kernel/routing/ClusterZone.cpp b/src/kernel/routing/ClusterZone.cpp index 96345afb7a..7ff40dced9 100644 --- a/src/kernel/routing/ClusterZone.cpp +++ b/src/kernel/routing/ClusterZone.cpp @@ -134,8 +134,8 @@ void ClusterZone::create_links_for_node(ClusterCreationArgs* cluster, int id, in link.policy = cluster->sharing_policy; sg_platf_new_link(&link); - s4u::Link* linkUp; - s4u::Link* linkDown; + const s4u::Link* linkUp; + const s4u::Link* linkDown; if (link.policy == simgrid::s4u::Link::SharingPolicy::SPLITDUPLEX) { linkUp = s4u::Link::by_name(link_id + "_UP"); linkDown = s4u::Link::by_name(link_id + "_DOWN"); diff --git a/src/kernel/routing/DijkstraZone.cpp b/src/kernel/routing/DijkstraZone.cpp index a5ad4b57ad..2694cdff9d 100644 --- a/src/kernel/routing/DijkstraZone.cpp +++ b/src/kernel/routing/DijkstraZone.cpp @@ -125,7 +125,7 @@ void DijkstraZone::get_local_route(NetPoint* src, NetPoint* dst, RouteCreationAr if (edge == nullptr) throw std::invalid_argument(xbt::string_printf("No route from '%s' to '%s'", src->get_cname(), dst->get_cname())); - RouteCreationArgs* e_route = static_cast(xbt_graph_edge_get_data(edge)); + const RouteCreationArgs* e_route = static_cast(xbt_graph_edge_get_data(edge)); for (auto const& link : e_route->link_list) { route->link_list.insert(route->link_list.begin(), link); @@ -168,9 +168,9 @@ void DijkstraZone::get_local_route(NetPoint* src, NetPoint* dst, RouteCreationAr xbt_dynar_foreach (xbt_graph_node_get_outedges(v_node), cursor, edge) { xbt_node_t u_node = xbt_graph_edge_get_target(edge); - GraphNodeData* data = static_cast(xbt_graph_node_get_data(u_node)); + const GraphNodeData* data = static_cast(xbt_graph_node_get_data(u_node)); int u_id = data->graph_id_; - RouteCreationArgs* tmp_e_route = static_cast(xbt_graph_edge_get_data(edge)); + const RouteCreationArgs* tmp_e_route = static_cast(xbt_graph_edge_get_data(edge)); int cost_v_u = tmp_e_route->link_list.size(); /* count of links, old model assume 1 */ if (cost_v_u + cost_arr[v_id] < cost_arr[u_id]) { @@ -194,9 +194,9 @@ void DijkstraZone::get_local_route(NetPoint* src, NetPoint* dst, RouteCreationAr if (edge == nullptr) throw std::invalid_argument(xbt::string_printf("No route from '%s' to '%s'", src->get_cname(), dst->get_cname())); - RouteCreationArgs* e_route = static_cast(xbt_graph_edge_get_data(edge)); + const RouteCreationArgs* e_route = static_cast(xbt_graph_edge_get_data(edge)); - NetPoint* prev_gw_src = gw_src; + const NetPoint* prev_gw_src = gw_src; gw_src = e_route->gw_src; NetPoint* gw_dst = e_route->gw_dst; diff --git a/src/kernel/routing/FloydZone.cpp b/src/kernel/routing/FloydZone.cpp index d9b7ab832b..4a7a7aad7e 100644 --- a/src/kernel/routing/FloydZone.cpp +++ b/src/kernel/routing/FloydZone.cpp @@ -67,7 +67,7 @@ void FloydZone::get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs* NetPoint* prev_dst_gw = nullptr; while (not route_stack.empty()) { - RouteCreationArgs* e_route = route_stack.back(); + const RouteCreationArgs* e_route = route_stack.back(); route_stack.pop_back(); if (hierarchy_ == RoutingMode::recursive && prev_dst_gw != nullptr && prev_dst_gw->get_cname() != e_route->gw_src->get_cname()) { diff --git a/src/kernel/routing/FullZone.cpp b/src/kernel/routing/FullZone.cpp index 779c949776..9438f2351f 100644 --- a/src/kernel/routing/FullZone.cpp +++ b/src/kernel/routing/FullZone.cpp @@ -59,7 +59,7 @@ void FullZone::get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs* XBT_DEBUG("full getLocalRoute from %s[%u] to %s[%u]", src->get_cname(), src->id(), dst->get_cname(), dst->id()); unsigned int table_size = get_table_size(); - RouteCreationArgs* e_route = TO_ROUTE_FULL(src->id(), dst->id()); + const RouteCreationArgs* e_route = TO_ROUTE_FULL(src->id(), dst->id()); if (e_route != nullptr) { res->gw_src = e_route->gw_src; diff --git a/src/kernel/routing/NetZoneImpl.cpp b/src/kernel/routing/NetZoneImpl.cpp index 1fa94750af..830f11350b 100644 --- a/src/kernel/routing/NetZoneImpl.cpp +++ b/src/kernel/routing/NetZoneImpl.cpp @@ -85,7 +85,7 @@ int NetZoneImpl::get_host_count() { int count = 0; for (auto const& card : get_vertices()) { - s4u::Host* host = simgrid::s4u::Host::by_name_or_null(card->get_name()); + const s4u::Host* host = simgrid::s4u::Host::by_name_or_null(card->get_name()); if (host != nullptr) count++; } @@ -218,8 +218,8 @@ static void find_common_ancestors(NetPoint* src, NetPoint* dst, /* engage the full recursive search */ /* (1) find the path to root of src and dst*/ - NetZoneImpl* src_as = src->get_englobing_zone(); - NetZoneImpl* dst_as = dst->get_englobing_zone(); + const NetZoneImpl* src_as = src->get_englobing_zone(); + const NetZoneImpl* dst_as = dst->get_englobing_zone(); xbt_assert(src_as, "Host %s must be in a netzone", src->get_cname()); xbt_assert(dst_as, "Host %s must be in a netzone", dst->get_cname()); @@ -273,7 +273,7 @@ bool NetZoneImpl::get_bypass_route(routing::NetPoint* src, routing::NetPoint* ds /* Base case, no recursion is needed */ if (dst->get_englobing_zone() == this && src->get_englobing_zone() == this) { if (bypass_routes_.find({src, dst}) != bypass_routes_.end()) { - BypassRoute* bypassedRoute = bypass_routes_.at({src, dst}); + const BypassRoute* bypassedRoute = bypass_routes_.at({src, dst}); for (resource::LinkImpl* const& link : bypassedRoute->links) { links.push_back(link); if (latency) @@ -316,7 +316,7 @@ bool NetZoneImpl::get_bypass_route(routing::NetPoint* src, routing::NetPoint* ds int max_index = std::max(max_index_src, max_index_dst); /* (3) Search for a bypass making the path up to the ancestor useless */ - BypassRoute* bypassedRoute = nullptr; + const BypassRoute* bypassedRoute = nullptr; std::pair key; for (int max = 0; max <= max_index; max++) { for (int i = 0; i < max; i++) { diff --git a/src/kernel/routing/RoutedZone.cpp b/src/kernel/routing/RoutedZone.cpp index dff7174aaf..135b6246d3 100644 --- a/src/kernel/routing/RoutedZone.cpp +++ b/src/kernel/routing/RoutedZone.cpp @@ -19,7 +19,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_routing_generic, surf_route, "Generic imple static const char* instr_node_name(xbt_node_t node) { - void* data = xbt_graph_node_get_data(node); + const void* data = xbt_graph_node_get_data(node); return static_cast(data); } @@ -153,8 +153,8 @@ void RoutedZone::get_route_check_params(NetPoint* src, NetPoint* dst) xbt_assert(src, "Cannot find a route from nullptr to %s", dst->get_cname()); xbt_assert(dst, "Cannot find a route from %s to nullptr", src->get_cname()); - NetZoneImpl* src_as = src->get_englobing_zone(); - NetZoneImpl* dst_as = dst->get_englobing_zone(); + const NetZoneImpl* src_as = src->get_englobing_zone(); + const NetZoneImpl* dst_as = dst->get_englobing_zone(); xbt_assert(src_as == dst_as, "Internal error: %s@%s and %s@%s are not in the same netzone as expected. Please report that bug.", -- 2.20.1