Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
save a vector, kill a dynar!
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Tue, 17 Dec 2019 14:00:45 +0000 (15:00 +0100)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Tue, 17 Dec 2019 17:09:10 +0000 (18:09 +0100)
include/simgrid/jedule/jedule_platform.hpp
include/xbt/log.hpp
include/xbt/virtu.h
src/bindings/java/JavaContext.cpp
src/bindings/java/jmsg.cpp
src/instr/instr_config.cpp
src/instr/jedule/jedule_sd_binding.cpp
src/smpi/internals/smpi_memory.cpp
src/xbt/xbt_main.cpp

index cf5b0e0..ed27a85 100644 (file)
@@ -7,7 +7,6 @@
 #define JED_SIMGRID_PLATFORM_H_
 
 #include <simgrid/forward.h>
-#include <xbt/dynar.h>
 
 #include <memory>
 #include <string>
index 3f74fb5..76221a7 100644 (file)
@@ -19,5 +19,6 @@ namespace xbt {
 XBT_PUBLIC void log_exception(e_xbt_log_priority_t priority, const char* context, std::exception const& exception);
 
 XBT_PUBLIC void install_exception_handler();
-}
-}
+
+} // namespace xbt
+} // namespace simgrid
index 98cd941..05be643 100644 (file)
@@ -19,11 +19,20 @@ XBT_PUBLIC const char* xbt_procname(void);
 
 XBT_PUBLIC int xbt_getpid(void);
 
-/* Get the name of the UNIX process englobing the world */
-XBT_PUBLIC_DATA char* xbt_binary_name;
+SG_END_DECL
+
+#ifdef __cplusplus
+#include <string>
+#include <vector>
+namespace simgrid {
+namespace xbt {
 
+/* Get the name of the UNIX process englobing the world */
+XBT_PUBLIC_DATA std::string binary_name;
 /** Contains all the parameters we got from the command line (including argv[0]) */
-XBT_PUBLIC_DATA xbt_dynar_t xbt_cmdline;
+XBT_PUBLIC_DATA std::vector<std::string> cmdline;
 
-SG_END_DECL
+} // namespace xbt
+} // namespace simgrid
+#endif
 #endif /* XBT_VIRTU_H */
index ad355eb..1622e85 100644 (file)
@@ -29,7 +29,7 @@ ContextFactory* java_factory()
 
 JavaContextFactory::JavaContextFactory() : ContextFactory()
 {
-  xbt_assert(xbt_binary_name && strcmp(xbt_binary_name, "java") == 0); // Set by Java_org_simgrid_msg_Msg_init
+  xbt_assert(xbt::binary_name == "java");
 }
 
 JavaContextFactory::~JavaContextFactory()=default;
index 66231b3..ddbac3b 100644 (file)
@@ -104,7 +104,7 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_init(JNIEnv * env, jclass cls, j
     argc += static_cast<int>(env->GetArrayLength(jargs));
   xbt_assert(argc > 0);
 
-  // Need a static storage because the XBT layer saves the arguments in xbt_binary_name and xbt_cmdline.
+  // Need a static storage because the XBT layer saves the arguments in xbt::binary_name and xbt::cmdline.
   static std::vector<std::string> args;
   args.reserve(argc);
 
index fcddfde..a704abf 100644 (file)
@@ -9,7 +9,7 @@
 #include "simgrid/version.h"
 #include "src/instr/instr_private.hpp"
 #include "surf/surf.hpp"
-#include "xbt/virtu.h" /* xbt_cmdline */
+#include "xbt/virtu.h" /* xbt::cmdline */
 
 #include <fstream>
 #include <string>
@@ -117,9 +117,7 @@ static void TRACE_start()
       tracing_file << "#This file was generated using SimGrid-" << SIMGRID_VERSION_MAJOR << "." << SIMGRID_VERSION_MINOR
                    << "." << SIMGRID_VERSION_PATCH << std::endl;
       tracing_file << "#[";
-      unsigned int cpt;
-      char* str;
-      xbt_dynar_foreach (xbt_cmdline, cpt, str) {
+      for (auto str : simgrid::xbt::cmdline) {
         tracing_file << str << " ";
       }
       tracing_file << "]" << std::endl;
index 5819009..918cfaa 100644 (file)
@@ -4,10 +4,9 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "simgrid/jedule/jedule.hpp"
-#include "src/simdag/simdag_private.hpp"
-
 #include "simgrid/s4u/Engine.hpp"
 #include "simgrid/s4u/NetZone.hpp"
+#include "src/simdag/simdag_private.hpp"
 
 #if SIMGRID_HAVE_JEDULE
 
@@ -43,19 +42,18 @@ void jedule_sd_exit()
 void jedule_sd_dump(const char * filename)
 {
   if (my_jedule) {
-    char *fname;
+    std::string fname;
     if (not filename) {
-      fname = bprintf("%s.jed", xbt_binary_name);
+      fname = simgrid::xbt::binary_name + ".jed";
     } else {
-      fname = xbt_strdup(filename);
+      fname = filename;
     }
 
-    FILE *fh = fopen(fname, "w");
+    FILE* fh = fopen(fname.c_str(), "w");
 
     my_jedule->write_output(fh);
 
     fclose(fh);
-    xbt_free(fname);
   }
 }
 #endif
index a315b6c..8a99ebc 100644 (file)
@@ -56,8 +56,9 @@ void smpi_prepare_global_memory_segment()
 static void smpi_get_executable_global_size()
 {
   char buffer[PATH_MAX];
-  char* full_name = realpath(xbt_binary_name, buffer);
-  xbt_assert(full_name != nullptr, "Could not resolve real path of binary file '%s'", xbt_binary_name);
+  char* full_name = realpath(simgrid::xbt::binary_name.c_str(), buffer);
+  xbt_assert(full_name != nullptr, "Could not resolve real path of binary file '%s'",
+             simgrid::xbt::binary_name.c_str());
 
   std::vector<simgrid::xbt::VmMap> map = simgrid::xbt::get_memory_map(getpid());
   for (auto i = map.begin(); i != map.end() ; ++i) {
index bfdf869..6e88536 100644 (file)
 #if HAVE_UNISTD_H
 # include <unistd.h>
 #endif
+#include <string>
+#include <vector>
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(module, xbt, "module handling");
 
 XBT_LOG_NEW_CATEGORY(smpi, "All SMPI categories"); /* lives here even if that's a bit odd to solve linking issues: this is used in xbt_log_file_appender to detect whether SMPI is used (and thus whether we should unbench the writing to disk) */
 
-char *xbt_binary_name = NULL;   /* Name of the system process containing us (mandatory to retrieve neat backtraces) */
-xbt_dynar_t xbt_cmdline = NULL; /* all we got in argv */
+namespace simgrid {
+namespace xbt {
+std::string binary_name;          /* Name of the system process containing us (mandatory to retrieve neat backtraces) */
+std::vector<std::string> cmdline; /* all we got in argv */
+} // namespace xbt
+} // namespace simgrid
 
 int xbt_initialized = 0;
 simgrid::config::Flag<bool> cfg_dbg_clean_atexit{
@@ -106,7 +112,6 @@ static void xbt_postexit()
     return;
   xbt_initialized--;
   xbt_dict_postexit();
-  xbt_dynar_free(&xbt_cmdline);
   xbt_log_postexit();
 #if SIMGRID_HAVE_MC
   mmalloc_postexit();
@@ -124,10 +129,9 @@ void xbt_init(int *argc, char **argv)
 
   simgrid::xbt::install_exception_handler();
 
-  xbt_binary_name = argv[0];
-  xbt_cmdline     = xbt_dynar_new(sizeof(char*), NULL);
+  simgrid::xbt::binary_name = argv[0];
   for (int i = 0; i < *argc; i++)
-    xbt_dynar_push(xbt_cmdline,&(argv[i]));
+    simgrid::xbt::cmdline.push_back(argv[i]);
 
   xbt_log_init(argc, argv);
 }