Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use boost::lexical_cast instead of xbt_str_parse_* in C++ files.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Tue, 3 Oct 2017 20:25:25 +0000 (22:25 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Mon, 27 Nov 2023 08:45:06 +0000 (09:45 +0100)
NOTE: needs to be completed (git grep xbt_str_parse \*.cpp)

src/mc/remote/AppSide.cpp
src/smpi/internals/smpi_replay.cpp

index aabac00..bfadbcb 100644 (file)
@@ -20,6 +20,7 @@
 #include "xbt/str.h"
 #include <simgrid/modelchecker.h>
 
+#include <boost/lexical_cast.hpp>
 #include <cerrno>
 #include <cinttypes>
 #include <cstdio> // setvbuf
@@ -56,7 +57,12 @@ AppSide* AppSide::get()
 
   // Fetch socket from MC_ENV_SOCKET_FD:
   const char* fd_env = std::getenv(MC_ENV_SOCKET_FD);
-  int fd             = xbt_str_parse_int(fd_env, "Not a number in variable '" MC_ENV_SOCKET_FD "'");
+  int fd;
+  try {
+    fd = boost::lexical_cast<int>(fd_env);
+  } catch (boost::bad_lexical_cast const&) {
+    xbt_die("Not a number in variable '%s': %s", MC_ENV_SOCKET_FD, fd_env);
+  }
   XBT_DEBUG("Model-checked application found socket FD %i", fd);
 
   instance_ = std::make_unique<simgrid::mc::AppSide>(fd);
index 701323f..51e0992 100644 (file)
@@ -15,6 +15,7 @@
 #include "xbt/replay.hpp"
 #include "xbt/str.h"
 
+#include <boost/lexical_cast.hpp>
 #include <cmath>
 #include <limits>
 #include <memory>
@@ -75,7 +76,11 @@ void log_timed_action(const simgrid::xbt::ReplayAction& action, double clock)
 /* Helper functions */
 static double parse_double(const std::string& string)
 {
-  return xbt_str_parse_double(string.c_str(), "not a double");
+  try {
+    return boost::lexical_cast<double>(string);
+  } catch (boost::bad_lexical_cast const&) {
+    throw std::invalid_argument("not a double: " + string);
+  }
 }
 
 template <typename T> static T parse_integer(const std::string& string)