Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Cleanup around simgrid::ParseError.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Wed, 20 Nov 2019 13:49:26 +0000 (14:49 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Wed, 20 Nov 2019 14:28:46 +0000 (15:28 +0100)
include/simgrid/Exception.hpp
src/surf/xml/platf.hpp
src/surf/xml/surfxml_sax_cb.cpp

index ad3498a..8127e89 100644 (file)
@@ -158,21 +158,13 @@ public:
   }
 };
 
-class XBT_PUBLIC ParseError : public Exception, public std::invalid_argument {
-  int line_;
-  std::string file_;
-  std::string msg_;
-  char* rendered_what = nullptr;
-
+/** Exception raised when something is going wrong during the parsing of XML files */
+class ParseError : public Exception {
 public:
-  ParseError(int line, std::string& file, std::string&& msg)
-      : Exception(XBT_THROW_POINT, std::move(msg)), std::invalid_argument(msg), line_(line), file_(file), msg_(msg)
+  ParseError(const std::string& file, int line, const std::string& msg)
+      : Exception(XBT_THROW_POINT, xbt::string_printf("Parse error at %s:%d: %s", file.c_str(), line, msg.c_str()))
   {
-    rendered_what = bprintf("Parse error at %s:%d: %s", file_.c_str(), line_, msg_.c_str());
   }
-  ~ParseError() { free(rendered_what); }
-
-  const char* what() const noexcept override { return rendered_what; }
 };
 
 class XBT_PUBLIC ForcefulKillException {
index d488e55..6c8b9d0 100644 (file)
@@ -16,11 +16,8 @@ XBT_PUBLIC void sg_platf_exit();
 
 XBT_PUBLIC void surf_parse_open(const std::string& file);
 XBT_PUBLIC void surf_parse_close();
-XBT_PUBLIC void surf_parse_assert(bool cond, std::string&& msg);
-SG_BEGIN_DECL
-XBT_ATTRIB_NORETURN XBT_PUBLIC void surf_parse_error(const char* msg);
-SG_END_DECL
-XBT_ATTRIB_NORETURN XBT_PUBLIC void surf_parse_error(std::string&& msg);
+XBT_PUBLIC void surf_parse_assert(bool cond, const std::string& msg);
+XBT_ATTRIB_NORETURN XBT_PUBLIC void surf_parse_error(const std::string& msg);
 XBT_PUBLIC void surf_parse_assert_netpoint(const std::string& hostname, const std::string& pre,
                                            const std::string& post);
 
index 0b49682..c73780d 100644 (file)
@@ -34,19 +34,15 @@ std::vector<simgrid::kernel::resource::DiskImpl*> parsed_disk_list; /* temporary
 /*
  * Helping functions
  */
-void surf_parse_assert(bool cond, std::string&& msg)
+void surf_parse_assert(bool cond, const std::string& msg)
 {
   if (not cond)
-    surf_parse_error(std::move(msg));
+    surf_parse_error(msg);
 }
 
-void surf_parse_error(const char* msg) {
-  throw simgrid::ParseError(surf_parse_lineno, surf_parsed_filename, std::string(msg));
-}
-
-void surf_parse_error(std::string&& msg)
+void surf_parse_error(const std::string& msg)
 {
-  throw simgrid::ParseError(surf_parse_lineno, surf_parsed_filename, std::move(msg));
+  throw simgrid::ParseError(surf_parsed_filename, surf_parse_lineno, msg);
 }
 
 void surf_parse_assert_netpoint(const std::string& hostname, const std::string& pre, const std::string& post)