Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
WIP stop using const char* in C++ layers
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Fri, 24 Feb 2017 13:47:51 +0000 (14:47 +0100)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Fri, 24 Feb 2017 13:47:51 +0000 (14:47 +0100)
(and ugly bprintf, const_cast and free that sonar doesn't like)

src/kernel/routing/DragonflyZone.cpp
src/kernel/routing/FatTreeZone.cpp
src/surf/sg_platf.cpp
src/surf/xml/platf_private.hpp
src/surf/xml/surfxml_sax_cb.cpp

index 1479f98..a85ce05 100644 (file)
@@ -142,7 +142,7 @@ void DragonflyZone::createLink(char* id, int numlinks, surf::LinkImpl** linkup,
   linkTemplate.bandwidth = this->cluster_->bw * numlinks;
   linkTemplate.latency   = this->cluster_->lat;
   linkTemplate.policy    = this->cluster_->sharing_policy; // sthg to do with that ?
-  linkTemplate.id        = id;
+  linkTemplate.id        = std::string(id);
   sg_platf_new_link(&linkTemplate);
   XBT_DEBUG("Generating link %s", id);
   surf::LinkImpl* link;
@@ -155,17 +155,14 @@ void DragonflyZone::createLink(char* id, int numlinks, surf::LinkImpl** linkup,
     link      = surf::LinkImpl::byName(tmpID.c_str());
     *linkdown = link; // check link ?
   } else {
-    link      = surf::LinkImpl::byName(linkTemplate.id);
+    link      = surf::LinkImpl::byName(linkTemplate.id.c_str());
     *linkup   = link;
     *linkdown = link;
   }
-
-  free((void*)linkTemplate.id);
 }
 
 void DragonflyZone::generateLinks()
 {
-
   static int uniqueId = 0;
   char* id            = nullptr;
   surf::LinkImpl* linkup;
index 4a1fa4c..cb69eef 100644 (file)
@@ -435,20 +435,18 @@ FatTreeNode::FatTreeNode(sg_platf_cluster_cbarg_t cluster, int id, int level, in
     linkTemplate.bandwidth = cluster->limiter_link;
     linkTemplate.latency   = 0;
     linkTemplate.policy    = SURF_LINK_SHARED;
-    linkTemplate.id        = bprintf("limiter_%d", id);
+    linkTemplate.id        = "limiter_"+std::to_string(id);
     sg_platf_new_link(&linkTemplate);
-    this->limiterLink = surf::LinkImpl::byName(linkTemplate.id);
-    free(const_cast<char*>(linkTemplate.id));
+    this->limiterLink = surf::LinkImpl::byName(linkTemplate.id.c_str());
   }
   if (cluster->loopback_bw || cluster->loopback_lat) {
     memset(&linkTemplate, 0, sizeof(linkTemplate));
     linkTemplate.bandwidth = cluster->loopback_bw;
     linkTemplate.latency   = cluster->loopback_lat;
     linkTemplate.policy    = SURF_LINK_FATPIPE;
-    linkTemplate.id        = bprintf("loopback_%d", id);
+    linkTemplate.id        = "loopback_"+ std::to_string(id);
     sg_platf_new_link(&linkTemplate);
-    this->loopback = surf::LinkImpl::byName(linkTemplate.id);
-    free(const_cast<char*>(linkTemplate.id));
+    this->loopback = surf::LinkImpl::byName(linkTemplate.id.c_str());
   }
 }
 
@@ -461,7 +459,8 @@ FatTreeLink::FatTreeLink(sg_platf_cluster_cbarg_t cluster, FatTreeNode* downNode
   linkTemplate.bandwidth = cluster->bw;
   linkTemplate.latency   = cluster->lat;
   linkTemplate.policy    = cluster->sharing_policy; // sthg to do with that ?
-  linkTemplate.id        = bprintf("link_from_%d_to_%d_%d", downNode->id, upNode->id, uniqueId);
+  linkTemplate.id        =
+      "link_from_" + std::to_string( downNode->id) + "_" + std::to_string(upNode->id) + "_" + std::to_string(uniqueId);
   sg_platf_new_link(&linkTemplate);
 
   if (cluster->sharing_policy == SURF_LINK_FULLDUPLEX) {
@@ -470,10 +469,9 @@ FatTreeLink::FatTreeLink(sg_platf_cluster_cbarg_t cluster, FatTreeNode* downNode
     tmpID          = std::string(linkTemplate.id) + "_DOWN";
     this->downLink    = surf::LinkImpl::byName(tmpID.c_str()); // check link ?
   } else {
-    this->upLink   = surf::LinkImpl::byName(linkTemplate.id);
+    this->upLink   = surf::LinkImpl::byName(linkTemplate.id.c_str());
     this->downLink = this->upLink;
   }
-  free(const_cast<char*>(linkTemplate.id));
   uniqueId++;
 }
 }
index 6303d9c..9cb4e2c 100644 (file)
@@ -116,17 +116,17 @@ simgrid::kernel::routing::NetPoint* sg_platf_new_router(const char* name, const
 }
 
 void sg_platf_new_link(sg_platf_link_cbarg_t link){
-  std::vector<char*> names;
+  std::vector<std::string> names;
 
   if (link->policy == SURF_LINK_FULLDUPLEX) {
-    names.push_back(bprintf("%s_UP", link->id));
-    names.push_back(bprintf("%s_DOWN", link->id));
+    names.push_back(link->id+ "_UP");
+    names.push_back(link->id+ "_DOWN");
   } else {
-    names.push_back(xbt_strdup(link->id));
+    names.push_back(link->id);
   }
   for (auto link_name : names) {
     simgrid::surf::LinkImpl* l =
-        surf_network_model->createLink(link_name, link->bandwidth, link->latency, link->policy);
+        surf_network_model->createLink(link_name.c_str(), link->bandwidth, link->latency, link->policy);
 
     if (link->properties) {
       xbt_dict_cursor_t cursor = nullptr;
@@ -142,8 +142,6 @@ void sg_platf_new_link(sg_platf_link_cbarg_t link){
       l->setBandwidthTrace(link->bandwidth_trace);
     if (link->state_trace)
       l->setStateTrace(link->state_trace);
-
-    xbt_free(link_name);
   }
 }
 
@@ -291,16 +289,15 @@ void sg_platf_new_cluster(sg_platf_cluster_cbarg_t cluster)
   if ((cluster->bb_bw != 0) || (cluster->bb_lat != 0)) {
 
     memset(&link, 0, sizeof(link));
-    link.id        = bprintf("%s_backbone", cluster->id);
+    link.id        = std::string(cluster->id)+ "_backbone";
     link.bandwidth = cluster->bb_bw;
     link.latency   = cluster->bb_lat;
     link.policy    = cluster->bb_sharing_policy;
 
-    XBT_DEBUG("<link\tid=\"%s\" bw=\"%f\" lat=\"%f\"/>", link.id, cluster->bb_bw, cluster->bb_lat);
+    XBT_DEBUG("<link\tid=\"%s\" bw=\"%f\" lat=\"%f\"/>", link.id.c_str(), cluster->bb_bw, cluster->bb_lat);
     sg_platf_new_link(&link);
 
-    routing_cluster_add_backbone(simgrid::surf::LinkImpl::byName(link.id));
-    free((char*)link.id);
+    routing_cluster_add_backbone(simgrid::surf::LinkImpl::byName(link.id.c_str()));
   }
 
   XBT_DEBUG("</AS>");
@@ -309,6 +306,7 @@ void sg_platf_new_cluster(sg_platf_cluster_cbarg_t cluster)
   simgrid::surf::on_cluster(cluster);
   delete cluster->radicals;
 }
+
 void routing_cluster_add_backbone(simgrid::surf::LinkImpl* bb)
 {
   simgrid::kernel::routing::ClusterZone* cluster =
@@ -324,12 +322,12 @@ void routing_cluster_add_backbone(simgrid::surf::LinkImpl* bb)
 void sg_platf_new_cabinet(sg_platf_cabinet_cbarg_t cabinet)
 {
   for (int radical : *cabinet->radicals) {
-    char *hostname = bprintf("%s%d%s", cabinet->prefix, radical, cabinet->suffix);
+    std::string hostname = std::string(cabinet->prefix) + std::to_string(radical) + std::string(cabinet->suffix);
     s_sg_platf_host_cbarg_t host;
     memset(&host, 0, sizeof(host));
     host.pstate           = 0;
     host.core_amount      = 1;
-    host.id               = hostname;
+    host.id               = hostname.c_str();
     host.speed_per_pstate.push_back(cabinet->speed);
     sg_platf_new_host(&host);
 
@@ -338,20 +336,17 @@ void sg_platf_new_cabinet(sg_platf_cabinet_cbarg_t cabinet)
     link.policy    = SURF_LINK_FULLDUPLEX;
     link.latency   = cabinet->lat;
     link.bandwidth = cabinet->bw;
-    link.id        = bprintf("link_%s",hostname);
+    link.id        = "link_" + hostname;
     sg_platf_new_link(&link);
-    free((char*)link.id);
 
     s_sg_platf_host_link_cbarg_t host_link;
     memset(&host_link, 0, sizeof(host_link));
-    host_link.id        = hostname;
-    host_link.link_up   = bprintf("link_%s_UP",hostname);
-    host_link.link_down = bprintf("link_%s_DOWN",hostname);
+    host_link.id        = hostname.c_str();
+    host_link.link_up   = bprintf("link_%s_UP",hostname.c_str());
+    host_link.link_down = bprintf("link_%s_DOWN",hostname.c_str());
     sg_platf_new_hostlink(&host_link);
     free((char*)host_link.link_up);
     free((char*)host_link.link_down);
-
-    free(hostname);
   }
   delete cabinet->radicals;
 }
index 6929d35..bd8a1b6 100644 (file)
@@ -12,6 +12,7 @@
 #include "simgrid/host.h"
 #include "src/surf/xml/platf.hpp"
 #include <vector>
+#include <string>
 
 SG_BEGIN_DECL()
 #include "src/surf/xml/simgrid_dtd.h"
@@ -57,7 +58,7 @@ typedef struct {
 } s_sg_platf_host_link_cbarg_t, *sg_platf_host_link_cbarg_t;
 
 typedef struct {
-  const char* id;
+  std::string id;
   double bandwidth;
   tmgr_trace_t bandwidth_trace;
   double latency;
index 2a0f2b5..2f6bc1d 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2006-2015. The SimGrid Team.
+  /* Copyright (c) 2006-2015. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
@@ -658,9 +658,9 @@ void ETag_surfxml_link(){
   current_property_set     = nullptr;
 
   link.id                  = A_surfxml_link_id;
-  link.bandwidth           = surf_parse_get_bandwidth(A_surfxml_link_bandwidth, "bandwidth of link", link.id);
+  link.bandwidth           = surf_parse_get_bandwidth(A_surfxml_link_bandwidth, "bandwidth of link", link.id.c_str());
   link.bandwidth_trace     = A_surfxml_link_bandwidth___file[0] ? tmgr_trace_new_from_file(A_surfxml_link_bandwidth___file) : nullptr;
-  link.latency             = surf_parse_get_time(A_surfxml_link_latency, "latency of link", link.id);
+  link.latency             = surf_parse_get_time(A_surfxml_link_latency, "latency of link", link.id.c_str());
   link.latency_trace       = A_surfxml_link_latency___file[0] ? tmgr_trace_new_from_file(A_surfxml_link_latency___file) : nullptr;
   link.state_trace         = A_surfxml_link_state___file[0] ? tmgr_trace_new_from_file(A_surfxml_link_state___file):nullptr;
 
@@ -675,7 +675,7 @@ void ETag_surfxml_link(){
      link.policy = SURF_LINK_FULLDUPLEX;
      break;
   default:
-    surf_parse_error("Invalid sharing policy in link %s", link.id);
+    surf_parse_error("Invalid sharing policy in link %s", link.id.c_str());
     break;
   }
 
@@ -715,8 +715,8 @@ void ETag_surfxml_backbone(){
 
   link.properties = nullptr;
   link.id = A_surfxml_backbone_id;
-  link.bandwidth = surf_parse_get_bandwidth(A_surfxml_backbone_bandwidth, "bandwidth of backbone", link.id);
-  link.latency = surf_parse_get_time(A_surfxml_backbone_latency, "latency of backbone", link.id);
+  link.bandwidth = surf_parse_get_bandwidth(A_surfxml_backbone_bandwidth, "bandwidth of backbone", link.id.c_str());
+  link.latency = surf_parse_get_time(A_surfxml_backbone_latency, "latency of backbone", link.id.c_str());
   link.policy = SURF_LINK_SHARED;
 
   sg_platf_new_link(&link);