From: Arnaud Giersch Date: Wed, 25 Oct 2017 13:21:21 +0000 (+0200) Subject: Use simgrid::xbt::Path instead of xbt_{base,dir}name in C++ files. X-Git-Tag: v3.18~397^2~8 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/3e5588fc9b34239f448a523211086b05c9fee29c?hp=172a73b13fe909117c7fbf3d69d4ce5e87efdbc6 Use simgrid::xbt::Path instead of xbt_{base,dir}name in C++ files. --- diff --git a/src/mc/mc_checkpoint.cpp b/src/mc/mc_checkpoint.cpp index 1e24eff865..aa9f21d46f 100644 --- a/src/mc/mc_checkpoint.cpp +++ b/src/mc/mc_checkpoint.cpp @@ -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 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 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: diff --git a/src/mc/remote/RemoteClient.cpp b/src/mc/remote/RemoteClient.cpp index 92a3955abb..297c545bc3 100644 --- a/src/mc/remote/RemoteClient.cpp +++ b/src/mc/remote/RemoteClient.cpp @@ -28,6 +28,7 @@ #include #include "xbt/base.h" +#include "xbt/file.hpp" #include "xbt/log.h" #include @@ -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)) { diff --git a/src/simdag/sd_daxloader.cpp b/src/simdag/sd_daxloader.cpp index 409caeec7a..eb18b68f99 100644 --- a/src/simdag/sd_daxloader.cpp +++ b/src/simdag/sd_daxloader.cpp @@ -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 @@ -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); diff --git a/src/simdag/sd_dotloader.cpp b/src/simdag/sd_dotloader.cpp index 8e3f73676e..b4f8b3b733 100644 --- a/src/simdag/sd_dotloader.cpp +++ b/src/simdag/sd_dotloader.cpp @@ -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 #include @@ -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; } diff --git a/src/surf/xml/surfxml_sax_cb.cpp b/src/surf/xml/surfxml_sax_cb.cpp index f67afd6ed4..d1c94568cf 100644 --- a/src/surf/xml/surfxml_sax_cb.cpp +++ b/src/surf/xml/surfxml_sax_cb.cpp @@ -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 @@ -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)