Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
chasing minor smells
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Thu, 11 May 2017 09:46:53 +0000 (11:46 +0200)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Thu, 11 May 2017 09:46:53 +0000 (11:46 +0200)
15 files changed:
examples/java/app/centralizedmutex/Node.java
examples/java/dht/kademlia/Node.java
examples/java/io/file/Node.java
src/kernel/routing/DijkstraZone.cpp
src/simgrid/host.cpp
src/simgrid/sg_config.cpp
src/smpi/instr_smpi.cpp
src/smpi/smpi_global.cpp
src/smpi/smpi_shared.cpp
src/surf/network_interface.cpp
src/surf/xml/surfxml_parseplatf.cpp
src/xbt/backtrace_linux.cpp
src/xbt/cunit.cpp
src/xbt/xbt_str.cpp
teshsuite/simdag/flatifier/flatifier.cpp

index 78bfef9..43ed0cf 100644 (file)
@@ -16,13 +16,13 @@ public class Node extends Process {
   public Node(Host host, String name, String[]args) {
    super(host,name,args);
   }
-  public void request(double CStime) throws MsgException {
+  public void request(double csTime) throws MsgException {
     RequestTask req = new RequestTask(getName());
     Msg.info("Send a request to the coordinator");
     req.send("coordinator");
     Msg.info("Wait for a grant from the coordinator");
     GrantTask.receive(getName());
-    Task compute = new Task("CS", CStime, 0);
+    Task compute = new Task("CS", csTime, 0);
     compute.execute();
     ReleaseTask release = new ReleaseTask();
     release.send("coordinator");
index 4e46ba0..7ac0c3d 100644 (file)
@@ -57,16 +57,16 @@ public class Node extends Process {
   }
 
   public void mainLoop() {
-    double next_lookup_time = Msg.getClock() + Common.RANDOM_LOOKUP_INTERVAL;
+    double nextLookupTime = Msg.getClock() + Common.RANDOM_LOOKUP_INTERVAL;
     while (Msg.getClock() < this.deadline) {
       try {
         if (comm == null) {
           comm = Task.irecv(Integer.toString(id));
         }
         if (!comm.test()) {
-          if (Msg.getClock() >= next_lookup_time) {
+          if (Msg.getClock() >= nextLookupTime) {
             randomLookup();
-            next_lookup_time += Common.RANDOM_LOOKUP_INTERVAL;
+            nextLookupTime += Common.RANDOM_LOOKUP_INTERVAL;
           } else {
             waitFor(1);
           }
index df9e214..82ce689 100644 (file)
@@ -26,10 +26,10 @@ import org.simgrid.msg.HostNotFoundException;
 import org.simgrid.msg.MsgException;
 
 public class Node extends Process {
-  private static String FILENAME1 = "/doc/simgrid/examples/platforms/g5k.xml";
-  private static String FILENAME2 = "\\Windows\\setupact.log";
-  private static String FILENAME3 = "/doc/simgrid/examples/platforms/g5k_cabinets.xml";
-  private static String FILENAME4 = "/doc/simgrid/examples/platforms/nancy.xml";
+  private static String file1 = "/doc/simgrid/examples/platforms/g5k.xml";
+  private static String file2 = "\\Windows\\setupact.log";
+  private static String file3 = "/doc/simgrid/examples/platforms/g5k_cabinets.xml";
+  private static String file4 = "/doc/simgrid/examples/platforms/nancy.xml";
 
   protected int rank;
 
@@ -40,42 +40,42 @@ public class Node extends Process {
 
   public void main(String[] args) throws MsgException {
     String mount;
-    String filename;
+    String fileName;
     switch (rank) {
       case 4:
         mount = "/home";
-        filename = mount + FILENAME1;
+        fileName = mount + file1;
       break;
       case 0:
         mount = "c:";
-        filename = mount + FILENAME2;
+        fileName = mount + file2;
       break;
       case 2:
         mount = "/home";
-        filename = mount + FILENAME3;
+        fileName = mount + file3;
       break;
       case 1:
         mount = "/home";
-        filename = mount + FILENAME4;
+        fileName = mount + file4;
       break;
       default:
         mount = "/home";
-        filename = mount + FILENAME1;
+        fileName = mount + file1;
     }
 
-    Msg.info("Open file " + filename);
-    File file = new File(filename);
+    Msg.info("Open file " + fileName);
+    File file = new File(fileName);
 
     long read = file.read(10000,1);
-    Msg.info("Having read " + read + " on " + filename);
+    Msg.info("Having read " + read + " on " + fileName);
 
     long write = file.write(100000,1);
-    Msg.info("Having write " + write + " on " + filename);
+    Msg.info("Having write " + write + " on " + fileName);
 
-    Msg.info("Seek back to the beginning of " + filename);
+    Msg.info("Seek back to the beginning of " + fileName);
     file.seek(0,File.SEEK_SET);
 
     read = file.read(150000,1);
-    Msg.info("Having read " + read + " on " + filename);  
+    Msg.info("Having read " + read + " on " + fileName);  
   }
 }
index d0e07ee..f987ae3 100644 (file)
@@ -236,11 +236,12 @@ void DijkstraZone::getLocalRoute(NetPoint* src, NetPoint* dst, sg_platf_route_cb
   }
 
   /* compose route path with links */
-  NetPoint *gw_src = nullptr;
-  NetPoint *gw_dst;
-  NetPoint *prev_gw_src;
-  NetPoint *first_gw = nullptr;
-  NetPoint *gw_dst_net_elm = nullptr, *prev_gw_src_net_elm = nullptr;
+  NetPoint* gw_src = nullptr;
+  NetPoint* gw_dst;
+  NetPoint* prev_gw_src;
+  NetPoint* first_gw            = nullptr;
+  NetPoint* gw_dst_net_elm      = nullptr;
+  NetPoint* prev_gw_src_net_elm = nullptr;
 
   for (int v = dst_node_id; v != src_node_id; v = pred_arr[v]) {
     xbt_node_t node_pred_v = xbt_dynar_get_as(nodes, pred_arr[v], xbt_node_t);
index 308a135..919fb94 100644 (file)
@@ -236,8 +236,6 @@ double sg_host_route_bandwidth(sg_host_t from, sg_host_t to)
 void sg_host_dump(sg_host_t host)
 {
   xbt_dict_t props;
-  xbt_dict_cursor_t cursor=nullptr;
-  char *key,*data;
 
   XBT_INFO("Displaying host %s", host->cname());
   XBT_INFO("  - speed: %.0f", host->speed());
@@ -246,6 +244,9 @@ void sg_host_dump(sg_host_t host)
 
   if (!xbt_dict_is_empty(props)){
     XBT_INFO("  - properties:");
+    xbt_dict_cursor_t cursor = nullptr;
+    char* key;
+    char* data;
 
     xbt_dict_foreach(props,cursor,key,data) {
       XBT_INFO("    %s->%s",key,data);
index f1434ef..729f1ee 100644 (file)
@@ -45,7 +45,8 @@ int _sg_cfg_exit_asap = 0;
 static void sg_config_cmd_line(int *argc, char **argv)
 {
   int shall_exit = 0;
-  int i, j;
+  int i;
+  int j;
 
   for (j = i = 1; i < *argc; i++) {
     if (!strncmp(argv[i], "--cfg=", strlen("--cfg="))) {
index 900d1a1..588086b 100644 (file)
@@ -61,20 +61,20 @@ static const char *smpi_colors[] ={
 
 static char *str_tolower (const char *str)
 {
-  char *ret = xbt_strdup (str);
-  int i, n = strlen (ret);
-  for (i = 0; i < n; i++)
+  char* ret = xbt_strdup(str);
+  int n     = strlen(ret);
+  for (int i = 0; i < n; i++)
     ret[i] = tolower (str[i]);
   return ret;
 }
 
 static const char *instr_find_color (const char *state)
 {
-  char *target = str_tolower (state);
-  const char *ret = nullptr;
-  unsigned int i = 0;
-  const char *current = smpi_colors[i];
-  while ((current != nullptr)){
+  char* target        = str_tolower(state);
+  const char* ret     = nullptr;
+  unsigned int i      = 0;
+  const charcurrent = smpi_colors[i];
+  while (current != nullptr) {
     if (strcmp (state, current) == 0 //exact match
         || strstr(target, current) != 0 ){//as substring
          ret = smpi_colors[i+1]; 
index d047bcf..161300d 100644 (file)
@@ -180,7 +180,8 @@ void smpi_comm_copy_buffer_callback(smx_activity_t synchro, void *buff, size_t b
        XBT_DEBUG("Privatization : We are copying from a zone inside global memory... Saving data to temp buffer !");
 
        smpi_switch_data_segment(
-           (static_cast<simgrid::smpi::Process*>((static_cast<simgrid::MsgActorExt*>(comm->src_proc->data)->data))->index()));
+           static_cast<simgrid::smpi::Process*>((static_cast<simgrid::MsgActorExt*>(comm->src_proc->data)->data))
+               ->index());
        tmpbuff = static_cast<void*>(xbt_malloc(buff_size));
        memcpy_private(tmpbuff, buff, private_blocks);
   }
@@ -189,7 +190,8 @@ void smpi_comm_copy_buffer_callback(smx_activity_t synchro, void *buff, size_t b
       && ((char*)comm->dst_buff < smpi_start_data_exe + smpi_size_data_exe )){
        XBT_DEBUG("Privatization : We are copying to a zone inside global memory - Switch data segment");
        smpi_switch_data_segment(
-           (static_cast<simgrid::smpi::Process*>((static_cast<simgrid::MsgActorExt*>(comm->dst_proc->data)->data))->index()));
+           static_cast<simgrid::smpi::Process*>((static_cast<simgrid::MsgActorExt*>(comm->dst_proc->data)->data))
+               ->index());
   }
   XBT_DEBUG("Copying %zu bytes from %p to %p", buff_size, tmpbuff,comm->dst_buff);
   memcpy_private(comm->dst_buff, tmpbuff, private_blocks);
@@ -664,8 +666,8 @@ int smpi_main(const char* executable, int argc, char *argv[])
     }
   }
   int count = smpi_process_count();
-  int i, ret=0;
-  for (i = 0; i < count; i++) {
+  int ret   = 0;
+  for (int i = 0; i < count; i++) {
     if(process_data[i]->return_value()!=0){
       ret=process_data[i]->return_value();//return first non 0 value
       break;
index b9e85fa..09d9030 100644 (file)
@@ -363,7 +363,8 @@ std::vector<std::pair<size_t, size_t>> shift_and_frame_private_blocks(const std:
 
 std::vector<std::pair<size_t, size_t>> merge_private_blocks(std::vector<std::pair<size_t, size_t>> src, std::vector<std::pair<size_t, size_t>> dst) {
   std::vector<std::pair<size_t, size_t>> result;
-  unsigned i_src=0, i_dst=0;
+  unsigned i_src = 0;
+  unsigned i_dst = 0;
   while(i_src < src.size() && i_dst < dst.size()) {
     std::pair<size_t, size_t> block;
     if(src[i_src].second <= dst[i_dst].first) {
index 13c24e0..13ce413 100644 (file)
@@ -35,9 +35,10 @@ namespace simgrid {
     LinkImpl** LinkImpl::linksList()
     {
       LinkImpl** res = xbt_new(LinkImpl*, (int)links->size());
-      int i=0;
+      int i          = 0;
       for (auto kv : *links) {
-        res[i++] = kv.second;
+        res[i] = kv.second;
+        i++;
       }
       return res;
     }
index 24892fd..ba3dab8 100644 (file)
@@ -180,7 +180,8 @@ void parse_platform_file(const char *file)
 
     /* connect all traces relative to hosts */
     xbt_dict_cursor_t cursor = nullptr;
-    char *trace_name, *elm;
+    char* trace_name;
+    char* elm;
 
     xbt_dict_foreach(trace_connect_list_host_avail, cursor, trace_name, elm) {
       tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
index 5e77a4a..20891ae 100644 (file)
@@ -34,8 +34,9 @@ extern char **environ;          /* the environment, as specified by the opengrou
 
 #include <unwind.h>
 struct trace_arg {
-  void **array;
-  int cnt, size;
+  void** array;
+  int cnt;
+  int size;
 };
 
 static _Unwind_Reason_Code
@@ -190,7 +191,8 @@ std::vector<std::string> resolveBacktrace(
   }
 
   /* To read the output of addr2line */
-  char line_func[1024], line_pos[1024];
+  char line_func[1024];
+  char line_pos[1024];
   for (std::size_t i = 0; i < count; i++) {
     XBT_DEBUG("Looking for symbol %zd, addr = '%s'", i, addrs[i].c_str());
     if (fgets(line_func, 1024, pipe)) {
@@ -217,7 +219,8 @@ std::vector<std::string> resolveBacktrace(
 
       char maps_buff[512];
       long int offset = 0;
-      char *p, *p2;
+      char* p;
+      char* p2;
       int found = 0;
 
       /* let's look for the offset of this library in our addressing space */
@@ -233,7 +236,8 @@ std::vector<std::string> resolveBacktrace(
         addrs[i].c_str(), addr);
 
       while (!found) {
-        long int first, last;
+        long int first;
+        long int last;
 
         if (fgets(maps_buff, 512, maps) == nullptr)
           break;
index bac2505..94e16a6 100644 (file)
@@ -88,7 +88,9 @@ struct s_xbt_test_unit {
   xbt_dynar_t tests;            /* of xbt_test_test_t */
 
   int nb_tests;
-  int test_failed, test_ignore, test_expect;
+  int test_failed;
+  int test_ignore;
+  int test_expect;
 };
 
 static void xbt_test_unit_dump(xbt_test_unit_t unit)
@@ -112,9 +114,14 @@ struct s_xbt_test_suite {
   char *title;
   xbt_dynar_t units;            /* of xbt_test_unit_t */
 
-  int nb_tests, nb_units;
-  int test_failed, test_ignore, test_expect;
-  int unit_failed, unit_ignore, unit_disabled;
+  int nb_tests;
+  int nb_units;
+  int test_failed;
+  int test_ignore;
+  int test_expect;
+  int unit_failed;
+  int unit_ignore;
+  int unit_disabled;
 };
 
 /* destroy test suite */
@@ -245,7 +252,9 @@ static int xbt_test_suite_run(xbt_test_suite_t suite, int verbosity)
   const char *file;
   int line;
   char *cp;
-  unsigned int it_unit, it_test, it_log;
+  unsigned int it_unit;
+  unsigned int it_test;
+  unsigned int it_log;
 
   int first = 1;                /* for result pretty printing */
 
@@ -253,25 +262,22 @@ static int xbt_test_suite_run(xbt_test_suite_t suite, int verbosity)
     return 0;
 
   /* suite title pretty-printing */
-  {
-    char suite_title[81];
-    int suite_len = strlen(suite->title);
-    int i;
-
-    xbt_assert(suite_len < 68, "suite title \"%s\" too long (%d should be less than 68", suite->title, suite_len);
-
-    suite_title[0] = ' ';
-    for (i = 1; i < 80; i++)
-      suite_title[i] = '=';
-    suite_title[i++] = '\n';
-    suite_title[80] = '\0';
-
-    snprintf(suite_title + 40 - (suite_len + 4) / 2, 81-(40 - (suite_len + 4)/ 2), "[ %s ]", suite->title);
-    suite_title[40 + (suite_len + 5) / 2] = '=';
-    if (!suite->enabled)
-      snprintf(suite_title + 70, 11, " DISABLED ");
-    fprintf(stderr, "\n%s\n", suite_title);
-  }
+  char suite_title[81];
+  int suite_len = strlen(suite->title);
+
+  xbt_assert(suite_len < 68, "suite title \"%s\" too long (%d should be less than 68", suite->title, suite_len);
+
+  suite_title[0] = ' ';
+  for (int i = 1; i < 79; i++)
+    suite_title[i] = '=';
+  suite_title[79]  = '\n';
+  suite_title[80]  = '\0';
+
+  snprintf(suite_title + 40 - (suite_len + 4) / 2, 81 - (40 - (suite_len + 4) / 2), "[ %s ]", suite->title);
+  suite_title[40 + (suite_len + 5) / 2] = '=';
+  if (!suite->enabled)
+    snprintf(suite_title + 70, 11, " DISABLED ");
+  fprintf(stderr, "\n%s\n", suite_title);
 
   if (suite->enabled) {
     /* iterate through all tests */
index 8496a21..90eb701 100644 (file)
@@ -183,8 +183,6 @@ char *xbt_str_varsubst(const char *str, xbt_dict_t patterns)
 xbt_dynar_t xbt_str_split(const char *s, const char *sep)
 {
   xbt_dynar_t res = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
-  const char *p, *q;
-  int done;
   const char *sep_dflt = " \t\n\r\x0B";
   char is_sep[256] = { 1, 0 };
 
@@ -197,12 +195,12 @@ xbt_dynar_t xbt_str_split(const char *s, const char *sep)
     while (*sep)
       is_sep[(unsigned char) *sep++] = 1;
   }
-  is_sep[0] = 1;                /* End of string is also separator */
+  is_sep[0] = 1; /* End of string is also separator */
 
   /* Do the job */
-  p = s;
-  q = s;
-  done = 0;
+  const char* p = s;
+  const char* q = s;
+  int done      = 0;
 
   if (s[0] == '\0')
     return res;
@@ -233,12 +231,10 @@ xbt_dynar_t xbt_str_split(const char *s, const char *sep)
 xbt_dynar_t xbt_str_split_str(const char *s, const char *sep)
 {
   xbt_dynar_t res = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
-  int done;
-  const char *p, *q;
 
-  p = s;
-  q = s;
-  done = 0;
+  const char* p = s;
+  const char* q = s;
+  int done      = 0;
 
   if (s[0] == '\0')
     return res;
@@ -287,10 +283,12 @@ xbt_dynar_t xbt_str_split_str(const char *s, const char *sep)
  */
 xbt_dynar_t xbt_str_split_quoted_in_place(char *s) {
   xbt_dynar_t res = xbt_dynar_new(sizeof(char *), nullptr);
-  char *beg, *end;              /* pointers around the parsed chunk */
-  int in_simple_quote = 0, in_double_quote = 0;
-  int done = 0;
-  int ctn = 0;                  /* Got something in this block */
+  char* beg;
+  char* end; /* pointers around the parsed chunk */
+  int in_simple_quote = 0;
+  int in_double_quote = 0;
+  int done            = 0;
+  int ctn             = 0; /* Got something in this block */
 
   if (s[0] == '\0')
     return res;
@@ -403,8 +401,7 @@ char *xbt_str_join(xbt_dynar_t dyn, const char *sep)
 {
   int len = 1, dyn_len = xbt_dynar_length(dyn);
   unsigned int cpt;
-  char *cursor;
-  char *res, *p;
+  char* cursor;
 
   if (!dyn_len)
     return xbt_strdup("");
@@ -415,8 +412,8 @@ char *xbt_str_join(xbt_dynar_t dyn, const char *sep)
   }
   len += strlen(sep) * dyn_len;
   /* Do the job */
-  res = (char*) xbt_malloc(len);
-  p = res;
+  char* res = (char*)xbt_malloc(len);
+  char* p   = res;
   xbt_dynar_foreach(dyn, cpt, cursor) {
     if ((int) cpt < dyn_len - 1)
       p += snprintf(p,len, "%s%s", cursor, sep);
@@ -433,26 +430,24 @@ char *xbt_str_join(xbt_dynar_t dyn, const char *sep)
  */
 char *xbt_str_join_array(const char *const *strs, const char *sep)
 {
-  char *res,*q;
   int amount_strings=0;
   int len=0;
-  int i;
 
   if ((!strs) || (!strs[0]))
     return xbt_strdup("");
 
   /* compute the length before malloc */
-  for (i=0;strs[i];i++) {
+  for (int i = 0; strs[i]; i++) {
     len += strlen(strs[i]);
     amount_strings++;
   }
   len += strlen(sep) * amount_strings;
 
   /* Do the job */
-  res = (char*) xbt_malloc(len);
-  q = res;
-  for (i=0;strs[i];i++) {
-    if (i!=0) { // not first loop
+  char* res = (char*)xbt_malloc(len);
+  char* q   = res;
+  for (int i = 0; strs[i]; i++) {
+    if (i != 0) { // not first loop
       q += snprintf(q,len, "%s%s", sep, strs[i]);
     } else {
       q += snprintf(q,len, "%s",strs[i]);
@@ -468,7 +463,7 @@ char *xbt_str_join_array(const char *const *strs, const char *sep)
  */
 long int xbt_str_parse_int(const char* str, const char* error_msg)
 {
-  char *endptr;
+  charendptr;
   if (str == nullptr || str[0] == '\0')
     THROWF(arg_error, 0, error_msg, str);
 
index 5baf868..d654328 100644 (file)
@@ -61,7 +61,8 @@ static void dump_platform()
   int version = 4;
   xbt_dict_t props = nullptr;
   xbt_dict_cursor_t cursor = nullptr;
-  char *key, *data;
+  char* key;
+  char* data;
 
   std::printf("<?xml version='1.0'?>\n");
   std::printf("<!DOCTYPE platform SYSTEM \"http://simgrid.gforge.inria.fr/simgrid/simgrid.dtd\">\n");