From c6374915fc9c74a89f67428ba910e204d2daa516 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Wed, 11 Jul 2018 11:13:57 +0200 Subject: [PATCH] stringify s4u::Engine --- include/simgrid/s4u/Engine.hpp | 26 +++++++++++++------------- include/simgrid/s4u/NetZone.hpp | 4 ++-- include/simgrid/simix.h | 6 +++--- include/simgrid/simix.hpp | 3 +-- src/include/surf/surf.hpp | 2 +- src/s4u/s4u_Engine.cpp | 14 ++++++++------ src/s4u/s4u_Netzone.cpp | 4 ++-- src/simix/smx_deployment.cpp | 13 +++++++------ src/simix/smx_environment.cpp | 4 ++-- src/surf/surf_interface.cpp | 12 +++++------- src/surf/surf_private.hpp | 2 +- src/surf/xml/platf.hpp | 2 +- src/surf/xml/surfxml_parseplatf.cpp | 9 +++++---- src/surf/xml/surfxml_sax_cb.cpp | 27 +++++++++++++-------------- 14 files changed, 64 insertions(+), 64 deletions(-) diff --git a/include/simgrid/s4u/Engine.hpp b/include/simgrid/s4u/Engine.hpp index d30bc2ffed..dc400f0710 100644 --- a/include/simgrid/s4u/Engine.hpp +++ b/include/simgrid/s4u/Engine.hpp @@ -49,11 +49,10 @@ public: * The environment is either a XML file following the simgrid.dtd formalism, or a lua file. * Some examples can be found in the directory examples/platforms. */ - void load_platform(const char* platf); + void load_platform(std::string platf); /** Registers the main function of an actor that will be launched from the deployment file */ - void register_function(const char* name, int (*code)(int, char**)); - // FIXME: provide a register_function(std::string, void (*code)(int, char**)) and deprecate the int returning one + void register_function(std::string name, int (*code)(int, char**)); // FIXME: provide a register_function(std::string, std::vector) /** Registers a function as the default main function of actors @@ -63,7 +62,7 @@ public: */ void register_default(int (*code)(int, char**)); - template void register_actor(const char* name) + template void register_actor(std::string name) { simgrid::simix::register_function(name, [](std::vector args) { return simgrid::simix::ActorCode([args] { @@ -73,7 +72,7 @@ public: }); } - template void register_actor(const char* name, F code) + template void register_actor(std::string name, F code) { simgrid::simix::register_function(name, [code](std::vector args) { return simgrid::simix::ActorCode([code, args] { code(std::move(args)); }); @@ -81,7 +80,7 @@ public: } /** @brief Load a deployment file and launch the actors that it contains */ - void load_deployment(const char* deploy); + void load_deployment(std::string deploy); protected: friend s4u::Host; @@ -127,7 +126,7 @@ public: simgrid::s4u::NetZone* get_netzone_root(); void set_netzone_root(s4u::NetZone* netzone); - simgrid::s4u::NetZone* netzone_by_name_or_null(const char* name); + simgrid::s4u::NetZone* netzone_by_name_or_null(std::string name); /** @brief Retrieves all netzones of the type indicated by the template argument */ template std::vector get_filtered_netzones() @@ -157,11 +156,11 @@ private: //////////////// Deprecated functions public: - XBT_ATTRIB_DEPRECATED_v323("Please use Engine::load_platform()") void loadPlatform(const char* platf) + XBT_ATTRIB_DEPRECATED_v323("Please use Engine::load_platform()") void loadPlatform(std::string platf) { load_platform(platf); } - XBT_ATTRIB_DEPRECATED_v323("Please use Engine::register_function()") void registerFunction(const char* name, + XBT_ATTRIB_DEPRECATED_v323("Please use Engine::register_function()") void registerFunction(std::string name, int (*code)(int, char**)) { register_function(name, code); @@ -171,17 +170,17 @@ public: register_default(code); } template - XBT_ATTRIB_DEPRECATED_v323("Please use Engine::register_actor()") void registerFunction(const char* name) + XBT_ATTRIB_DEPRECATED_v323("Please use Engine::register_actor()") void registerFunction(std::string name) { register_actor(name); } template - XBT_ATTRIB_DEPRECATED_v323("Please use Engine::register_actor()") void registerFunction(const char* name, F code) + XBT_ATTRIB_DEPRECATED_v323("Please use Engine::register_actor()") void registerFunction(std::string name, F code) { register_actor(name, code); } - XBT_ATTRIB_DEPRECATED_v323("Please use Engine::load_deployment()") void loadDeployment(const char* deploy) + XBT_ATTRIB_DEPRECATED_v323("Please use Engine::load_deployment()") void loadDeployment(std::string deploy) { load_deployment(deploy); } @@ -232,7 +231,8 @@ public: { return get_netzone_root(); } - XBT_ATTRIB_DEPRECATED_v323("Please use Engine::netzone_by_name_or_null()") simgrid::s4u::NetZone* getNetzoneByNameOrNull(const char* name) + XBT_ATTRIB_DEPRECATED_v323( + "Please use Engine::netzone_by_name_or_null()") simgrid::s4u::NetZone* getNetzoneByNameOrNull(std::string name) { return netzone_by_name_or_null(name); } diff --git a/include/simgrid/s4u/NetZone.hpp b/include/simgrid/s4u/NetZone.hpp index e4d56e0f77..1771886264 100644 --- a/include/simgrid/s4u/NetZone.hpp +++ b/include/simgrid/s4u/NetZone.hpp @@ -54,8 +54,8 @@ public: std::vector get_children(); /** Retrieve the property value (or nullptr if not set) */ - const char* get_property(const char* key); - void set_property(const char* key, const char* value); + const char* get_property(std::string key); + void set_property(std::string key, std::string value); /* Add content to the netzone, at parsing time. It should be sealed afterward. */ int add_component(kernel::routing::NetPoint* elm); /* A host, a router or a netzone, whatever */ diff --git a/include/simgrid/simix.h b/include/simgrid/simix.h index 1c20d8e0c2..ac0f0264a2 100644 --- a/include/simgrid/simix.h +++ b/include/simgrid/simix.h @@ -111,14 +111,14 @@ XBT_PUBLIC double SIMIX_timer_get_date(smx_timer_t timer); XBT_PUBLIC void SIMIX_display_process_status(); /******************************* Environment **********************************/ -XBT_PUBLIC void SIMIX_create_environment(const char* file); +XBT_PUBLIC void SIMIX_create_environment(std::string file); /******************************** Deployment **********************************/ -XBT_PUBLIC void SIMIX_function_register(const char* name, xbt_main_func_t code); +XBT_PUBLIC void SIMIX_function_register(std::string name, xbt_main_func_t code); XBT_PUBLIC void SIMIX_function_register_default(xbt_main_func_t code); XBT_PUBLIC void SIMIX_init_application(); -XBT_PUBLIC void SIMIX_launch_application(const char* file); +XBT_PUBLIC void SIMIX_launch_application(std::string file); XBT_PUBLIC void SIMIX_process_set_function(const char* process_host, const char* process_function, xbt_dynar_t arguments, double process_start_time, double process_kill_time); diff --git a/include/simgrid/simix.hpp b/include/simgrid/simix.hpp index a88cf53f9c..0af396308b 100644 --- a/include/simgrid/simix.hpp +++ b/include/simgrid/simix.hpp @@ -73,8 +73,7 @@ typedef std::function ActorCode; // Create ActorCode based on argv: typedef std::function args)> ActorCodeFactory; -XBT_PUBLIC void register_function(const char* name, ActorCodeFactory factory); - +XBT_PUBLIC void register_function(std::string name, ActorCodeFactory factory); } } diff --git a/src/include/surf/surf.hpp b/src/include/surf/surf.hpp index 0d9f99a5e7..6c7e702508 100644 --- a/src/include/surf/surf.hpp +++ b/src/include/surf/surf.hpp @@ -79,6 +79,6 @@ XBT_PUBLIC double surf_get_clock(); XBT_PUBLIC void surf_exit(); /* surf parse file related (public because called from a test suite) */ -XBT_PUBLIC void parse_platform_file(const char* file); +XBT_PUBLIC void parse_platform_file(std::string file); #endif diff --git a/src/s4u/s4u_Engine.cpp b/src/s4u/s4u_Engine.cpp index e4372120df..58a77c86e5 100644 --- a/src/s4u/s4u_Engine.cpp +++ b/src/s4u/s4u_Engine.cpp @@ -20,6 +20,8 @@ #include "src/surf/network_interface.hpp" #include "surf/surf.hpp" // routing_platf. FIXME:KILLME. SOON +#include + XBT_LOG_NEW_CATEGORY(s4u, "Log channels of the S4U (Simgrid for you) interface"); namespace simgrid { @@ -69,12 +71,12 @@ double Engine::get_clock() return SIMIX_get_clock(); } -void Engine::load_platform(const char* platf) +void Engine::load_platform(std::string platf) { SIMIX_create_environment(platf); } -void Engine::register_function(const char* name, int (*code)(int, char**)) +void Engine::register_function(std::string name, int (*code)(int, char**)) { SIMIX_function_register(name, code); } @@ -82,7 +84,7 @@ void Engine::register_default(int (*code)(int, char**)) { SIMIX_function_register_default(code); } -void Engine::load_deployment(const char* deploy) +void Engine::load_deployment(std::string deploy) { SIMIX_launch_application(deploy); } @@ -272,9 +274,9 @@ void Engine::set_netzone_root(s4u::NetZone* netzone) pimpl->netzone_root_ = netzone->get_impl(); } -static s4u::NetZone* netzone_by_name_recursive(s4u::NetZone* current, const char* name) +static s4u::NetZone* netzone_by_name_recursive(s4u::NetZone* current, std::string name) { - if (not strcmp(current->get_cname(), name)) + if (current->get_name() == name) return current; for (auto const& elem : current->get_children()) { @@ -287,7 +289,7 @@ static s4u::NetZone* netzone_by_name_recursive(s4u::NetZone* current, const char } /** @brief Retrieve the NetZone of the given name (or nullptr if not found) */ -NetZone* Engine::netzone_by_name_or_null(const char* name) +NetZone* Engine::netzone_by_name_or_null(std::string name) { return netzone_by_name_recursive(get_netzone_root(), name); } diff --git a/src/s4u/s4u_Netzone.cpp b/src/s4u/s4u_Netzone.cpp index c9dc1bd922..cc6071c322 100644 --- a/src/s4u/s4u_Netzone.cpp +++ b/src/s4u/s4u_Netzone.cpp @@ -33,11 +33,11 @@ std::unordered_map* NetZone::get_properties() } /** Retrieve the property value (or nullptr if not set) */ -const char* NetZone::get_property(const char* key) +const char* NetZone::get_property(std::string key) { return properties_.at(key).c_str(); } -void NetZone::set_property(const char* key, const char* value) +void NetZone::set_property(std::string key, std::string value) { simgrid::simix::simcall([this, key, value] { properties_[key] = value; }); } diff --git a/src/simix/smx_deployment.cpp b/src/simix/smx_deployment.cpp index 1033c13026..e18a28183b 100644 --- a/src/simix/smx_deployment.cpp +++ b/src/simix/smx_deployment.cpp @@ -35,7 +35,7 @@ void SIMIX_init_application() * \include small_deployment.xml * */ -void SIMIX_launch_application(const char *file) +void SIMIX_launch_application(std::string file) { XBT_ATTRIB_UNUSED int parse_status; xbt_assert(simix_global, "SIMIX_global_init has to be called before SIMIX_launch_application."); @@ -46,11 +46,12 @@ void SIMIX_launch_application(const char *file) try { parse_status = surf_parse(); surf_parse_close(); - xbt_assert(not parse_status, "Parse error at %s:%d", file, surf_parse_lineno); + xbt_assert(not parse_status, "Parse error at %s:%d", file.c_str(), surf_parse_lineno); } catch (xbt_ex& e) { - XBT_ERROR("Unrecoverable error at %s:%d. The full exception stack follows, in case it helps you to diagnose the problem.", - file, surf_parse_lineno); + XBT_ERROR( + "Unrecoverable error at %s:%d. The full exception stack follows, in case it helps you to diagnose the problem.", + file.c_str(), surf_parse_lineno); throw; } } @@ -69,7 +70,7 @@ static simgrid::simix::ActorCodeFactory toActorCodeFactory(xbt_main_func_t code) * \param name the reference name of the function. * \param code the function */ -void SIMIX_function_register(const char *name, xbt_main_func_t code) +void SIMIX_function_register(std::string name, xbt_main_func_t code) { xbt_assert(simix_global, "SIMIX_global_init has to be called before SIMIX_function_register."); @@ -144,7 +145,7 @@ void SIMIX_process_set_function(const char* process_host, const char* process_fu namespace simgrid { namespace simix { -void register_function(const char* name, ActorCodeFactory factory) +void register_function(std::string name, ActorCodeFactory factory) { simix_global->registered_functions[name] = std::move(factory); } diff --git a/src/simix/smx_environment.cpp b/src/simix/smx_environment.cpp index ad6fe51ad9..5010842773 100644 --- a/src/simix/smx_environment.cpp +++ b/src/simix/smx_environment.cpp @@ -27,7 +27,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_environment, simix, "Logging specific to S * \include small_platform.xml * */ -void SIMIX_create_environment(const char *file) +void SIMIX_create_environment(std::string file) { double start = 0; double end = 0; @@ -37,7 +37,7 @@ void SIMIX_create_environment(const char *file) parse_platform_file(file); } catch (xbt_ex& e) { - xbt_die("Error while loading %s: %s", file, e.what()); + xbt_die("Error while loading %s: %s", file.c_str(), e.what()); } if(XBT_LOG_ISENABLED(simix_environment, xbt_log_priority_debug)) end = xbt_os_time(); diff --git a/src/surf/surf_interface.cpp b/src/surf/surf_interface.cpp index 61081b2719..40a5736ea0 100644 --- a/src/surf/surf_interface.cpp +++ b/src/surf/surf_interface.cpp @@ -127,11 +127,11 @@ double surf_get_clock() } /* returns whether #file_path is a absolute file path. Surprising, isn't it ? */ -static bool is_absolute_file_path(const char* file_path) +static bool is_absolute_file_path(std::string file_path) { #ifdef _WIN32 WIN32_FIND_DATA wfd = {0}; - HANDLE hFile = FindFirstFile(file_path, &wfd); + HANDLE hFile = FindFirstFile(file_path.c_str(), &wfd); if (INVALID_HANDLE_VALUE == hFile) return false; @@ -139,7 +139,7 @@ static bool is_absolute_file_path(const char* file_path) FindClose(hFile); return true; #else - return (file_path[0] == '/'); + return (file_path.c_str()[0] == '/'); #endif } @@ -166,14 +166,12 @@ std::ifstream* surf_ifsopen(std::string name) return fs; } -FILE *surf_fopen(const char *name, const char *mode) +FILE* surf_fopen(std::string name, const char* mode) { FILE *file = nullptr; - xbt_assert(name); - if (is_absolute_file_path(name)) /* don't mess with absolute file names */ - return fopen(name, mode); + return fopen(name.c_str(), mode); /* search relative files in the path */ for (auto const& path_elm : surf_path) { diff --git a/src/surf/surf_private.hpp b/src/surf/surf_private.hpp index 06530ad93d..4540c404e7 100644 --- a/src/surf/surf_private.hpp +++ b/src/surf/surf_private.hpp @@ -11,7 +11,7 @@ /* Generic functions common to all models */ -XBT_PRIVATE FILE* surf_fopen(const char* name, const char* mode); +XBT_PRIVATE FILE* surf_fopen(std::string name, const char* mode); XBT_PRIVATE std::ifstream* surf_ifsopen(std::string name); XBT_PRIVATE void check_disk_attachment(); diff --git a/src/surf/xml/platf.hpp b/src/surf/xml/platf.hpp index 1e095b6721..53068351e9 100644 --- a/src/surf/xml/platf.hpp +++ b/src/surf/xml/platf.hpp @@ -12,7 +12,7 @@ XBT_PUBLIC void sg_platf_init(); XBT_PUBLIC void sg_platf_exit(); -XBT_PUBLIC void surf_parse_open(const char* file); +XBT_PUBLIC void surf_parse_open(std::string file); XBT_PUBLIC void surf_parse_close(); XBT_PUBLIC void surf_parse_assert(bool cond, std::string msg); XBT_ATTRIB_NORETURN XBT_PUBLIC void surf_parse_error(std::string msg); diff --git a/src/surf/xml/surfxml_parseplatf.cpp b/src/surf/xml/surfxml_parseplatf.cpp index e3cb42bd64..479475007d 100644 --- a/src/surf/xml/surfxml_parseplatf.cpp +++ b/src/surf/xml/surfxml_parseplatf.cpp @@ -60,11 +60,12 @@ void sg_platf_trace_connect(simgrid::kernel::routing::TraceConnectCreationArgs* } /* This function acts as a main in the parsing area. */ -void parse_platform_file(const char *file) +void parse_platform_file(std::string file) { #if SIMGRID_HAVE_LUA - int len = (file == nullptr ? 0 : strlen(file)); - int is_lua = (file != nullptr && len > 3 && file[len - 3] == 'l' && file[len - 2] == 'u' && file[len - 1] == 'a'); + const char* cfile = file.c_str(); + int len = strlen(cfile); + int is_lua = len > 3 && file[len - 3] == 'l' && file[len - 2] == 'u' && file[len - 1] == 'a'; #endif sg_platf_init(); @@ -78,7 +79,7 @@ void parse_platform_file(const char *file) lua_State* L = luaL_newstate(); luaL_openlibs(L); - luaL_loadfile(L, file); // This loads the file without executing it. + luaL_loadfile(L, cfile); // This loads the file without executing it. /* Run the script */ if (lua_pcall(L, 0, 0, 0)) { diff --git a/src/surf/xml/surfxml_sax_cb.cpp b/src/surf/xml/surfxml_sax_cb.cpp index ebc12b7e40..715d57de7d 100644 --- a/src/surf/xml/surfxml_sax_cb.cpp +++ b/src/surf/xml/surfxml_sax_cb.cpp @@ -24,7 +24,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_parse, surf, "Logging specific to the SURF #include "simgrid_dtd.c" -static const char* surf_parsed_filename; // Currently parsed file (for the error messages) +static std::string surf_parsed_filename; // Currently parsed file (for the error messages) std::vector parsed_link_list; /* temporary store of current list link of a route */ @@ -36,7 +36,7 @@ void surf_parse_assert(bool cond, std::string msg) 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.c_str(), lineno, msg.c_str()); surf_exit(); xbt_die("Exiting now"); } @@ -46,7 +46,7 @@ void surf_parse_error(std::string msg) { 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.c_str(), lineno, msg.c_str()); surf_exit(); xbt_die("Exiting now"); } @@ -377,19 +377,20 @@ void STag_surfxml_platform() { "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.c_str(), 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 to get rid of this warning. " "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.c_str()); } - 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); + 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.c_str(), version); } void ETag_surfxml_platform(){ simgrid::s4u::on_platform_created(); @@ -406,7 +407,7 @@ void STag_surfxml_prop() XBT_DEBUG("Set zone property %s -> %s", A_surfxml_prop_id, A_surfxml_prop_value); simgrid::s4u::NetZone* netzone = simgrid::s4u::Engine::get_instance()->netzone_by_name_or_null(A_surfxml_zone_id); - netzone->set_property(A_surfxml_prop_id, A_surfxml_prop_value); + netzone->set_property(std::string(A_surfxml_prop_id), A_surfxml_prop_value); } else { if (not current_property_set) current_property_set = new std::unordered_map; // Maybe, it should raise an error @@ -962,17 +963,15 @@ void ETag_surfxml_model___prop(){/* Nothing to do */} /* Open and Close parse file */ YY_BUFFER_STATE surf_input_buffer; -void surf_parse_open(const char *file) +void surf_parse_open(std::string file) { - xbt_assert(file, "Cannot parse the nullptr file. Bypassing the parser is strongly deprecated nowadays."); - surf_parsed_filename = file; std::string dir = simgrid::xbt::Path(file).get_dir_name(); surf_path.push_back(dir); surf_file_to_parse = surf_fopen(file, "r"); if (surf_file_to_parse == nullptr) - xbt_die("Unable to open '%s'\n", file); + xbt_die("Unable to open '%s'\n", file.c_str()); surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE); surf_parse__switch_to_buffer(surf_input_buffer); surf_parse_lineno = 1; -- 2.20.1