From: Arnaud Giersch Date: Thu, 15 Oct 2020 12:45:42 +0000 (+0200) Subject: Rewrite in a simpler manner. X-Git-Tag: v3.26~298 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/30b4f947d87ffdc4bccdb56fa4be9514780daf9b Rewrite in a simpler manner. --- diff --git a/include/xbt/functional.hpp b/include/xbt/functional.hpp index c09d278254..cc053a56a2 100644 --- a/include/xbt/functional.hpp +++ b/include/xbt/functional.hpp @@ -12,6 +12,7 @@ #include #include +#include #include #include #include @@ -38,15 +39,9 @@ public: { const int argc = args_->size(); std::vector args = *args_; - if (not args.empty()) { - char noarg[] = {'\0'}; - auto argv = std::make_unique(argc + 1); - for (int i = 0; i != argc; ++i) - argv[i] = args[i].empty() ? noarg : &args[i].front(); - argv[argc] = nullptr; - code_(argc, argv.get()); - } else - code_(argc, nullptr); + std::vector argv(args.size() + 1); // argv[argc] is nullptr + std::transform(begin(args), end(args), begin(argv), [](std::string& s) { return &s.front(); }); + code_(argc, argv.data()); } }; diff --git a/src/bindings/python/simgrid_python.cpp b/src/bindings/python/simgrid_python.cpp index 75d9f7560a..ce10be9067 100644 --- a/src/bindings/python/simgrid_python.cpp +++ b/src/bindings/python/simgrid_python.cpp @@ -31,6 +31,7 @@ #include #include +#include #include #include #include @@ -151,14 +152,11 @@ PYBIND11_MODULE(simgrid, m) /* Class Engine */ py::class_(m, "Engine", "Simulation Engine") .def(py::init([](std::vector args) { - static char noarg[] = {'\0'}; auto argc = static_cast(args.size()); - auto argv = std::make_unique(argc + 1); - for (int i = 0; i != argc; ++i) - argv[i] = args[i].empty() ? noarg : &args[i].front(); - argv[argc] = nullptr; + std::vector argv(args.size() + 1); // argv[argc] is nullptr + std::transform(begin(args), end(args), begin(argv), [](std::string& s) { return &s.front(); }); // Currently this can be dangling, we should wrap this somehow. - return new simgrid::s4u::Engine(&argc, argv.get()); + return new simgrid::s4u::Engine(&argc, argv.data()); })) .def_static("get_clock", &Engine::get_clock, "The simulation time, ie the amount of simulated seconds since the simulation start.")