Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[sonar] Constify pointer and reference local variables in src/kernel/.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Mon, 23 Dec 2019 22:46:44 +0000 (23:46 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Mon, 23 Dec 2019 23:33:39 +0000 (00:33 +0100)
15 files changed:
src/kernel/activity/IoImpl.cpp
src/kernel/activity/MailboxImpl.cpp
src/kernel/activity/SleepImpl.cpp
src/kernel/context/ContextRaw.cpp
src/kernel/context/ContextSwapped.cpp
src/kernel/context/ContextUnix.cpp
src/kernel/lmm/fair_bottleneck.cpp
src/kernel/lmm/maxmin.cpp
src/kernel/resource/profile/Profile.cpp
src/kernel/routing/ClusterZone.cpp
src/kernel/routing/DijkstraZone.cpp
src/kernel/routing/FloydZone.cpp
src/kernel/routing/FullZone.cpp
src/kernel/routing/NetZoneImpl.cpp
src/kernel/routing/RoutedZone.cpp

index 8472157..d9d5719 100644 (file)
@@ -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:
index 8915ec7..855b354 100644 (file)
@@ -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_;
index 8a3eb18..9b5be40 100644 (file)
@@ -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;
index d493cae..09e9560 100644 (file)
@@ -224,10 +224,10 @@ void RawContext::wrapper(RawContext* context)
 
 void RawContext::swap_into(SwappedContext* to_)
 {
-  RawContext* to = static_cast<RawContext*>(to_);
+  const RawContext* to = static_cast<RawContext*>(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_);
 }
index a629281..e2ca416 100644 (file)
@@ -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<SwappedContext*>(first_actor->context_.get())->resume();
index fba49bf..3cacf6d 100644 (file)
@@ -91,10 +91,10 @@ UContext::UContext(std::function<void()>&& code, actor::ActorImpl* actor, Swappe
 
 void UContext::swap_into(SwappedContext* to_)
 {
-  UContext* to = static_cast<UContext*>(to_);
+  const UContext* to = static_cast<UContext*>(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_);
 }
index 1db0704..e19ef33 100644 (file)
@@ -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()) {
index d0a9f1f..b082826 100644 (file)
@@ -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 <class CnstList> 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;
index 482ee82..6b88203 100644 (file)
@@ -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;
index 96345af..7ff40dc 100644 (file)
@@ -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");
index a5ad4b5..2694cdf 100644 (file)
@@ -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<RouteCreationArgs*>(xbt_graph_edge_get_data(edge));
+    const RouteCreationArgs* e_route = static_cast<RouteCreationArgs*>(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<GraphNodeData*>(xbt_graph_node_get_data(u_node));
+        const GraphNodeData* data            = static_cast<GraphNodeData*>(xbt_graph_node_get_data(u_node));
         int u_id                           = data->graph_id_;
-        RouteCreationArgs* tmp_e_route     = static_cast<RouteCreationArgs*>(xbt_graph_edge_get_data(edge));
+        const RouteCreationArgs* tmp_e_route = static_cast<RouteCreationArgs*>(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<RouteCreationArgs*>(xbt_graph_edge_get_data(edge));
+    const RouteCreationArgs* e_route = static_cast<RouteCreationArgs*>(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;
 
index d9b7ab8..4a7a7aa 100644 (file)
@@ -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()) {
index 779c949..9438f23 100644 (file)
@@ -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;
index 1fa9475..830f113 100644 (file)
@@ -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<kernel::routing::NetPoint*, kernel::routing::NetPoint*> key;
   for (int max = 0; max <= max_index; max++) {
     for (int i = 0; i < max; i++) {
index dff7174..135b624 100644 (file)
@@ -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<const char*>(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.",