#include "src/smpi/include/smpi_actor.hpp"
#include "xbt/config.hpp"
+#include <algorithm>
#include <cfloat> /* DBL_MAX */
#include <dlfcn.h>
#include <fcntl.h>
static int smpi_run_entry_point(smpi_entry_point_type entry_point, std::vector<std::string> args)
{
- int argc_saved = args.size();
- int argc=argc_saved;
- char** argv = new char*[argc + 1];
- for (int i = 0; i != argc; ++i)
- argv[i] = xbt_strdup(args[i].c_str());
- argv[argc] = nullptr;
- char* name = argv[0];
- char* instance = argv[1];
+ // copy C strings, we need them writable
+ std::vector<char*>* args4argv = new std::vector<char*>(args.size());
+ std::transform(begin(args), end(args), begin(*args4argv), [](const std::string& s) { return xbt_strdup(s.c_str()); });
+
+#if !SMPI_IFORT
+ // take a copy of args4argv to keep reference of the allocated strings
+ const std::vector<char*> args2str(*args4argv);
+#endif
+ int argc = args4argv->size();
+ args4argv->push_back(nullptr);
+ char** argv = args4argv->data();
+
simgrid::smpi::ActorExt::init(&argc, &argv);
#if SMPI_IFORT
for_rtl_init_ (&argc, argv);
#if SMPI_IFORT
for_rtl_finish_ ();
#else
- for (int i = 0; i != argc; ++i)
- xbt_free(argv[i]);
- if (argc_saved > 3) {
- xbt_free(instance);
- xbt_free(name);
- }
- delete[] argv;
+ for (char* s : args2str)
+ xbt_free(s);
+ delete args4argv;
#endif
if (res != 0){