Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
dynar--
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Thu, 9 Mar 2017 09:03:50 +0000 (10:03 +0100)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Thu, 9 Mar 2017 10:35:20 +0000 (11:35 +0100)
src/include/surf/surf.h
src/simgrid/sg_config.cpp
src/surf/storage_interface.cpp
src/surf/surf_interface.cpp
src/surf/surf_interface.hpp
src/surf/trace_mgr.cpp
src/surf/xml/surfxml_sax_cb.cpp

index a20b63e..134173a 100644 (file)
@@ -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
 
index 900285a..a2d536b 100644 (file)
@@ -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, &copy);
+          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);
     }
 
index 89a0d0c..7fe5fd0 100644 (file)
@@ -7,6 +7,7 @@
 #include "storage_interface.hpp"
 #include "surf_private.h"
 #include "xbt/file.h" /* xbt_getline */
+#include <boost/algorithm/string/join.hpp>
 
 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;
index 6c607d5..e9b9cf2 100644 (file)
@@ -28,7 +28,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_kernel, surf, "Logging specific to SURF (ke
 std::vector<surf_model_t> * 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<std::string> surf_path;
 std::vector<simgrid::s4u::Host*> 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();
index 5a2a7d9..a5987f5 100644 (file)
@@ -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<std::string> surf_path;
 
 extern "C" {
 XBT_PUBLIC(double) surf_get_clock(void);
index bdf6339..ddd0708 100644 (file)
@@ -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 <math.h>
 #include <unordered_map>
+#include <boost/algorithm/string/join.hpp>
 
 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);
index b711427..ae13da9 100644 (file)
@@ -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);