Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use simgrid::xbt::Path instead of xbt_{base,dir}name in C++ files.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Wed, 25 Oct 2017 13:21:21 +0000 (15:21 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Wed, 25 Oct 2017 13:27:08 +0000 (15:27 +0200)
src/mc/mc_checkpoint.cpp
src/mc/remote/RemoteClient.cpp
src/simdag/sd_daxloader.cpp
src/simdag/sd_dotloader.cpp
src/surf/xml/surfxml_sax_cb.cpp

index 1e24eff..aa9f21d 100644 (file)
@@ -18,6 +18,7 @@
 #include "src/internal_config.h"
 #include "src/mc/mc_private.hpp"
 #include "src/smpi/include/private.hpp"
+#include "xbt/file.hpp"
 #include "xbt/mmalloc.h"
 #include "xbt/module.h"
 
@@ -185,18 +186,15 @@ void find_object_address(
   std::vector<simgrid::xbt::VmMap> const& maps,
   simgrid::mc::ObjectInformation* result)
 {
-  char* name = xbt_basename(result->file_name.c_str());
+  std::string name = simgrid::xbt::Path(result->file_name).getBasename();
 
   for (size_t i = 0; i < maps.size(); ++i) {
     simgrid::xbt::VmMap const& reg = maps[i];
     if (maps[i].pathname.empty())
       continue;
-    char* map_basename = xbt_basename(maps[i].pathname.c_str());
-    if (strcmp(name, map_basename) != 0) {
-      free(map_basename);
+    std::string map_basename = simgrid::xbt::Path(maps[i].pathname).getBasename();
+    if (map_basename != name)
       continue;
-    }
-    free(map_basename);
 
     // This is the non-GNU_RELRO-part of the data segment:
     if (reg.prot == PROT_RW) {
@@ -250,8 +248,6 @@ void find_object_address(
     result->end = result->end_exec;
 
   xbt_assert(result->start_exec || result->start_rw || result->start_ro);
-
-  free(name);
 }
 
 /************************************* Take Snapshot ************************************/
@@ -522,12 +518,9 @@ static std::vector<s_fd_infos_t> get_current_fds(pid_t pid)
 
     // If dot_output enabled, do not handle the corresponding file
     if (dot_output != nullptr) {
-      char* link_basename = xbt_basename(link);
-      if (strcmp(link_basename, _sg_mc_dot_output_file) == 0) {
-        free(link_basename);
+      std::string link_basename = simgrid::xbt::Path(link).getBasename();
+      if (link_basename == _sg_mc_dot_output_file)
         continue;
-      }
-      free(link_basename);
     }
 
     // This is probably a shared memory used by lttng-ust:
index 92a3955..297c545 100644 (file)
@@ -28,6 +28,7 @@
 #include <libunwind.h>
 
 #include "xbt/base.h"
+#include "xbt/file.hpp"
 #include "xbt/log.h"
 #include <xbt/mmalloc.h>
 
@@ -118,17 +119,13 @@ struct s_mc_memory_map_re {
 
 static char* get_lib_name(const char* pathname, s_mc_memory_map_re* res)
 {
-  char* map_basename = xbt_basename(pathname);
+  std::string map_basename = simgrid::xbt::Path(pathname).getBasename();
 
   regmatch_t match;
-  if (regexec(&res->so_re, map_basename, 1, &match, 0)) {
-    free(map_basename);
+  if (regexec(&res->so_re, map_basename.c_str(), 1, &match, 0))
     return nullptr;
-  }
 
-  char* libname = strndup(map_basename, match.rm_so);
-  free(map_basename);
-  map_basename = nullptr;
+  char* libname = strndup(map_basename.c_str(), match.rm_so);
 
   // Strip the version suffix:
   if (libname && not regexec(&res->version_re, libname, 1, &match, 0)) {
index 409caee..eb18b68 100644 (file)
@@ -6,7 +6,7 @@
 
 #include "simdag_private.hpp"
 #include "simgrid/simdag.h"
-#include "xbt/file.h" /* xbt_basename() */
+#include "xbt/file.hpp"
 #include "xbt/log.h"
 #include "xbt/misc.h"
 #include <map>
@@ -241,9 +241,8 @@ xbt_dynar_t SD_daxload(const char *filename)
   }
 
   if (not acyclic_graph_detail(result)) {
-    char* base = xbt_basename(filename);
-    XBT_ERROR("The DAX described in %s is not a DAG. It contains a cycle.", base);
-    free(base);
+    std::string base = simgrid::xbt::Path(filename).getBasename();
+    XBT_ERROR("The DAX described in %s is not a DAG. It contains a cycle.", base.c_str());
     xbt_dynar_foreach(result, cpt, file)
       SD_task_destroy(file);
     xbt_dynar_free_container(&result);
index 8e3f736..b4f8b3b 100644 (file)
@@ -7,7 +7,7 @@
 #include "simdag_private.hpp"
 #include "simgrid/simdag.h"
 #include "src/internal_config.h"
-#include "xbt/file.h"
+#include "xbt/file.hpp"
 #include <cstring>
 #include <unordered_map>
 
@@ -238,9 +238,8 @@ xbt_dynar_t SD_dotload_generic(const char* filename, bool sequential, bool sched
   }
 
   if (result && not acyclic_graph_detail(result)) {
-    char* base = xbt_basename(filename);
-    XBT_ERROR("The DOT described in %s is not a DAG. It contains a cycle.", base);
-    free(base);
+    std::string base = simgrid::xbt::Path(filename).getBasename();
+    XBT_ERROR("The DOT described in %s is not a DAG. It contains a cycle.", base.c_str());
     xbt_dynar_free(&result);
     result = nullptr;
   }
index f67afd6..d1c9456 100644 (file)
@@ -7,7 +7,7 @@
 #include "simgrid/sg_config.h"
 #include "src/kernel/routing/NetPoint.hpp"
 #include "src/surf/network_interface.hpp"
-#include "xbt/file.h"
+#include "xbt/file.hpp"
 
 #include "src/surf/xml/platf_private.hpp"
 #include <boost/algorithm/string.hpp>
@@ -1069,9 +1069,8 @@ void surf_parse_open(const char *file)
   xbt_assert(file, "Cannot parse the nullptr file. Bypassing the parser is strongly deprecated nowadays.");
 
   surf_parsed_filename = xbt_strdup(file);
-  char* dir            = xbt_dirname(file);
-  surf_path.push_back(std::string(dir));
-  xbt_free(dir);
+  std::string dir      = simgrid::xbt::Path(file).getDirname();
+  surf_path.push_back(dir);
 
   surf_file_to_parse = surf_fopen(file, "r");
   if (surf_file_to_parse == nullptr)