Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
stringify (a lot)
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Sat, 4 Nov 2017 00:04:43 +0000 (01:04 +0100)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Sat, 4 Nov 2017 00:04:43 +0000 (01:04 +0100)
had to do some sloppy stuff in MC because of C headers and lazyness at
1AM

41 files changed:
include/simgrid/s4u/Storage.hpp
include/xbt/config.h
include/xbt/config.hpp
src/bindings/java/jmsg_storage.cpp
src/include/mc/mc.h
src/include/simgrid/sg_config.h
src/include/smpi/smpi_utils.hpp
src/include/surf/surf.h
src/instr/instr_config.cpp
src/instr/instr_paje_containers.cpp
src/instr/instr_paje_trace.cpp
src/instr/instr_private.hpp
src/mc/ModelChecker.cpp
src/mc/Session.cpp
src/mc/checker/LivenessChecker.cpp
src/mc/checker/simgrid_mc.cpp
src/mc/mc_base.cpp
src/mc/mc_checkpoint.cpp
src/mc/mc_config.cpp
src/mc/mc_global.cpp
src/mc/mc_record.cpp
src/mc/mc_record.hpp
src/mc/mc_replay.h
src/s4u/s4u_storage.cpp
src/simgrid/sg_config.cpp
src/simix/smx_global.cpp
src/smpi/colls/smpi_coll.cpp
src/smpi/include/private.hpp
src/smpi/include/smpi_coll.hpp
src/smpi/internals/smpi_bench.cpp
src/smpi/internals/smpi_global.cpp
src/smpi/internals/smpi_shared.cpp
src/smpi/internals/smpi_utils.cpp
src/surf/PropertyHolder.cpp
src/surf/PropertyHolder.hpp
src/surf/cpu_cas01.cpp
src/surf/network_cm02.cpp
src/surf/network_ib.cpp
src/surf/sg_platf.cpp
src/surf/surf_interface.cpp
src/xbt/config.cpp

index f28f936..b8d328e 100644 (file)
@@ -40,8 +40,8 @@ public:
   sg_size_t getSizeUsed();
 
   std::map<std::string, std::string>* getProperties();
-  const char* getProperty(const char* key);
-  void setProperty(const char* key, const char* value);
+  const char* getProperty(std::string key);
+  void setProperty(std::string, std::string value);
   std::map<std::string, sg_size_t>* getContent();
 
   void setUserdata(void* data) { userdata_ = data; }
index a6246df..0b84408 100644 (file)
@@ -72,7 +72,6 @@ XBT_PUBLIC(void) xbt_cfg_set_parse(const char *options);
 /* Set the value of the cell \a name in \a cfg with the provided value.*/
 XBT_PUBLIC(void) xbt_cfg_set_int       (const char *name, int val);
 XBT_PUBLIC(void) xbt_cfg_set_double    (const char *name, double val);
-XBT_PUBLIC(void) xbt_cfg_set_string    (const char *name, const char *val);
 XBT_PUBLIC(void) xbt_cfg_set_boolean   (const char *name, const char *val);
 XBT_PUBLIC(void) xbt_cfg_set_as_string(const char *name, const char *val);
 
@@ -137,7 +136,6 @@ XBT_PUBLIC(void) xbt_cfg_help();
 
 XBT_PUBLIC(int)    xbt_cfg_get_int(const char *name);
 XBT_PUBLIC(double) xbt_cfg_get_double(const char *name);
-XBT_PUBLIC(char *) xbt_cfg_get_string(const char *name);
 XBT_PUBLIC(int)    xbt_cfg_get_boolean(const char *name);
 
 /** @} */
index f5b3c95..c3d0c4c 100644 (file)
@@ -238,5 +238,7 @@ public:
 
 }
 }
+XBT_PUBLIC(std::string) xbt_cfg_get_string(const char* name);
+XBT_PUBLIC(void) xbt_cfg_set_string(const char* name, std::string val);
 
 #endif
index e92d050..a31349d 100644 (file)
@@ -7,9 +7,11 @@
 
 #include "simgrid/msg.h"
 
+#include "include/xbt/signal.hpp"
 #include "jmsg.hpp"
 #include "jmsg_storage.h"
 #include "jxbt_utilities.hpp"
+#include "simgrid/s4u/Storage.hpp"
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(java);
 
@@ -164,9 +166,8 @@ Java_org_simgrid_msg_Storage_setProperty(JNIEnv *env, jobject jstorage, jobject
   }
   const char *name = env->GetStringUTFChars((jstring) jname, 0);
   const char *value_java = env->GetStringUTFChars((jstring) jvalue, 0);
-  char *value = xbt_strdup(value_java);
 
-  MSG_storage_set_property_value(storage, name, value);
+  storage->setProperty(name, std::string(value_java));
 
   env->ReleaseStringUTFChars((jstring) jvalue, value_java);
   env->ReleaseStringUTFChars((jstring) jname, name);
index d3f6b29..49e0f09 100644 (file)
@@ -30,12 +30,10 @@ extern XBT_PRIVATE int _sg_do_model_check_record;
 extern XBT_PRIVATE int _sg_mc_checkpoint;
 extern XBT_PUBLIC(int) _sg_mc_sparse_checkpoint;
 extern XBT_PUBLIC(int) _sg_mc_ksm;
-extern XBT_PUBLIC(char*) _sg_mc_property_file;
 extern XBT_PRIVATE int _sg_mc_timeout;
 extern XBT_PRIVATE int _sg_mc_hash;
 extern XBT_PRIVATE int _sg_mc_max_depth;
 extern XBT_PUBLIC(int) _sg_mc_max_visited_states;
-extern XBT_PRIVATE char* _sg_mc_dot_output_file;
 extern XBT_PUBLIC(int) _sg_mc_comms_determinism;
 extern XBT_PUBLIC(int) _sg_mc_send_determinism;
 extern XBT_PRIVATE int _sg_mc_snapshot_fds;
index 588ac41..304b7b6 100644 (file)
@@ -7,6 +7,7 @@
 #define SIMGRID_CONFIG_H
 
 #include "xbt/config.h"
+#include "xbt/config.hpp"
 
 /** Config Globals */
 SG_BEGIN_DECL()
@@ -20,4 +21,4 @@ XBT_PUBLIC(void) sg_config_finalize();
 
 SG_END_DECL()
 
-#endif
\ No newline at end of file
+#endif
index 9b991fd..52289c4 100644 (file)
@@ -7,6 +7,7 @@
 #define SMPI_UTILS_HPP
 #include "xbt/base.h"
 #include <cstddef>
+#include <string>
 #include <vector>
 
 extern "C" {
@@ -19,6 +20,6 @@ struct s_smpi_factor_t {
 typedef s_smpi_factor_t* smpi_os_factor_t;
 }
 
-XBT_PUBLIC(std::vector<s_smpi_factor_t>) parse_factor(const char *smpi_coef_string);
+XBT_PUBLIC(std::vector<s_smpi_factor_t>) parse_factor(std::string smpi_coef_string);
 
 #endif
index 837c31f..7b0f721 100644 (file)
@@ -89,10 +89,11 @@ struct surf_model_description {
   const char *description;
   void_f_void_t model_init_preparse;
 };
-typedef struct surf_model_description  s_surf_model_description_t;
-typedef struct surf_model_description* surf_model_description_t;
+typedef struct surf_model_description s_surf_model_description_t;
 
-XBT_PUBLIC(int) find_model_description(s_surf_model_description_t * table, const char *name);
+#ifdef __cplusplus
+XBT_PUBLIC(int) find_model_description(s_surf_model_description_t* table, std::string name);
+#endif
 XBT_PUBLIC(void) model_help(const char *category, s_surf_model_description_t * table);
 
 /***************************/
index 5333849..41b7c85 100644 (file)
@@ -3,6 +3,7 @@
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
+#include "include/xbt/config.hpp"
 #include "src/instr/instr_private.hpp"
 #include "surf/surf.h"
 #include <string>
@@ -103,15 +104,15 @@ int TRACE_start()
     /* init the tracing module to generate the right output */
 
     /* open the trace file(s) */
-    const char* format = xbt_cfg_get_string(OPT_TRACING_FORMAT);
-    XBT_DEBUG("Tracing format %s\n", format);
-    if (not strcmp(format, "Paje")) {
+    std::string format = xbt_cfg_get_string(OPT_TRACING_FORMAT);
+    XBT_DEBUG("Tracing format %s\n", format.c_str());
+    if (format == "Paje") {
       TRACE_paje_start();
-    } else if (not strcmp(format, "TI")) {
+    } else if (format == "TI") {
       instr_fmt_type = instr_fmt_TI;
       TRACE_TI_start();
     }else{
-      xbt_die("Unknown trace format :%s ", format);
+      xbt_die("Unknown trace format :%s ", format.c_str());
     }
 
     /* activate trace */
@@ -145,14 +146,14 @@ int TRACE_end()
     delete root_type;
 
     /* close the trace files */
-    const char* format = xbt_cfg_get_string(OPT_TRACING_FORMAT);
-    XBT_DEBUG("Tracing format %s\n", format);
-    if (not strcmp(format, "Paje")) {
+    std::string format = xbt_cfg_get_string(OPT_TRACING_FORMAT);
+    XBT_DEBUG("Tracing format %s\n", format.c_str());
+    if (format == "Paje") {
       TRACE_paje_end();
-    } else if (not strcmp(format, "TI")) {
+    } else if (format == "TI") {
       TRACE_TI_end();
     }else{
-      xbt_die("Unknown trace format :%s ", format);
+      xbt_die("Unknown trace format :%s ", format.c_str());
     }
 
     /* de-activate trace */
@@ -269,12 +270,12 @@ bool TRACE_display_sizes ()
    return trace_display_sizes && trace_smpi_enabled && TRACE_is_enabled();
 }
 
-char *TRACE_get_comment ()
+std::string TRACE_get_comment()
 {
   return xbt_cfg_get_string(OPT_TRACING_COMMENT);
 }
 
-char *TRACE_get_comment_file ()
+std::string TRACE_get_comment_file()
 {
   return xbt_cfg_get_string(OPT_TRACING_COMMENT_FILE);
 }
@@ -284,17 +285,17 @@ int TRACE_precision ()
   return xbt_cfg_get_int(OPT_TRACING_PRECISION);
 }
 
-char *TRACE_get_filename()
+std::string TRACE_get_filename()
 {
   return xbt_cfg_get_string(OPT_TRACING_FILENAME);
 }
 
-char *TRACE_get_viva_uncat_conf ()
+std::string TRACE_get_viva_uncat_conf()
 {
   return xbt_cfg_get_string(OPT_VIVA_UNCAT_CONF);
 }
 
-char *TRACE_get_viva_cat_conf ()
+std::string TRACE_get_viva_cat_conf()
 {
   return xbt_cfg_get_string(OPT_VIVA_CAT_CONF);
 }
@@ -576,12 +577,12 @@ static void generate_cat_configuration (const char *output, const char *name, in
 
 void TRACE_generate_viva_uncat_conf ()
 {
-  generate_uncat_configuration (TRACE_get_viva_uncat_conf (), "viva", 0);
+  generate_uncat_configuration(TRACE_get_viva_uncat_conf().c_str(), "viva", 0);
 }
 
 void TRACE_generate_viva_cat_conf ()
 {
-  generate_cat_configuration (TRACE_get_viva_cat_conf(), "viva", 0);
+  generate_cat_configuration(TRACE_get_viva_cat_conf().c_str(), "viva", 0);
 }
 
 static int previous_trace_state = -1;
index fc6900e..ce66709 100644 (file)
@@ -164,19 +164,16 @@ void Container::logCreation()
     }
 
     if (not xbt_cfg_get_boolean("tracing/smpi/format/ti-one-file") || ti_unique_file == nullptr) {
-      char* folder_name = bprintf("%s_files", TRACE_get_filename());
-      char* filename    = bprintf("%s/%f_%s.txt", folder_name, prefix, name_.c_str());
+      std::string folder_name = TRACE_get_filename() + "_files";
+      std::string filename    = folder_name + "/" + std::to_string(prefix) + "_" + name_ + ".txt";
 #ifdef WIN32
-      _mkdir(folder_name);
+      _mkdir(folder_name.c_str());
 #else
-      mkdir(folder_name, S_IRWXU | S_IRWXG | S_IRWXO);
+      mkdir(folder_name.c_str(), S_IRWXU | S_IRWXG | S_IRWXO);
 #endif
-      ti_unique_file = fopen(filename, "w");
-      xbt_assert(ti_unique_file, "Tracefile %s could not be opened for writing: %s", filename, strerror(errno));
-      fprintf(tracing_file, "%s\n", filename);
-
-      xbt_free(folder_name);
-      xbt_free(filename);
+      ti_unique_file = fopen(filename.c_str(), "w");
+      xbt_assert(ti_unique_file, "Tracefile %s could not be opened for writing: %s", filename.c_str(), strerror(errno));
+      fprintf(tracing_file, "%s\n", filename.c_str());
     }
     tracing_files.insert({this, ti_unique_file});
   } else {
index 9c094b6..e4aea24 100644 (file)
@@ -119,13 +119,13 @@ void simgrid::instr::PajeEvent::insertIntoBuffer()
 }
 
 void TRACE_paje_start() {
-  char *filename = TRACE_get_filename();
-  tracing_file = fopen(filename, "w");
+  std::string filename = TRACE_get_filename();
+  tracing_file         = fopen(filename.c_str(), "w");
   if (tracing_file == nullptr){
-    THROWF (system_error, 1, "Tracefile %s could not be opened for writing.", filename);
+    THROWF(system_error, 1, "Tracefile %s could not be opened for writing.", filename.c_str());
   }
 
-  XBT_DEBUG("Filename %s is open for writing", filename);
+  XBT_DEBUG("Filename %s is open for writing", filename.c_str());
 
   /* output generator version */
   fprintf (tracing_file, "#This file was generated using SimGrid-%d.%d.%d\n",
@@ -150,19 +150,19 @@ void TRACE_paje_start() {
 
 void TRACE_paje_end() {
   fclose(tracing_file);
-  char *filename = TRACE_get_filename();
-  XBT_DEBUG("Filename %s is closed", filename);
+  XBT_DEBUG("Filename %s is closed", TRACE_get_filename().c_str());
 }
 
 
 void TRACE_TI_start()
 {
-  char *filename = TRACE_get_filename();
-  tracing_file = fopen(filename, "w");
-  if (tracing_file == nullptr)
-    THROWF(system_error, 1, "Tracefile %s could not be opened for writing.", filename);
+  std::string filename = TRACE_get_filename();
+  tracing_file         = fopen(filename.c_str(), "w");
+  if (tracing_file == nullptr) {
+    THROWF(system_error, 1, "Tracefile %s could not be opened for writing.", filename.c_str());
+  }
 
-  XBT_DEBUG("Filename %s is open for writing", filename);
+  XBT_DEBUG("Filename %s is open for writing", filename.c_str());
 
   /* output one line comment */
   dump_comment(TRACE_get_comment());
@@ -174,5 +174,5 @@ void TRACE_TI_start()
 void TRACE_TI_end()
 {
   fclose(tracing_file);
-  XBT_DEBUG("Filename %s is closed", TRACE_get_filename());
+  XBT_DEBUG("Filename %s is closed", TRACE_get_filename().c_str());
 }
index 60e6bca..a250924 100644 (file)
@@ -65,12 +65,12 @@ XBT_PRIVATE bool TRACE_onelink_only();
 XBT_PRIVATE bool TRACE_disable_destroy();
 XBT_PRIVATE bool TRACE_basic();
 XBT_PRIVATE bool TRACE_display_sizes();
-XBT_PRIVATE char* TRACE_get_comment();
-XBT_PRIVATE char* TRACE_get_comment_file();
 XBT_PRIVATE int TRACE_precision();
-XBT_PRIVATE char* TRACE_get_filename();
-XBT_PRIVATE char* TRACE_get_viva_uncat_conf();
-XBT_PRIVATE char* TRACE_get_viva_cat_conf();
+XBT_PRIVATE std::string TRACE_get_comment();
+XBT_PRIVATE std::string TRACE_get_comment_file();
+XBT_PRIVATE std::string TRACE_get_filename();
+XBT_PRIVATE std::string TRACE_get_viva_uncat_conf();
+XBT_PRIVATE std::string TRACE_get_viva_cat_conf();
 XBT_PRIVATE void TRACE_generate_viva_uncat_conf();
 XBT_PRIVATE void TRACE_generate_viva_cat_conf();
 XBT_PRIVATE void instr_pause_tracing();
index 67eb84b..53ebd7e 100644 (file)
@@ -34,6 +34,7 @@
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_ModelChecker, mc, "ModelChecker");
 
 ::simgrid::mc::ModelChecker* mc_model_checker = nullptr;
+extern std::string _sg_mc_dot_output_file;
 
 using simgrid::mc::remote;
 
@@ -96,7 +97,7 @@ void ModelChecker::start()
 
   process_->init();
 
-  if ((_sg_mc_dot_output_file != nullptr) && (_sg_mc_dot_output_file[0] != '\0'))
+  if (not _sg_mc_dot_output_file.empty())
     MC_init_dot_output();
 
   setup_ignore();
index b88f98d..a01cf12 100644 (file)
@@ -23,6 +23,7 @@
 #include "src/smpi/include/private.hpp"
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_Session, mc, "Model-checker session");
+extern std::string _sg_mc_dot_output_file;
 
 namespace simgrid {
 namespace mc {
@@ -122,7 +123,7 @@ void Session::logState()
 {
   mc_model_checker->getChecker()->logState();
 
-  if ((_sg_mc_dot_output_file != nullptr) && (_sg_mc_dot_output_file[0] != '\0')) {
+  if (not _sg_mc_dot_output_file.empty()) {
     fprintf(dot_output, "}\n");
     fclose(dot_output);
   }
index 3ff91d3..75e4cc2 100644 (file)
@@ -33,6 +33,7 @@
 #include "src/mc/remote/Client.hpp"
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_liveness, mc, "Logging specific to algorithms for liveness properties verification");
+extern std::string _sg_mc_property_file;
 
 /********* Static functions *********/
 
@@ -347,8 +348,8 @@ void LivenessChecker::backtrack()
 
 void LivenessChecker::run()
 {
-  XBT_INFO("Check the liveness property %s", _sg_mc_property_file);
-  MC_automaton_load(_sg_mc_property_file);
+  XBT_INFO("Check the liveness property %s", _sg_mc_property_file.c_str());
+  MC_automaton_load(_sg_mc_property_file.c_str());
 
   XBT_DEBUG("Starting the liveness algorithm");
   simgrid::mc::session->initialize();
index c094a75..277dead 100644 (file)
@@ -29,6 +29,7 @@
 #include "src/mc/remote/mc_protocol.h"
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_main, mc, "Entry point for simgrid-mc");
+extern std::string _sg_mc_property_file;
 
 static inline
 char** argvdup(int argc, char** argv)
@@ -39,18 +40,14 @@ char** argvdup(int argc, char** argv)
   return argv_copy;
 }
 
-static
-std::unique_ptr<simgrid::mc::Checker> createChecker(simgrid::mc::Session& session)
+static std::unique_ptr<simgrid::mc::Checker> createChecker(simgrid::mc::Session& session)
 {
   if (_sg_mc_comms_determinism || _sg_mc_send_determinism)
-    return std::unique_ptr<simgrid::mc::Checker>(
-      simgrid::mc::createCommunicationDeterminismChecker(session));
-  else if (_sg_mc_property_file == nullptr || _sg_mc_property_file[0] == '\0')
-    return std::unique_ptr<simgrid::mc::Checker>(
-      simgrid::mc::createSafetyChecker(session));
+    return std::unique_ptr<simgrid::mc::Checker>(simgrid::mc::createCommunicationDeterminismChecker(session));
+  else if (_sg_mc_property_file.empty())
+    return std::unique_ptr<simgrid::mc::Checker>(simgrid::mc::createSafetyChecker(session));
   else
-    return std::unique_ptr<simgrid::mc::Checker>(
-      simgrid::mc::createLivenessChecker(session));
+    return std::unique_ptr<simgrid::mc::Checker>(simgrid::mc::createLivenessChecker(session));
 }
 
 int main(int argc, char** argv)
index 429a995..eebd47b 100644 (file)
@@ -175,7 +175,7 @@ static int prng_random(int min, int max)
 
 int simcall_HANDLER_mc_random(smx_simcall_t simcall, int min, int max)
 {
-  if (not MC_is_active() && not MC_record_path)
+  if (not MC_is_active() && MC_record_path.empty())
     return prng_random(min, max);
   return simcall->mc_value;
 }
index 3295f91..9c531b3 100644 (file)
@@ -51,6 +51,8 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_checkpoint, mc, "Logging specific to mc_check
 #define PROT_RWX (PROT_READ | PROT_WRITE | PROT_EXEC)
 #define PROT_RW (PROT_READ | PROT_WRITE)
 #define PROT_RX (PROT_READ | PROT_EXEC)
+extern std::string _sg_mc_property_file;
+extern std::string _sg_mc_dot_output_file;
 
 namespace simgrid {
 namespace mc {
@@ -560,7 +562,7 @@ std::shared_ptr<simgrid::mc::Snapshot> take_snapshot(int num_state)
 
   snapshot->to_ignore = mc_model_checker->process().ignored_heap();
 
-  if (_sg_mc_max_visited_states > 0 || strcmp(_sg_mc_property_file, "")) {
+  if (_sg_mc_max_visited_states > 0 || not _sg_mc_property_file.empty()) {
     snapshot->stacks = take_snapshot_stacks(snapshot.get());
     if (_sg_mc_hash)
       snapshot->hash = simgrid::mc::hash(*snapshot);
index 566544c..d783988 100644 (file)
@@ -39,7 +39,7 @@ int _sg_mc_timeout = 0;
 
 void _mc_cfg_cb_timeout(const char *name)
 {
-  if (_sg_cfg_init_status && not(_sg_do_model_check || MC_record_path))
+  if (_sg_cfg_init_status && not(_sg_do_model_check || not MC_record_path.empty()))
     xbt_die("You are specifying a value to enable/disable timeout for wait requests after the initialization (through MSG_config?), but model-checking was not activated at config time (through bu the program was not runned under the model-checker (with simgrid-mc)). This won't work, sorry.");
 
   _sg_mc_timeout = xbt_cfg_get_boolean(name);
@@ -51,11 +51,11 @@ int _sg_do_model_check_record = 0;
 int _sg_mc_checkpoint = 0;
 int _sg_mc_sparse_checkpoint = 0;
 int _sg_mc_ksm = 0;
-char *_sg_mc_property_file = nullptr;
+std::string _sg_mc_property_file;
 int _sg_mc_hash = 0;
 int _sg_mc_max_depth = 1000;
 int _sg_mc_max_visited_states = 0;
-char *_sg_mc_dot_output_file = nullptr;
+std::string _sg_mc_dot_output_file;
 int _sg_mc_comms_determinism = 0;
 int _sg_mc_send_determinism = 0;
 int _sg_mc_snapshot_fds = 0;
@@ -67,14 +67,13 @@ void _mc_cfg_cb_reduce(const char *name)
     xbt_die
         ("You are specifying a reduction strategy after the initialization (through MSG_config?), but model-checking was not activated at config time (through bu the program was not runned under the model-checker (with simgrid-mc)). This won't work, sorry.");
 
-  char *val = xbt_cfg_get_string(name);
-  if (not strcasecmp(val, "none"))
+  std::string val = xbt_cfg_get_string(name);
+  if (val == "none")
     simgrid::mc::reduction_mode = simgrid::mc::ReductionMode::none;
-  else if (not strcasecmp(val, "dpor"))
+  else if (val == "dpor")
     simgrid::mc::reduction_mode = simgrid::mc::ReductionMode::dpor;
   else
-    xbt_die("configuration option %s can only take 'none' or 'dpor' as a value",
-            name);
+    xbt_die("configuration option %s can only take 'none' or 'dpor' as a value", name);
 }
 
 void _mc_cfg_cb_checkpoint(const char *name)
index b06c18d..cd9f830 100644 (file)
@@ -47,6 +47,8 @@
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_global, mc, "Logging specific to MC (global)");
 
+extern std::string _sg_mc_dot_output_file;
+
 namespace simgrid {
 namespace mc {
 
@@ -76,7 +78,7 @@ FILE *dot_output = nullptr;
 
 void MC_init_dot_output()
 {
-  dot_output = fopen(_sg_mc_dot_output_file, "w");
+  dot_output = fopen(_sg_mc_dot_output_file.c_str(), "w");
 
   if (dot_output == nullptr) {
     perror("Error open dot output file");
index 5939b84..b0011bd 100644 (file)
@@ -38,7 +38,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_record, mc,
   " Logging specific to MC record/replay facility");
 
 extern "C" {
-char* MC_record_path = nullptr;
+std::string MC_record_path;
 }
 
 namespace simgrid {
@@ -67,10 +67,10 @@ void replay(RecordTrace const& trace)
   }
 }
 
-void replay(const char* path_string)
+void replay(std::string path_string)
 {
   simgrid::mc::processes_time.resize(SIMIX_process_get_maxpid());
-  simgrid::mc::RecordTrace trace = simgrid::mc::parseRecordTrace(path_string);
+  simgrid::mc::RecordTrace trace = simgrid::mc::parseRecordTrace(path_string.c_str());
   simgrid::mc::replay(trace);
   simgrid::mc::processes_time.clear();
 }
index af99482..c9cb094 100644 (file)
@@ -34,7 +34,7 @@ XBT_PRIVATE std::string traceToString(simgrid::mc::RecordTrace const& trace);
 XBT_PRIVATE void dumpRecordPath();
 
 XBT_PRIVATE void replay(RecordTrace const& trace);
-XBT_PRIVATE void replay(const char* trace);
+XBT_PRIVATE void replay(std::string trace);
 }
 }
 
index fa295af..1b4c190 100644 (file)
@@ -14,11 +14,11 @@ SG_BEGIN_DECL()
  *
  *  This is using the format generated by traceToString().
  */
-XBT_PUBLIC_DATA(char*) MC_record_path;
+XBT_PUBLIC_DATA(std::string) MC_record_path;
 
 /** Whether the replay mode is enabled */
 static inline int MC_record_replay_is_active() {
-  return MC_record_path != 0;
+  return not MC_record_path.empty();
 }
 
 SG_END_DECL()
index c3066bd..6dd8fe9 100644 (file)
@@ -70,12 +70,12 @@ std::map<std::string, std::string>* Storage::getProperties()
   return simgrid::simix::kernelImmediate([this] { return pimpl_->getProperties(); });
 }
 
-const char* Storage::getProperty(const char* key)
+const char* Storage::getProperty(std::string key)
 {
   return this->pimpl_->getProperty(key);
 }
 
-void Storage::setProperty(const char* key, const char* value)
+void Storage::setProperty(std::string key, std::string value)
 {
   simgrid::simix::kernelImmediate([this, key, value] { this->pimpl_->setProperty(key, value); });
 }
index 752cf85..17bb94f 100644 (file)
@@ -112,11 +112,11 @@ static void _sg_cfg_cb__plugin(const char *name)
 {
   xbt_assert(_sg_cfg_init_status < 2, "Cannot load a plugin after the initialization");
 
-  char *val = xbt_cfg_get_string(name);
-  if (val==nullptr || val[0] == '\0')
+  std::string val = xbt_cfg_get_string(name);
+  if (val.empty())
     return;
 
-  if (not strcmp(val, "help")) {
+  if (val == "help") {
     model_help("plugin", surf_plugin_description);
     sg_cfg_exit_early();
   }
@@ -130,8 +130,8 @@ static void _sg_cfg_cb__host_model(const char *name)
 {
   xbt_assert(_sg_cfg_init_status < 2, "Cannot change the model after the initialization");
 
-  char *val = xbt_cfg_get_string(name);
-  if (not strcmp(val, "help")) {
+  std::string val = xbt_cfg_get_string(name);
+  if (val == "help") {
     model_help("host", surf_host_model_description);
     sg_cfg_exit_early();
   }
@@ -145,8 +145,8 @@ static void _sg_cfg_cb__cpu_model(const char *name)
 {
   xbt_assert(_sg_cfg_init_status < 2, "Cannot change the model after the initialization");
 
-  char *val = xbt_cfg_get_string(name);
-  if (not strcmp(val, "help")) {
+  std::string val = xbt_cfg_get_string(name);
+  if (val == "help") {
     model_help("CPU", surf_cpu_model_description);
     sg_cfg_exit_early();
   }
@@ -160,8 +160,8 @@ static void _sg_cfg_cb__optimization_mode(const char *name)
 {
   xbt_assert(_sg_cfg_init_status < 2, "Cannot change the model after the initialization");
 
-  char *val = xbt_cfg_get_string(name);
-  if (not strcmp(val, "help")) {
+  std::string val = xbt_cfg_get_string(name);
+  if (val == "help") {
     model_help("optimization", surf_optimization_mode_description);
     sg_cfg_exit_early();
   }
@@ -175,8 +175,8 @@ static void _sg_cfg_cb__storage_mode(const char *name)
 {
   xbt_assert(_sg_cfg_init_status < 2, "Cannot change the model after the initialization");
 
-  char *val = xbt_cfg_get_string(name);
-  if (not strcmp(val, "help")) {
+  std::string val = xbt_cfg_get_string(name);
+  if (val == "help") {
     model_help("storage", surf_storage_model_description);
     sg_cfg_exit_early();
   }
@@ -189,8 +189,8 @@ static void _sg_cfg_cb__network_model(const char *name)
 {
   xbt_assert(_sg_cfg_init_status < 2, "Cannot change the model after the initialization");
 
-  char *val = xbt_cfg_get_string(name);
-  if (not strcmp(val, "help")) {
+  std::string val = xbt_cfg_get_string(name);
+  if (val == "help") {
     model_help("network", surf_network_model_description);
     sg_cfg_exit_early();
   }
@@ -203,8 +203,6 @@ static void _sg_cfg_cb__network_model(const char *name)
 
 static void _sg_cfg_cb_model_check_replay(const char *name) {
   MC_record_path = xbt_cfg_get_string(name);
-  if (MC_record_path[0] == '\0')
-    MC_record_path = nullptr;
 }
 
 #if SIMGRID_HAVE_MC
@@ -250,15 +248,14 @@ static void _sg_cfg_cb_contexts_parallel_threshold(const char *name)
 
 static void _sg_cfg_cb_contexts_parallel_mode(const char *name)
 {
-  const char* mode_name = xbt_cfg_get_string(name);
-  if (not strcmp(mode_name, "posix")) {
+  std::string mode_name = xbt_cfg_get_string(name);
+  if (mode_name == "posix") {
     SIMIX_context_set_parallel_mode(XBT_PARMAP_POSIX);
-  } else if (not strcmp(mode_name, "futex")) {
+  } else if (mode_name == "futex") {
     SIMIX_context_set_parallel_mode(XBT_PARMAP_FUTEX);
-  } else if (not strcmp(mode_name, "busy_wait")) {
+  } else if (mode_name == "busy_wait") {
     SIMIX_context_set_parallel_mode(XBT_PARMAP_BUSY_WAIT);
-  }
-  else {
+  } else {
     xbt_die("Command line setting of the parallel synchronization mode should "
             "be one of \"posix\", \"futex\" or \"busy_wait\"");
   }
@@ -300,7 +297,7 @@ void sg_config_init(int *argc, char **argv)
 
   /* Plugins configuration */
   describe_model(description, descsize, surf_plugin_description, "plugin", "The plugins");
-  xbt_cfg_register_string("plugin", nullptr, &_sg_cfg_cb__plugin, description);
+  xbt_cfg_register_string("plugin", "", &_sg_cfg_cb__plugin, description);
 
   describe_model(description, descsize, surf_cpu_model_description, "model", "The model to use for the CPU");
   xbt_cfg_register_string("cpu/model", "Cas01", &_sg_cfg_cb__cpu_model, description);
index 0644ac7..6452ba7 100644 (file)
@@ -411,7 +411,7 @@ static bool SIMIX_execute_tasks()
  */
 void SIMIX_run()
 {
-  if (MC_record_path) {
+  if (not MC_record_path.empty()) {
     simgrid::mc::replay(MC_record_path);
     return;
   }
index 57ddfa1..3606038 100644 (file)
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_coll, smpi, "Logging specific to SMPI (coll)");
 
-#define COLL_SETTER(cat, ret, args, args2)\
-int (*Colls::cat ) args;\
-void Colls::set_##cat (const char * name){\
-    int id = find_coll_description(mpi_coll_## cat ##_description,\
-                                             name,#cat);\
-    cat = reinterpret_cast<ret (*) args>\
-        (mpi_coll_## cat ##_description[id].coll);\
-    if (cat == nullptr)\
-      xbt_die("Collective "#cat" set to nullptr!");\
-}
+#define COLL_SETTER(cat, ret, args, args2)                                                                             \
+  int(*Colls::cat) args;                                                                                               \
+  void Colls::set_##cat(std::string name)                                                                              \
+  {                                                                                                                    \
+    int id = find_coll_description(mpi_coll_##cat##_description, name, #cat);                                          \
+    cat    = reinterpret_cast<ret(*) args>(mpi_coll_##cat##_description[id].coll);                                     \
+    if (cat == nullptr)                                                                                                \
+      xbt_die("Collective " #cat " set to nullptr!");                                                                  \
+  }
 
-#define SET_COLL(coll)\
-    name = xbt_cfg_get_string("smpi/"#coll);\
-    if (name==nullptr || name[0] == '\0')\
-        name = selector_name;\
-    set_##coll(name);
+#define SET_COLL(coll)                                                                                                 \
+  name = xbt_cfg_get_string("smpi/" #coll);                                                                            \
+  if (name.empty())                                                                                                    \
+    name = selector_name;                                                                                              \
+  set_##coll(name);
 
 namespace simgrid{
 namespace smpi{
@@ -68,30 +67,25 @@ void Colls::coll_help(const char *category, s_mpi_coll_description_t * table)
     XBT_WARN("  %s: %s\n", table[i].name, table[i].description);
 }
 
-int Colls::find_coll_description(s_mpi_coll_description_t * table, const char *name, const char *desc)
+int Colls::find_coll_description(s_mpi_coll_description_t* table, std::string name, const char* desc)
 {
-  char *name_list = nullptr;
   for (int i = 0; table[i].name; i++)
-    if (not strcmp(name, table[i].name)) {
+    if (name == table[i].name) {
       if (strcmp(table[i].name,"default"))
         XBT_INFO("Switch to algorithm %s for collective %s",table[i].name,desc);
       return i;
     }
 
   if (not table[0].name)
-    xbt_die("No collective is valid for '%s'! This is a bug.",name);
-  name_list = xbt_strdup(table[0].name);
-  for (int i = 1; table[i].name; i++) {
-    name_list = static_cast<char*>(xbt_realloc(name_list, strlen(name_list) + strlen(table[i].name) + 3));
-    strncat(name_list, ", ",2);
-    strncat(name_list, table[i].name, strlen(table[i].name));
-  }
-  xbt_die("Collective '%s' is invalid! Valid collectives are: %s.", name, name_list);
+    xbt_die("No collective is valid for '%s'! This is a bug.", name.c_str());
+  std::string name_list = std::string(table[0].name);
+  for (int i = 1; table[i].name; i++)
+    name_list = name_list + ", " + table[i].name;
+
+  xbt_die("Collective '%s' is invalid! Valid collectives are: %s.", name.c_str(), name_list.c_str());
   return -1;
 }
 
-
-
 COLL_APPLY(COLL_SETTER,COLL_GATHER_SIG,"");
 COLL_APPLY(COLL_SETTER,COLL_ALLGATHER_SIG,"");
 COLL_APPLY(COLL_SETTER,COLL_ALLGATHERV_SIG,"");
@@ -106,23 +100,23 @@ COLL_APPLY(COLL_SETTER,COLL_ALLTOALLV_SIG,"");
 
 
 void Colls::set_collectives(){
-    const char* selector_name = static_cast<char*>(xbt_cfg_get_string("smpi/coll-selector"));
-    if (selector_name==nullptr || selector_name[0] == '\0')
-        selector_name = "default";
-
-    const char* name;
-
-    SET_COLL(gather);
-    SET_COLL(allgather);
-    SET_COLL(allgatherv);
-    SET_COLL(allreduce);
-    SET_COLL(alltoall);
-    SET_COLL(alltoallv);
-    SET_COLL(reduce);
-    SET_COLL(reduce_scatter);
-    SET_COLL(scatter);
-    SET_COLL(bcast);
-    SET_COLL(barrier);
+  std::string selector_name = xbt_cfg_get_string("smpi/coll-selector");
+  if (selector_name.empty())
+    selector_name = "default";
+
+  std::string name;
+
+  SET_COLL(gather);
+  SET_COLL(allgather);
+  SET_COLL(allgatherv);
+  SET_COLL(allreduce);
+  SET_COLL(alltoall);
+  SET_COLL(alltoallv);
+  SET_COLL(reduce);
+  SET_COLL(reduce_scatter);
+  SET_COLL(scatter);
+  SET_COLL(bcast);
+  SET_COLL(barrier);
 }
 
 
index 02261ca..26c3ea0 100644 (file)
@@ -6,6 +6,7 @@
 #ifndef SMPI_PRIVATE_HPP
 #define SMPI_PRIVATE_HPP
 
+#include "include/xbt/config.hpp"
 #include "simgrid/msg.h" // msg_bar_t
 #include "smpi/smpi.h"
 #include "src/instr/instr_smpi.hpp"
index 3993774..99a7377 100644 (file)
 
 /** \brief MPI collective description */
 
-#define COLL_DEFS(cat, ret, args, args2)\
-    static void set_##cat(const char* name);\
-    static s_mpi_coll_description_t mpi_coll_##cat##_description[];\
-    static int (*cat ) args;
+#define COLL_DEFS(cat, ret, args, args2)                                                                               \
+  static void set_##cat(std::string name);                                                                             \
+  static s_mpi_coll_description_t mpi_coll_##cat##_description[];                                                      \
+  static int(*cat) args;
 
 #define COLL_SIG(cat, ret, args, args2)\
     static int cat args;
@@ -91,7 +91,7 @@ struct s_mpi_coll_description_t {
 class Colls{
   public:
     static XBT_PUBLIC(void) coll_help(const char *category, s_mpi_coll_description_t * table);
-    static XBT_PUBLIC(int) find_coll_description(s_mpi_coll_description_t * table, const char *name, const char *desc);
+    static XBT_PUBLIC(int) find_coll_description(s_mpi_coll_description_t* table, std::string name, const char* desc);
     static void set_collectives();
 
     // for each collective type, create the set_* prototype, the description array and the function pointer
index 5d2df18..7f8dd61 100644 (file)
@@ -86,7 +86,7 @@ void smpi_bench_begin()
     return;
 
 #if HAVE_PAPI
-  if (xbt_cfg_get_string("smpi/papi-events")[0] != '\0') {
+  if (not xbt_cfg_get_string("smpi/papi-events").empty()) {
     int event_set = smpi_process()->papi_event_set();
     // PAPI_start sets everything to 0! See man(3) PAPI_start
     if (PAPI_LOW_LEVEL_INITED == PAPI_is_initialized()) {
index 351a95e..0a66fcf 100644 (file)
@@ -251,8 +251,8 @@ void smpi_global_init()
     xbt_os_walltimer_start(global_timer);
   }
 
-  if (xbt_cfg_get_string("smpi/comp-adjustment-file")[0] != '\0') {
-    std::string filename {xbt_cfg_get_string("smpi/comp-adjustment-file")};
+  std::string filename = xbt_cfg_get_string("smpi/comp-adjustment-file");
+  if (not filename.empty()) {
     std::ifstream fstream(filename);
     if (not fstream.is_open()) {
       xbt_die("Could not open file %s. Does it exist?", filename.c_str());
@@ -278,7 +278,7 @@ void smpi_global_init()
   // and the (computed) event_set.
   std::map</* computation unit name */ std::string, papi_process_data> units2papi_setup;
 
-  if (xbt_cfg_get_string("smpi/papi-events")[0] != '\0') {
+  if (not xbt_cfg_get_string("smpi/papi-events").empty()) {
     if (PAPI_library_init(PAPI_VER_CURRENT) != PAPI_VER_CURRENT)
       XBT_ERROR("Could not initialize PAPI library; is it correctly installed and linked?"
                 " Expected version is %i",
@@ -286,7 +286,7 @@ void smpi_global_init()
 
     typedef boost::tokenizer<boost::char_separator<char>> Tokenizer;
     boost::char_separator<char> separator_units(";");
-    std::string str = std::string(xbt_cfg_get_string("smpi/papi-events"));
+    std::string str = xbt_cfg_get_string("smpi/papi-events");
     Tokenizer tokens(str, separator_units);
 
     // Iterate over all the computational units. This could be processes, hosts, threads, ranks... You name it.
@@ -432,31 +432,24 @@ static void smpi_init_logs(){
 }
 
 static void smpi_init_options(){
-    //return if already called
-    if (smpi_cpu_threshold > -1)
-      return;
-    simgrid::smpi::Colls::set_collectives();
-    simgrid::smpi::Colls::smpi_coll_cleanup_callback=nullptr;
-    smpi_cpu_threshold = xbt_cfg_get_double("smpi/cpu-threshold");
-    smpi_host_speed = xbt_cfg_get_double("smpi/host-speed");
-    const char* smpi_privatize_option               = xbt_cfg_get_string("smpi/privatization");
-    if (std::strcmp(smpi_privatize_option, "no") == 0)
-      smpi_privatize_global_variables = SMPI_PRIVATIZE_NONE;
-    else if (std::strcmp(smpi_privatize_option, "yes") == 0)
-      smpi_privatize_global_variables = SMPI_PRIVATIZE_DEFAULT;
-    else if (std::strcmp(smpi_privatize_option, "mmap") == 0)
-      smpi_privatize_global_variables = SMPI_PRIVATIZE_MMAP;
-    else if (std::strcmp(smpi_privatize_option, "dlopen") == 0)
-      smpi_privatize_global_variables = SMPI_PRIVATIZE_DLOPEN;
-
-    // Some compatibility stuff:
-    else if (std::strcmp(smpi_privatize_option, "1") == 0)
-      smpi_privatize_global_variables = SMPI_PRIVATIZE_DEFAULT;
-    else if (std::strcmp(smpi_privatize_option, "0") == 0)
-      smpi_privatize_global_variables = SMPI_PRIVATIZE_NONE;
-
-    else
-      xbt_die("Invalid value for smpi/privatization: '%s'", smpi_privatize_option);
+  // return if already called
+  if (smpi_cpu_threshold > -1)
+    return;
+  simgrid::smpi::Colls::set_collectives();
+  simgrid::smpi::Colls::smpi_coll_cleanup_callback = nullptr;
+  smpi_cpu_threshold                               = xbt_cfg_get_double("smpi/cpu-threshold");
+  smpi_host_speed                                  = xbt_cfg_get_double("smpi/host-speed");
+  std::string smpi_privatize_option                = xbt_cfg_get_string("smpi/privatization");
+  if (smpi_privatize_option == "no" || smpi_privatize_option == "0")
+    smpi_privatize_global_variables = SMPI_PRIVATIZE_NONE;
+  else if (smpi_privatize_option == "yes" || smpi_privatize_option == "1")
+    smpi_privatize_global_variables = SMPI_PRIVATIZE_DEFAULT;
+  else if (smpi_privatize_option == "mmap")
+    smpi_privatize_global_variables = SMPI_PRIVATIZE_MMAP;
+  else if (smpi_privatize_option == "dlopen")
+    smpi_privatize_global_variables = SMPI_PRIVATIZE_DLOPEN;
+  else
+    xbt_die("Invalid value for smpi/privatization: '%s'", smpi_privatize_option.c_str());
 
 #if defined(__FreeBSD__)
     if (smpi_privatize_global_variables == SMPI_PRIVATIZE_MMAP) {
@@ -468,7 +461,7 @@ static void smpi_init_options(){
     if (smpi_cpu_threshold < 0)
       smpi_cpu_threshold = DBL_MAX;
 
-    char* val = xbt_cfg_get_string("smpi/shared-malloc");
+    const char* val = xbt_cfg_get_string("smpi/shared-malloc").c_str();
     if (not strcasecmp(val, "yes") || not strcmp(val, "1") || not strcasecmp(val, "on") ||
         not strcasecmp(val, "global")) {
       smpi_cfg_shared_malloc = shmalloc_global;
index 9f30550..8ed34e8 100644 (file)
@@ -191,8 +191,8 @@ static void *smpi_shared_malloc_local(size_t size, const char *file, int line)
 
 void* smpi_shared_malloc_partial(size_t size, size_t* shared_block_offsets, int nb_shared_blocks)
 {
-  char *huge_page_mount_point = xbt_cfg_get_string("smpi/shared-malloc-hugepage");
-  bool use_huge_page = huge_page_mount_point[0] != '\0';
+  std::string huge_page_mount_point = xbt_cfg_get_string("smpi/shared-malloc-hugepage");
+  bool use_huge_page                = not huge_page_mount_point.empty();
 #ifndef MAP_HUGETLB /* If the system header don't define that mmap flag */
   xbt_assert(not use_huge_page,
              "Huge pages are not available on your system, you cannot use the smpi/shared-malloc-hugepage option.");
@@ -232,11 +232,10 @@ void* smpi_shared_malloc_partial(size_t size, size_t* shared_block_offsets, int
    * We cannot use a same file for the two type of calls, since the first one needs to be
    * opened in a hugetlbfs mount point whereas the second needs to be a "classical" file. */
   if(use_huge_page && smpi_shared_malloc_bogusfile_huge_page == -1) {
-    char* huge_page_filename               = bprintf("%s/simgrid-shmalloc-XXXXXX", huge_page_mount_point);
-    smpi_shared_malloc_bogusfile_huge_page = mkstemp(huge_page_filename);
-    XBT_DEBUG("bogusfile_huge_page: %s\n", huge_page_filename);
-    unlink(huge_page_filename);
-    xbt_free(huge_page_filename);
+    std::string huge_page_filename         = huge_page_mount_point + "/simgrid-shmalloc-XXXXXX";
+    smpi_shared_malloc_bogusfile_huge_page = mkstemp((char*)huge_page_filename.c_str());
+    XBT_DEBUG("bogusfile_huge_page: %s\n", huge_page_filename.c_str());
+    unlink(huge_page_filename.c_str());
   }
   if(smpi_shared_malloc_bogusfile == -1) {
     char name[]                  = "/tmp/simgrid-shmalloc-XXXXXX";
index 86594e1..fb514c3 100644 (file)
@@ -11,7 +11,7 @@
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_utils, smpi, "Logging specific to SMPI (utils)");
 
-std::vector<s_smpi_factor_t> parse_factor(const char *smpi_coef_string)
+std::vector<s_smpi_factor_t> parse_factor(std::string smpi_coef_string)
 {
   std::vector<s_smpi_factor_t> smpi_factor;
 
@@ -19,8 +19,7 @@ std::vector<s_smpi_factor_t> parse_factor(const char *smpi_coef_string)
   typedef boost::tokenizer<boost::char_separator<char>> Tokenizer;
   boost::char_separator<char> sep(";");
   boost::char_separator<char> factor_separator(":");
-  std::string tmp_string(smpi_coef_string);
-  Tokenizer tokens(tmp_string, sep);
+  Tokenizer tokens(smpi_coef_string, sep);
 
   /**
    * Iterate over patterns like A:B:C:D;E:F;G:H
@@ -34,7 +33,7 @@ std::vector<s_smpi_factor_t> parse_factor(const char *smpi_coef_string)
     Tokenizer factor_values(*token_iter, factor_separator);
     s_smpi_factor_t fact;
     if (factor_values.begin() == factor_values.end()) {
-      xbt_die("Malformed radical for smpi factor: '%s'", smpi_coef_string);
+      xbt_die("Malformed radical for smpi factor: '%s'", smpi_coef_string.c_str());
     }
     unsigned int iteration = 0;
     for (Tokenizer::iterator factor_iter = factor_values.begin(); factor_iter != factor_values.end(); ++factor_iter) {
index e7657a2..6298706 100644 (file)
@@ -13,7 +13,8 @@ PropertyHolder::~PropertyHolder() {
 }
 
 /** @brief Return the property associated to the provided key (or nullptr if not existing) */
-const char *PropertyHolder::getProperty(const char*key) {
+const char* PropertyHolder::getProperty(std::string key)
+{
   if (properties_ == nullptr)
     return nullptr;
   auto prop = properties_->find(key);
index 0dfe679..64633b3 100644 (file)
@@ -21,7 +21,7 @@ public:
   PropertyHolder() = default;
   ~PropertyHolder();
 
-  const char *getProperty(const char*id);
+  const char* getProperty(std::string key);
   void setProperty(std::string id, std::string value);
 
   /* FIXME: This should not be exposed, as users may do bad things with the dict they got (it's not a copy).
index 446d217..40d145e 100644 (file)
@@ -19,8 +19,7 @@ void surf_cpu_model_init_Cas01()
   xbt_assert(not surf_cpu_model_pm);
   xbt_assert(not surf_cpu_model_vm);
 
-  char *optim = xbt_cfg_get_string("cpu/optim");
-  if (not strcmp(optim, "TI")) {
+  if (xbt_cfg_get_string("cpu/optim") == "TI") {
     surf_cpu_model_init_ti();
     return;
   }
@@ -37,19 +36,19 @@ namespace surf {
 
 CpuCas01Model::CpuCas01Model() : simgrid::surf::CpuModel()
 {
-  char *optim = xbt_cfg_get_string("cpu/optim");
+  std::string optim = xbt_cfg_get_string("cpu/optim");
   bool select = xbt_cfg_get_boolean("cpu/maxmin-selective-update");
 
-  if (not strcmp(optim, "Full")) {
+  if (optim == "Full") {
     setUpdateMechanism(UM_FULL);
     selectiveUpdate_ = select;
-  } else if (not strcmp(optim, "Lazy")) {
+  } else if (optim == "Lazy") {
     setUpdateMechanism(UM_LAZY);
     selectiveUpdate_ = true;
     xbt_assert(select || (xbt_cfg_is_default_value("cpu/maxmin-selective-update")),
                "Disabling selective update while using the lazy update mechanism is dumb!");
   } else {
-    xbt_die("Unsupported optimization (%s) for this model", optim);
+    xbt_die("Unsupported optimization (%s) for this model", optim.c_str());
   }
 
   p_cpuRunningActionSetThatDoesNotNeedBeingChecked = new ActionList();
index fe1a8dc..fe92ad9 100644 (file)
@@ -134,19 +134,19 @@ namespace surf {
 NetworkCm02Model::NetworkCm02Model()
   :NetworkModel()
 {
-  char *optim = xbt_cfg_get_string("network/optim");
+  std::string optim = xbt_cfg_get_string("network/optim");
   bool select = xbt_cfg_get_boolean("network/maxmin-selective-update");
 
-  if (not strcmp(optim, "Full")) {
+  if (optim == "Full") {
     setUpdateMechanism(UM_FULL);
     selectiveUpdate_ = select;
-  } else if (not strcmp(optim, "Lazy")) {
+  } else if (optim == "Lazy") {
     setUpdateMechanism(UM_LAZY);
     selectiveUpdate_ = true;
     xbt_assert(select || (xbt_cfg_is_default_value("network/maxmin-selective-update")),
                "You cannot disable selective update when using the lazy update mechanism");
   } else {
-    xbt_die("Unsupported optimization (%s) for this model. Accepted: Full, Lazy.", optim);
+    xbt_die("Unsupported optimization (%s) for this model. Accepted: Full, Lazy.", optim.c_str());
   }
 
   maxminSystem_ = lmm_system_new(selectiveUpdate_);
index 7d7c324..9f0e10c 100644 (file)
@@ -104,7 +104,7 @@ namespace surf {
 
 NetworkIBModel::NetworkIBModel() : NetworkSmpiModel()
 {
-  const char* IB_factors_string = xbt_cfg_get_string("smpi/IB-penalty-factors");
+  std::string IB_factors_string = xbt_cfg_get_string("smpi/IB-penalty-factors");
   std::vector<std::string> radical_elements;
   boost::split(radical_elements, IB_factors_string, boost::is_any_of(";"));
 
index d6f9e7d..ad5d651 100644 (file)
@@ -521,10 +521,10 @@ void sg_platf_end() {
 /* Pick the right models for CPU, net and host, and call their model_init_preparse */
 static void surf_config_models_setup()
 {
-  const char* host_model_name    = xbt_cfg_get_string("host/model");
-  const char* network_model_name = xbt_cfg_get_string("network/model");
-  const char* cpu_model_name     = xbt_cfg_get_string("cpu/model");
-  const char* storage_model_name = xbt_cfg_get_string("storage/model");
+  std::string host_model_name    = xbt_cfg_get_string("host/model");
+  std::string network_model_name = xbt_cfg_get_string("network/model");
+  std::string cpu_model_name     = xbt_cfg_get_string("cpu/model");
+  std::string storage_model_name = xbt_cfg_get_string("storage/model");
 
   /* The compound host model is needed when using non-default net/cpu models */
   if ((not xbt_cfg_is_default_value("network/model") || not xbt_cfg_is_default_value("cpu/model")) &&
@@ -533,10 +533,10 @@ static void surf_config_models_setup()
     xbt_cfg_set_string("host/model", host_model_name);
   }
 
-  XBT_DEBUG("host model: %s", host_model_name);
-  if (not strcmp(host_model_name, "compound")) {
-    xbt_assert(cpu_model_name, "Set a cpu model to use with the 'compound' host model");
-    xbt_assert(network_model_name, "Set a network model to use with the 'compound' host model");
+  XBT_DEBUG("host model: %s", host_model_name.c_str());
+  if (host_model_name == "compound") {
+    xbt_assert(not cpu_model_name.empty(), "Set a cpu model to use with the 'compound' host model");
+    xbt_assert(not network_model_name.empty(), "Set a network model to use with the 'compound' host model");
 
     int cpu_id = find_model_description(surf_cpu_model_description, cpu_model_name);
     surf_cpu_model_description[cpu_id].model_init_preparse();
index 77bc7ca..bd45679 100644 (file)
@@ -239,23 +239,20 @@ void model_help(const char *category, s_surf_model_description_t * table)
     printf("  %s: %s\n", table[i].name, table[i].description);
 }
 
-int find_model_description(s_surf_model_description_t* table, const char* name)
+int find_model_description(s_surf_model_description_t* table, std::string name)
 {
   for (int i = 0; table[i].name; i++)
-    if (not strcmp(name, table[i].name)) {
+    if (name == table[i].name)
       return i;
-    }
 
   if (not table[0].name)
     xbt_die("No model is valid! This is a bug.");
 
-  char* name_list = xbt_strdup(table[0].name);
-  for (int i = 1; table[i].name; i++) {
-    name_list = (char *) xbt_realloc(name_list, strlen(name_list) + strlen(table[i].name) + 3);
-    strncat(name_list, ", ", 2);
-    strncat(name_list, table[i].name, strlen(table[i].name));
-  }
-  xbt_die("Model '%s' is invalid! Valid models are: %s.", name, name_list);
+  std::string name_list = std::string(table[0].name);
+  for (int i = 1; table[i].name; i++)
+    name_list = name_list + ", " + table[i].name;
+
+  xbt_die("Model '%s' is invalid! Valid models are: %s.", name.c_str(), name_list.c_str());
   return -1;
 }
 
index 5b8ec4a..0d2265d 100644 (file)
@@ -14,6 +14,7 @@
 #include <map>
 #include <stdexcept>
 #include <string>
+#include <string>
 #include <type_traits>
 #include <typeinfo>
 #include <vector>
@@ -458,8 +459,7 @@ void xbt_cfg_register_string(const char *name, const char *default_value, xbt_cf
     simgrid_config = xbt_cfg_new();
     atexit(sg_config_finalize);
   }
-  simgrid_config->registerOption<std::string>(name, desc,
-    default_value ? default_value : "", cb_set);
+  simgrid_config->registerOption<std::string>(name, desc, default_value ? default_value : "", cb_set);
 }
 
 void xbt_cfg_register_boolean(const char *name, const char*default_value,xbt_cfg_cb_t cb_set, const char *desc)
@@ -657,13 +657,13 @@ void xbt_cfg_set_double(const char *key, double value)
  * @param value the value to be added
  *
  */
-void xbt_cfg_set_string(const char *key, const char *value)
+void xbt_cfg_set_string(const char* key, std::string value)
 {
   try {
-    (*simgrid_config)[key].setValue<std::string>(value ? value : "");
+    (*simgrid_config)[key].setValue<std::string>(value);
     return;
   }
-  TRANSLATE_EXCEPTIONS("Could not set variable %s to string %s", key, value);
+  TRANSLATE_EXCEPTIONS("Could not set variable %s to string %s", key, value.c_str());
 }
 
 /** @brief Set or add a boolean value to \a name within \a cfg
@@ -729,10 +729,10 @@ double xbt_cfg_get_double(const char *key)
  *
  * \warning the returned value is the actual content of the config set
  */
-char *xbt_cfg_get_string(const char *key)
+std::string xbt_cfg_get_string(const char* key)
 {
   try {
-    return (char*) (*simgrid_config)[key].getValue<std::string>().c_str();
+    return (*simgrid_config)[key].getValue<std::string>();
   }
   TRANSLATE_EXCEPTIONS("Could not get variable %s", key);
 }