From f99dc20a7a829278a448ddf412abe4be587807f5 Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Tue, 3 Oct 2017 22:25:25 +0200 Subject: [PATCH] Use boost::lexical_cast instead of xbt_str_parse_* in C++ files. NOTE: needs to be completed (git grep xbt_str_parse \*.cpp) --- src/mc/remote/AppSide.cpp | 8 +++++++- src/smpi/internals/smpi_replay.cpp | 7 ++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/mc/remote/AppSide.cpp b/src/mc/remote/AppSide.cpp index aabac0027a..bfadbcb132 100644 --- a/src/mc/remote/AppSide.cpp +++ b/src/mc/remote/AppSide.cpp @@ -20,6 +20,7 @@ #include "xbt/str.h" #include +#include #include #include #include // 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(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(fd); diff --git a/src/smpi/internals/smpi_replay.cpp b/src/smpi/internals/smpi_replay.cpp index 701323fb28..51e0992e62 100644 --- a/src/smpi/internals/smpi_replay.cpp +++ b/src/smpi/internals/smpi_replay.cpp @@ -15,6 +15,7 @@ #include "xbt/replay.hpp" #include "xbt/str.h" +#include #include #include #include @@ -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(string); + } catch (boost::bad_lexical_cast const&) { + throw std::invalid_argument("not a double: " + string); + } } template static T parse_integer(const std::string& string) -- 2.20.1