From 0af9f2144555a92e4a2f4cd47a39210c4e64d322 Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Mon, 13 Feb 2023 16:09:47 +0100 Subject: [PATCH] Reduce scope for variables. --- src/instr/instr_config.cpp | 4 ++-- src/instr/instr_interface.cpp | 10 +++++----- src/instr/instr_private.hpp | 7 ------- src/smpi/include/private.hpp | 3 --- src/smpi/internals/smpi_global.cpp | 2 +- src/smpi/internals/smpi_memory.cpp | 6 +++--- src/smpi/internals/smpi_shared.cpp | 4 ++-- src/smpi/internals/smpi_utils.cpp | 11 ++++++----- src/surf/network_ns3.cpp | 3 +-- src/surf/xml/surfxml_parseplatf.cpp | 10 +++++----- src/surf/xml/surfxml_sax_cb.cpp | 8 ++++---- 11 files changed, 29 insertions(+), 39 deletions(-) diff --git a/src/instr/instr_config.cpp b/src/instr/instr_config.cpp index 19d9e9eb22..c13fdffc99 100644 --- a/src/instr/instr_config.cpp +++ b/src/instr/instr_config.cpp @@ -20,7 +20,7 @@ XBT_LOG_NEW_CATEGORY(instr, "Logging the behavior of the tracing system (used fo XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_config, instr, "Configuration"); std::ofstream tracing_file; -std::map tracing_files; // TI specific +static std::map tracing_files; // TI specific constexpr char OPT_TRACING_BASIC[] = "tracing/basic"; constexpr char OPT_TRACING_COMMENT_FILE[] = "tracing/comment-file"; @@ -206,7 +206,7 @@ void TRACE_help() namespace simgrid::instr { static bool trace_active = false; TraceFormat trace_format = TraceFormat::Paje; -int trace_precision; +static int trace_precision; /************* * Callbacks * diff --git a/src/instr/instr_interface.cpp b/src/instr/instr_interface.cpp index 4ff4120d65..106acd4c31 100644 --- a/src/instr/instr_interface.cpp +++ b/src/instr/instr_interface.cpp @@ -17,11 +17,11 @@ enum class InstrUserVariable { DECLARE, SET, ADD, SUB }; XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_api, instr, "API"); -std::set> created_categories; -std::set> declared_marks; -std::set> user_host_variables; -std::set> user_vm_variables; -std::set> user_link_variables; +static std::set> created_categories; +static std::set> declared_marks; +static std::set> user_host_variables; +static std::set> user_vm_variables; +static std::set> user_link_variables; static void instr_user_variable(double time, const std::string& resource, const std::string& variable_name, const std::string& parent_type, double value, InstrUserVariable what, diff --git a/src/instr/instr_private.hpp b/src/instr/instr_private.hpp index c6b35da74e..091bbccb9e 100644 --- a/src/instr/instr_private.hpp +++ b/src/instr/instr_private.hpp @@ -40,7 +40,6 @@ void dump_header(bool basic, bool display_sizes); */ enum class TraceFormat { Paje, /*TimeIndependent*/ Ti }; extern TraceFormat trace_format; -extern int trace_precision; extern double last_timestamp_to_dump; void init(); @@ -233,12 +232,6 @@ public: XBT_PRIVATE std::string instr_pid(simgrid::s4u::Actor const& proc); -extern XBT_PRIVATE std::set> created_categories; -extern XBT_PRIVATE std::set> declared_marks; -extern XBT_PRIVATE std::set> user_host_variables; -extern XBT_PRIVATE std::set> user_vm_variables; -extern XBT_PRIVATE std::set> user_link_variables; - /* from instr_config.c */ XBT_PRIVATE bool TRACE_needs_platform(); XBT_PRIVATE bool TRACE_is_enabled(); diff --git a/src/smpi/include/private.hpp b/src/smpi/include/private.hpp index 4440cc749f..2133849028 100644 --- a/src/smpi/include/private.hpp +++ b/src/smpi/include/private.hpp @@ -118,9 +118,6 @@ XBT_PRIVATE bool smpi_cfg_display_alloc(); // utilities XBT_PRIVATE void smpi_init_options_internal(bool called_by_smpi_main); -extern XBT_PRIVATE char* smpi_data_exe_start; // start of the data+bss segment of the executable -extern XBT_PRIVATE size_t smpi_data_exe_size; // size of the data+bss segment of the executable - XBT_PRIVATE bool smpi_switch_data_segment(simgrid::s4u::ActorPtr actor, const void* addr = nullptr); XBT_PRIVATE void smpi_prepare_global_memory_segment(); diff --git a/src/smpi/internals/smpi_global.cpp b/src/smpi/internals/smpi_global.cpp index 13e44ca460..fce781e94c 100644 --- a/src/smpi/internals/smpi_global.cpp +++ b/src/smpi/internals/smpi_global.cpp @@ -72,7 +72,7 @@ std::map std::unordered_map location2speedup; static int smpi_exit_status = 0; -xbt_os_timer_t global_timer; +static xbt_os_timer_t global_timer; static std::vector privatize_libs_paths; // No instance gets manually created; check also the smpirun.in script as diff --git a/src/smpi/internals/smpi_memory.cpp b/src/smpi/internals/smpi_memory.cpp index b9b81f6bed..d2d121e447 100644 --- a/src/smpi/internals/smpi_memory.cpp +++ b/src/smpi/internals/smpi_memory.cpp @@ -26,9 +26,9 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_memory, smpi, "Memory layout support for SMPI"); -char* smpi_data_exe_start = nullptr; -size_t smpi_data_exe_size = 0; -SmpiPrivStrategies smpi_privatize_global_variables; +static char* smpi_data_exe_start = nullptr; // start of the data+bss segment of the executable +static size_t smpi_data_exe_size = 0; // size of the data+bss segment of the executable +static SmpiPrivStrategies smpi_privatize_global_variables; static void* smpi_data_exe_copy; // Initialized by smpi_prepare_global_memory_segment(). diff --git a/src/smpi/internals/smpi_shared.cpp b/src/smpi/internals/smpi_shared.cpp index 95067dd211..10ab0ad0ae 100644 --- a/src/smpi/internals/smpi_shared.cpp +++ b/src/smpi/internals/smpi_shared.cpp @@ -58,7 +58,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_shared, smpi, "Logging specific to SMPI (shared memory macros)"); -namespace{ +namespace { /** Some location in the source code * * This information is used by SMPI_SHARED_MALLOC to allocate some shared memory for all simulated processes. @@ -94,7 +94,7 @@ std::map> calls; int smpi_shared_malloc_bogusfile = -1; int smpi_shared_malloc_bogusfile_huge_page = -1; unsigned long smpi_shared_malloc_blocksize = 1UL << 20; -} +} // namespace void smpi_shared_destroy() { diff --git a/src/smpi/internals/smpi_utils.cpp b/src/smpi/internals/smpi_utils.cpp index 94060e92e6..46249714c6 100644 --- a/src/smpi/internals/smpi_utils.cpp +++ b/src/smpi/internals/smpi_utils.cpp @@ -19,10 +19,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_utils, smpi, "Logging specific to SMPI (utils)"); -extern std::string surf_parsed_filename; -extern int surf_parse_lineno; - -namespace simgrid::smpi::utils { +namespace { double total_benched_time=0; unsigned long total_malloc_size=0; @@ -41,7 +38,7 @@ struct current_buffer_metadata_t { }; alloc_metadata_t max_malloc; -F2C* current_handle = nullptr; +simgrid::smpi::F2C* current_handle = nullptr; current_buffer_metadata_t current_buffer1; current_buffer_metadata_t current_buffer2; @@ -49,6 +46,10 @@ std::unordered_map allocs; std::unordered_map> collective_calls; +} // namespace + +namespace simgrid::smpi::utils { + void add_benched_time(double time){ total_benched_time += time; } diff --git a/src/surf/network_ns3.cpp b/src/surf/network_ns3.cpp index 5ab5965842..8f1d008a5c 100644 --- a/src/surf/network_ns3.cpp +++ b/src/surf/network_ns3.cpp @@ -51,8 +51,6 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(res_ns3, res_network, "Network model based on ns extern std::map> flow_from_sock; extern std::map> sink_from_sock; -static ns3::InternetStackHelper stack; - static int number_of_links = 1; static int number_of_networks = 1; @@ -67,6 +65,7 @@ static std::string transformIpv4Address(ns3::Ipv4Address from) NetPointNs3::NetPointNs3() { + static ns3::InternetStackHelper stack; stack.Install(ns3_node_); } diff --git a/src/surf/xml/surfxml_parseplatf.cpp b/src/surf/xml/surfxml_parseplatf.cpp index 5cfc7f2ffa..5477468ca2 100644 --- a/src/surf/xml/surfxml_parseplatf.cpp +++ b/src/surf/xml/surfxml_parseplatf.cpp @@ -17,11 +17,11 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_parse); /* Trace related stuff */ XBT_PRIVATE std::unordered_map traces_set_list; -XBT_PRIVATE std::unordered_map trace_connect_list_host_avail; -XBT_PRIVATE std::unordered_map trace_connect_list_host_speed; -XBT_PRIVATE std::unordered_map trace_connect_list_link_avail; -XBT_PRIVATE std::unordered_map trace_connect_list_link_bw; -XBT_PRIVATE std::unordered_map trace_connect_list_link_lat; +static std::unordered_map trace_connect_list_host_avail; +static std::unordered_map trace_connect_list_host_speed; +static std::unordered_map trace_connect_list_link_avail; +static std::unordered_map trace_connect_list_link_bw; +static std::unordered_map trace_connect_list_link_lat; void sg_platf_trace_connect(simgrid::kernel::routing::TraceConnectCreationArgs* trace_connect) { diff --git a/src/surf/xml/surfxml_sax_cb.cpp b/src/surf/xml/surfxml_sax_cb.cpp index 567a2b2377..af1ae599b9 100644 --- a/src/surf/xml/surfxml_sax_cb.cpp +++ b/src/surf/xml/surfxml_sax_cb.cpp @@ -29,7 +29,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_parse, surf, "Logging specific to the SURF parsing module"); std::string surf_parsed_filename; // Currently parsed file (for the error messages) -std::vector parsed_link_list; /* temporary store of current link list of a route */ +static std::vector parsed_link_list; /* temporary store of current link list of a route */ /* Helping functions */ void surf_parse_assert(bool cond, const std::string& msg) @@ -127,9 +127,9 @@ static void explodesRadical(const std::string& radicals, std::vector* explo /* make sure these symbols are defined as strong ones in this file so that the linker can resolve them */ -std::vector> property_sets; +static std::vector> property_sets; -FILE *surf_file_to_parse = nullptr; +static FILE* surf_file_to_parse = nullptr; /* Stuff relative to storage */ void STag_surfxml_storage() @@ -826,7 +826,7 @@ void ETag_surfxml_argument(){/* Nothing to do */} void ETag_surfxml_model___prop(){/* Nothing to do */} /* Open and Close parse file */ -YY_BUFFER_STATE surf_input_buffer; +static YY_BUFFER_STATE surf_input_buffer; void surf_parse_open(const std::string& file) { -- 2.20.1