From 1ac51a57cbc9eeda2ae7100d7366d0788db83029 Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Tue, 17 Dec 2019 15:00:45 +0100 Subject: [PATCH] save a vector, kill a dynar! --- include/simgrid/jedule/jedule_platform.hpp | 1 - include/xbt/log.hpp | 5 +++-- include/xbt/virtu.h | 17 +++++++++++++---- src/bindings/java/JavaContext.cpp | 2 +- src/bindings/java/jmsg.cpp | 2 +- src/instr/instr_config.cpp | 6 ++---- src/instr/jedule/jedule_sd_binding.cpp | 12 +++++------- src/smpi/internals/smpi_memory.cpp | 5 +++-- src/xbt/xbt_main.cpp | 16 ++++++++++------ 9 files changed, 38 insertions(+), 28 deletions(-) diff --git a/include/simgrid/jedule/jedule_platform.hpp b/include/simgrid/jedule/jedule_platform.hpp index cf5b0e0a33..ed27a85c16 100644 --- a/include/simgrid/jedule/jedule_platform.hpp +++ b/include/simgrid/jedule/jedule_platform.hpp @@ -7,7 +7,6 @@ #define JED_SIMGRID_PLATFORM_H_ #include -#include #include #include diff --git a/include/xbt/log.hpp b/include/xbt/log.hpp index 3f74fb55b3..76221a71f9 100644 --- a/include/xbt/log.hpp +++ b/include/xbt/log.hpp @@ -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 diff --git a/include/xbt/virtu.h b/include/xbt/virtu.h index 98cd941681..05be643930 100644 --- a/include/xbt/virtu.h +++ b/include/xbt/virtu.h @@ -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 +#include +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 cmdline; -SG_END_DECL +} // namespace xbt +} // namespace simgrid +#endif #endif /* XBT_VIRTU_H */ diff --git a/src/bindings/java/JavaContext.cpp b/src/bindings/java/JavaContext.cpp index ad355eb868..1622e85672 100644 --- a/src/bindings/java/JavaContext.cpp +++ b/src/bindings/java/JavaContext.cpp @@ -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; diff --git a/src/bindings/java/jmsg.cpp b/src/bindings/java/jmsg.cpp index 66231b3972..ddbac3b289 100644 --- a/src/bindings/java/jmsg.cpp +++ b/src/bindings/java/jmsg.cpp @@ -104,7 +104,7 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_init(JNIEnv * env, jclass cls, j argc += static_cast(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 args; args.reserve(argc); diff --git a/src/instr/instr_config.cpp b/src/instr/instr_config.cpp index fcddfdeaef..a704abfe69 100644 --- a/src/instr/instr_config.cpp +++ b/src/instr/instr_config.cpp @@ -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 #include @@ -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; diff --git a/src/instr/jedule/jedule_sd_binding.cpp b/src/instr/jedule/jedule_sd_binding.cpp index 5819009b9c..918cfaa583 100644 --- a/src/instr/jedule/jedule_sd_binding.cpp +++ b/src/instr/jedule/jedule_sd_binding.cpp @@ -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 diff --git a/src/smpi/internals/smpi_memory.cpp b/src/smpi/internals/smpi_memory.cpp index a315b6c9cc..8a99ebcf26 100644 --- a/src/smpi/internals/smpi_memory.cpp +++ b/src/smpi/internals/smpi_memory.cpp @@ -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 map = simgrid::xbt::get_memory_map(getpid()); for (auto i = map.begin(); i != map.end() ; ++i) { diff --git a/src/xbt/xbt_main.cpp b/src/xbt/xbt_main.cpp index bfdf869665..6e885360be 100644 --- a/src/xbt/xbt_main.cpp +++ b/src/xbt/xbt_main.cpp @@ -28,13 +28,19 @@ #if HAVE_UNISTD_H # include #endif +#include +#include 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 cmdline; /* all we got in argv */ +} // namespace xbt +} // namespace simgrid int xbt_initialized = 0; simgrid::config::Flag 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); } -- 2.20.1