From: Frederic Suter Date: Thu, 9 Mar 2017 09:03:50 +0000 (+0100) Subject: dynar-- X-Git-Tag: v3_15~178 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/013aee5c38d6c531af7a469a89d6474a19233d3f?hp=69b64311b67fddc105da16faded6fecec9db45d3 dynar-- --- diff --git a/src/include/surf/surf.h b/src/include/surf/surf.h index a20b63ea34..134173a0ec 100644 --- a/src/include/surf/surf.h +++ b/src/include/surf/surf.h @@ -30,7 +30,6 @@ extern XBT_PRIVATE double sg_latency_factor; extern XBT_PRIVATE double sg_bandwidth_factor; extern XBT_PRIVATE double sg_weight_S_parameter; extern XBT_PRIVATE int sg_network_crosstraffic; -extern XBT_PRIVATE xbt_dynar_t surf_path; #ifdef __cplusplus diff --git a/src/simgrid/sg_config.cpp b/src/simgrid/sg_config.cpp index 900285aca8..a2d536bf3a 100644 --- a/src/simgrid/sg_config.cpp +++ b/src/simgrid/sg_config.cpp @@ -26,6 +26,7 @@ #include "mc/mc.h" #include "simgrid/instr.h" #include "src/mc/mc_replay.h" +#include "src/surf/surf_interface.hpp" XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_config, surf, "About the configuration of SimGrid"); @@ -421,8 +422,7 @@ void sg_config_init(int *argc, char **argv) "", [](std::string const& path) { if (path[0] != '\0') { - char* copy = xbt_strdup(path.c_str()); - xbt_dynar_push(surf_path, ©); + surf_path.push_back(path); } }); @@ -605,12 +605,11 @@ void sg_config_init(int *argc, char **argv) "Whether to cleanup SimGrid at exit. Disable it if your code segfaults after its end."); xbt_cfg_register_alias("clean-atexit","clean_atexit"); - if (!surf_path) { + if (surf_path.empty()) { /* retrieves the current directory of the current process */ const char *initial_path = __surf_get_initial_path(); xbt_assert((initial_path), "__surf_get_initial_path() failed! Can't resolve current Windows directory"); - surf_path = xbt_dynar_new(sizeof(char *), &xbt_free_ref); xbt_cfg_setdefault_string("path", initial_path); } diff --git a/src/surf/storage_interface.cpp b/src/surf/storage_interface.cpp index 89a0d0c046..7fe5fd05a1 100644 --- a/src/surf/storage_interface.cpp +++ b/src/surf/storage_interface.cpp @@ -7,6 +7,7 @@ #include "storage_interface.hpp" #include "surf_private.h" #include "xbt/file.h" /* xbt_getline */ +#include XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_storage, surf, "Logging specific to the SURF storage module"); @@ -87,7 +88,7 @@ xbt_dict_t Storage::parseContent(const char *filename) xbt_dict_t parse_content = xbt_dict_new_homogeneous(xbt_free_f); FILE *file = surf_fopen(filename, "r"); - xbt_assert(file, "Cannot open file '%s' (path=%s)", filename, xbt_str_join(surf_path, ":")); + xbt_assert(file, "Cannot open file '%s' (path=%s)", filename, (boost::join(surf_path, ":")).c_str()); char *line = nullptr; size_t len = 0; diff --git a/src/surf/surf_interface.cpp b/src/surf/surf_interface.cpp index 6c607d5494..e9b9cf2f78 100644 --- a/src/surf/surf_interface.cpp +++ b/src/surf/surf_interface.cpp @@ -28,7 +28,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_kernel, surf, "Logging specific to SURF (ke std::vector * all_existing_models = nullptr; /* to destroy models correctly */ simgrid::trace_mgr::future_evt_set *future_evt_set = nullptr; -xbt_dynar_t surf_path = nullptr; +std::vector surf_path; std::vector host_that_restart; xbt_dict_t watched_hosts_lib; @@ -127,8 +127,6 @@ double surf_get_clock() FILE *surf_fopen(const char *name, const char *mode) { - unsigned int cpt; - char *path_elm = nullptr; char *buff; FILE *file = nullptr; @@ -138,8 +136,8 @@ FILE *surf_fopen(const char *name, const char *mode) return fopen(name, mode); /* search relative files in the path */ - xbt_dynar_foreach(surf_path, cpt, path_elm) { - buff = bprintf("%s" FILE_DELIM "%s", path_elm, name); + for (auto path_elm : surf_path) { + buff = bprintf("%s" FILE_DELIM "%s", path_elm.c_str(), name); file = fopen(buff, mode); free(buff); @@ -356,8 +354,6 @@ void surf_exit() { TRACE_end(); /* Just in case it was not called by the upper layer (or there is no upper layer) */ - xbt_dynar_free(&surf_path); - sg_host_exit(); xbt_lib_free(&storage_lib); sg_link_exit(); diff --git a/src/surf/surf_interface.hpp b/src/surf/surf_interface.hpp index 5a2a7d9bf4..a5987f592d 100644 --- a/src/surf/surf_interface.hpp +++ b/src/surf/surf_interface.hpp @@ -29,7 +29,7 @@ extern XBT_PRIVATE double sg_latency_factor; extern XBT_PRIVATE double sg_bandwidth_factor; extern XBT_PRIVATE double sg_weight_S_parameter; extern XBT_PRIVATE int sg_network_crosstraffic; -extern XBT_PRIVATE xbt_dynar_t surf_path; +extern XBT_PRIVATE std::vector surf_path; extern "C" { XBT_PUBLIC(double) surf_get_clock(void); diff --git a/src/surf/trace_mgr.cpp b/src/surf/trace_mgr.cpp index bdf633941a..ddd0708951 100644 --- a/src/surf/trace_mgr.cpp +++ b/src/surf/trace_mgr.cpp @@ -9,10 +9,12 @@ #include "xbt/str.h" #include "xbt/dict.h" #include "src/surf/trace_mgr.hpp" +#include "src/surf/surf_interface.hpp" #include "surf_private.h" #include "xbt/RngStream.h" #include #include +#include XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_trace, surf, "Surf trace management"); @@ -85,8 +87,7 @@ tmgr_trace_t tmgr_trace_new_from_file(const char *filename) xbt_assert(trace_list.find(filename) == trace_list.end(), "Refusing to define trace %s twice", filename); FILE *f = surf_fopen(filename, "r"); - xbt_assert(f != nullptr, - "Cannot open file '%s' (path=%s)", filename, xbt_str_join(surf_path, ":")); + xbt_assert(f != nullptr, "Cannot open file '%s' (path=%s)", filename, (boost::join(surf_path, ":")).c_str()); char *tstr = xbt_str_from_file(f); fclose(f); diff --git a/src/surf/xml/surfxml_sax_cb.cpp b/src/surf/xml/surfxml_sax_cb.cpp index b7114274f7..ae13da939b 100644 --- a/src/surf/xml/surfxml_sax_cb.cpp +++ b/src/surf/xml/surfxml_sax_cb.cpp @@ -1010,8 +1010,9 @@ 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); - xbt_dynar_push(surf_path, &dir); + char* dir = xbt_dirname(file); + surf_path.push_back(std::string(dir)); + xbt_free(dir); surf_file_to_parse = surf_fopen(file, "r"); xbt_assert((surf_file_to_parse), "Unable to open \"%s\"\n", file); @@ -1023,9 +1024,7 @@ void surf_parse_open(const char *file) void surf_parse_close() { if (surf_parsed_filename) { - char *dir = nullptr; - xbt_dynar_pop(surf_path, &dir); - free(dir); + surf_path.pop_back(); } free(surf_parsed_filename);