Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix use-ater-free.
[simgrid.git] / src / surf / sg_platf.cpp
index 4801306..97ce0b1 100644 (file)
@@ -35,8 +35,7 @@ XBT_PRIVATE std::vector<std::string> known_storages;
 namespace simgrid {
 namespace surf {
 
-simgrid::xbt::signal<void(sg_platf_cluster_cbarg_t)> on_cluster;
-
+simgrid::xbt::signal<void(ClusterCreationArgs*)> on_cluster;
 }
 }
 
@@ -77,7 +76,7 @@ void sg_platf_new_host(sg_platf_host_cbarg_t args)
 {
   std::map<std::string, std::string> props;
   if (args->properties) {
-    for (auto elm : *args->properties)
+    for (auto const& elm : *args->properties)
       props.insert({elm.first, elm.second});
     delete args->properties;
   }
@@ -100,18 +99,18 @@ void sg_platf_new_host(sg_platf_host_cbarg_t args)
 }
 
 /** @brief Add a "router" to the network element list */
-simgrid::kernel::routing::NetPoint* sg_platf_new_router(const char* name, const char* coords)
+simgrid::kernel::routing::NetPoint* sg_platf_new_router(std::string name, const char* coords)
 {
   simgrid::kernel::routing::NetZoneImpl* current_routing = routing_get_current();
 
   if (current_routing->hierarchy_ == simgrid::kernel::routing::NetZoneImpl::RoutingMode::unset)
     current_routing->hierarchy_ = simgrid::kernel::routing::NetZoneImpl::RoutingMode::base;
   xbt_assert(nullptr == simgrid::s4u::Engine::getInstance()->getNetpointByNameOrNull(name),
-             "Refusing to create a router named '%s': this name already describes a node.", name);
+             "Refusing to create a router named '%s': this name already describes a node.", name.c_str());
 
   simgrid::kernel::routing::NetPoint* netpoint =
       new simgrid::kernel::routing::NetPoint(name, simgrid::kernel::routing::NetPoint::Type::Router, current_routing);
-  XBT_DEBUG("Router '%s' has the id %u", name, netpoint->id());
+  XBT_DEBUG("Router '%s' has the id %u", name.c_str(), netpoint->id());
 
   if (coords && strcmp(coords, ""))
     new simgrid::kernel::routing::vivaldi::Coords(netpoint, coords);
@@ -130,14 +129,13 @@ void sg_platf_new_link(LinkCreationArgs* link)
   } else {
     names.push_back(link->id);
   }
-  for (auto link_name : names) {
+  for (auto const& link_name : names) {
     simgrid::surf::LinkImpl* l =
         surf_network_model->createLink(link_name.c_str(), link->bandwidth, link->latency, link->policy);
 
     if (link->properties) {
-      for (auto elm : *link->properties)
+      for (auto const& elm : *link->properties)
         l->setProperty(elm.first, elm.second);
-      delete link->properties;
     }
 
     if (link->latency_trace)
@@ -147,9 +145,10 @@ void sg_platf_new_link(LinkCreationArgs* link)
     if (link->state_trace)
       l->setStateTrace(link->state_trace);
   }
+  delete link->properties;
 }
 
-void sg_platf_new_cluster(sg_platf_cluster_cbarg_t cluster)
+void sg_platf_new_cluster(ClusterCreationArgs* cluster)
 {
   using simgrid::kernel::routing::ClusterZone;
   using simgrid::kernel::routing::DragonflyZone;
@@ -189,7 +188,7 @@ void sg_platf_new_cluster(sg_platf_cluster_cbarg_t cluster)
     current_as->hasLimiter_ = 1;
   }
 
-  for (int i : *cluster->radicals) {
+  for (int const& i : *cluster->radicals) {
     std::string host_id = std::string(cluster->prefix) + std::to_string(i) + cluster->suffix;
     std::string link_id = std::string(cluster->id) + "_link_" + std::to_string(i);
 
@@ -201,7 +200,7 @@ void sg_platf_new_cluster(sg_platf_cluster_cbarg_t cluster)
     if ((cluster->properties != nullptr) && (not cluster->properties->empty())) {
       host.properties = new std::map<std::string, std::string>;
 
-      for (auto elm : *cluster->properties)
+      for (auto const& elm : *cluster->properties)
         host.properties->insert({elm.first, elm.second});
     }
 
@@ -272,10 +271,10 @@ void sg_platf_new_cluster(sg_platf_cluster_cbarg_t cluster)
 
   // Add a router.
   XBT_DEBUG(" ");
-  XBT_DEBUG("<router id=\"%s\"/>", cluster->router_id);
-  if (not cluster->router_id || not strcmp(cluster->router_id, "")) {
+  XBT_DEBUG("<router id=\"%s\"/>", cluster->router_id.c_str());
+  if (cluster->router_id.empty()) {
     std::string newid   = std::string(cluster->prefix) + cluster->id + "_router" + cluster->suffix;
-    current_as->router_ = sg_platf_new_router(newid.c_str(), NULL);
+    current_as->router_ = sg_platf_new_router(newid, NULL);
   } else {
     current_as->router_ = sg_platf_new_router(cluster->router_id, NULL);
   }
@@ -316,7 +315,7 @@ void routing_cluster_add_backbone(simgrid::surf::LinkImpl* bb)
 
 void sg_platf_new_cabinet(CabinetCreationArgs* cabinet)
 {
-  for (int radical : *cabinet->radicals) {
+  for (int const& radical : *cabinet->radicals) {
     std::string hostname = cabinet->prefix + std::to_string(radical) + cabinet->suffix;
     s_sg_platf_host_cbarg_t host;
     memset(&host, 0, sizeof(host));
@@ -333,13 +332,10 @@ void sg_platf_new_cabinet(CabinetCreationArgs* cabinet)
     link.id        = "link_" + hostname;
     sg_platf_new_link(&link);
 
-    s_sg_platf_host_link_cbarg_t host_link;
-    memset(&host_link, 0, sizeof(host_link));
-    std::string tmp_link_up   = std::string("link_") + hostname + "_UP";
-    std::string tmp_link_down = std::string("link_") + hostname + "_DOWN";
-    host_link.id        = hostname.c_str();
-    host_link.link_up         = tmp_link_up.c_str();
-    host_link.link_down       = tmp_link_down.c_str();
+    HostLinkCreationArgs host_link;
+    host_link.id        = hostname;
+    host_link.link_up   = std::string("link_") + hostname + "_UP";
+    host_link.link_down = std::string("link_") + hostname + "_DOWN";
     sg_platf_new_hostlink(&host_link);
   }
   delete cabinet->radicals;
@@ -379,7 +375,7 @@ void sg_platf_new_storage(StorageCreationArgs* storage)
   auto s = surf_storage_model->createStorage(storage->id, stype->id, storage->content, storage->attach);
 
   if (storage->properties) {
-    for (auto elm : *storage->properties)
+    for (auto const& elm : *storage->properties)
       s->setProperty(elm.first, elm.second);
     delete storage->properties;
   }
@@ -429,7 +425,7 @@ void sg_platf_new_process(sg_platf_process_cbarg_t process)
     // The requested host does not exist. Do a nice message to the user
     std::string msg = std::string("Cannot create process '") + process->function + "': host '" + process->host +
                       "' does not exist\nExisting hosts: '";
-    for (auto kv : simgrid::s4u::host_list) {
+    for (auto const& kv : simgrid::s4u::host_list) {
       simgrid::s4u::Host* host = kv.second;
       msg += host->getName();
       msg += "', '";
@@ -664,23 +660,23 @@ void sg_platf_new_Zone_seal()
 }
 
 /** @brief Add a link connecting an host to the rest of its AS (which must be cluster or vivaldi) */
-void sg_platf_new_hostlink(sg_platf_host_link_cbarg_t hostlink)
+void sg_platf_new_hostlink(HostLinkCreationArgs* hostlink)
 {
-  simgrid::kernel::routing::NetPoint* netpoint = sg_host_by_name(hostlink->id)->pimpl_netpoint;
-  xbt_assert(netpoint, "Host '%s' not found!", hostlink->id);
+  simgrid::kernel::routing::NetPoint* netpoint = sg_host_by_name(hostlink->id.c_str())->pimpl_netpoint;
+  xbt_assert(netpoint, "Host '%s' not found!", hostlink->id.c_str());
   xbt_assert(dynamic_cast<simgrid::kernel::routing::ClusterZone*>(current_routing),
              "Only hosts from Cluster and Vivaldi ASes can get an host_link.");
 
   simgrid::surf::LinkImpl* linkUp   = simgrid::surf::LinkImpl::byName(hostlink->link_up);
   simgrid::surf::LinkImpl* linkDown = simgrid::surf::LinkImpl::byName(hostlink->link_down);
 
-  xbt_assert(linkUp, "Link '%s' not found!", hostlink->link_up);
-  xbt_assert(linkDown, "Link '%s' not found!", hostlink->link_down);
+  xbt_assert(linkUp, "Link '%s' not found!", hostlink->link_up.c_str());
+  xbt_assert(linkDown, "Link '%s' not found!", hostlink->link_down.c_str());
 
   auto as_cluster = static_cast<simgrid::kernel::routing::ClusterZone*>(current_routing);
 
   if (as_cluster->privateLinks_.find(netpoint->id()) != as_cluster->privateLinks_.end())
-    surf_parse_error(std::string("Host_link for '") + hostlink->id + "' is already defined!");
+    surf_parse_error(std::string("Host_link for '") + hostlink->id.c_str() + "' is already defined!");
 
   XBT_DEBUG("Push Host_link for host '%s' to position %u", netpoint->cname(), netpoint->id());
   as_cluster->privateLinks_.insert({netpoint->id(), {linkUp, linkDown}});