#include "simgrid_dtd.c"
-char* surf_parsed_filename = nullptr; // to locate parse error messages
+/*
+ * Stuff relative to the <include> tag
+ */
+static std::vector<YY_BUFFER_STATE> surf_input_buffer_stack;
+static std::vector<FILE*> surf_file_to_parse_stack;
+static std::vector<std::string> surf_parsed_filename_stack;
+
+static inline const char* surf_parsed_filename() // to locate parse error messages
+{
+ return surf_parsed_filename_stack.empty() ? nullptr : surf_parsed_filename_stack.back().c_str();
+}
std::vector<simgrid::surf::LinkImpl*> parsed_link_list; /* temporary store of current list link of a route */
if (not cond) {
int lineno = surf_parse_lineno;
cleanup();
- XBT_ERROR("Parse error at %s:%d: %s", surf_parsed_filename, lineno, msg.c_str());
+ XBT_ERROR("Parse error at %s:%d: %s", surf_parsed_filename(), lineno, msg.c_str());
surf_exit();
xbt_die("Exiting now");
}
{
int lineno = surf_parse_lineno;
cleanup();
- XBT_ERROR("Parse error at %s:%d: %s", surf_parsed_filename, lineno, msg.c_str());
+ XBT_ERROR("Parse error at %s:%d: %s", surf_parsed_filename(), lineno, msg.c_str());
surf_exit();
xbt_die("Exiting now");
}
void surf_parse_warn(std::string msg)
{
- XBT_WARN("%s:%d: %s", surf_parsed_filename, surf_parse_lineno, msg.c_str());
+ XBT_WARN("%s:%d: %s", surf_parsed_filename(), surf_parse_lineno, msg.c_str());
}
double surf_parse_get_double(std::string s)
sg_platf_new_mount(&mount);
}
-/*
- * Stuff relative to the <include> tag
- */
-static std::vector<YY_BUFFER_STATE> surf_input_buffer_stack;
-static std::vector<FILE*> surf_file_to_parse_stack;
-static std::vector<char*> surf_parsed_filename_stack;
-
void STag_surfxml_include()
{
XBT_ERROR("<include> tag is deprecated, and will be removed in SimGrid v3.18. Please stop using it now (or tell us why you need it).");
parse_after_config();
XBT_DEBUG("STag_surfxml_include '%s'",A_surfxml_include_file);
- surf_parsed_filename_stack.push_back(surf_parsed_filename); // save old file name
- surf_parsed_filename = xbt_strdup(A_surfxml_include_file);
+ surf_parsed_filename_stack.emplace_back(A_surfxml_include_file); // save file name
surf_file_to_parse_stack.push_back(surf_file_to_parse); // save old file descriptor
surf_input_buffer_stack.pop_back();
// Restore the filename for error messages
- free(surf_parsed_filename);
surf_parsed_filename_stack.pop_back();
return 1;
"Use simgrid_update_xml to update your file automatically. "
"This program is installed automatically with SimGrid, or "
"available in the tools/ directory of the source archive.",
- surf_parsed_filename, version);
+ surf_parsed_filename(), version);
if (version < 4.1) {
XBT_INFO("You're using a v%.1f XML file (%s) while the current standard is v4.1 "
"That's fine, the new version is backward compatible. \n\n"
"Use simgrid_update_xml to update your file automatically. "
"This program is installed automatically with SimGrid, or "
"available in the tools/ directory of the source archive.",
- version, surf_parsed_filename);
+ version, surf_parsed_filename());
}
xbt_assert(version <= 4.1, "******* FILE %s COMES FROM THE FUTURE (v:%.1f) *********\n "
"The most recent formalism that this version of SimGrid understands is v4.1.\n"
"Please update your code, or use another, more adapted, file.",
- surf_parsed_filename, version);
+ surf_parsed_filename(), version);
sg_platf_begin();
}
{
xbt_assert(file, "Cannot parse the nullptr file. Bypassing the parser is strongly deprecated nowadays.");
- surf_parsed_filename = xbt_strdup(file);
+ surf_parsed_filename_stack.emplace_back(file);
std::string dir = simgrid::xbt::Path(file).getDirname();
surf_path.push_back(dir);
void surf_parse_close()
{
- if (surf_parsed_filename) {
+ if (surf_parsed_filename()) {
surf_path.pop_back();
}
- free(surf_parsed_filename);
- surf_parsed_filename = nullptr;
+ surf_parsed_filename_stack.pop_back();
if (surf_file_to_parse) {
surf_parse__delete_buffer(surf_input_buffer);