From 322edd8b835377309e887b8333d01869aa734f3c Mon Sep 17 00:00:00 2001 From: Eric Berquist Date: Tue, 22 Aug 2023 11:47:17 -0600 Subject: [PATCH 1/6] use std::filesystem::rename --- src/sst/core/sstregistertool.cc | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/sst/core/sstregistertool.cc b/src/sst/core/sstregistertool.cc index d926fdf3d..45578f97d 100644 --- a/src/sst/core/sstregistertool.cc +++ b/src/sst/core/sstregistertool.cc @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -141,6 +142,8 @@ sstRegister(char* argv[]) fclose(cfgFile); } +namespace fs = std::filesystem; + // sstUnregister // Takes a string argument and searches the sstsimulator config file for that name. // Removes the component from the file - unregistering it from SST @@ -174,11 +177,17 @@ sstUnregister(const std::string& element) if ( found ) { std::cout << "\tModel " << element << " has been unregistered!\n"; } else - std::cout << "Model " << element << " not found\n\n"; + std::cout << "\tModel " << element << " not found\n\n"; infile.close(); outfile.close(); - rename(tempfile.c_str(), cfgPath); + try { + fs::rename(tempfile.c_str(), cfgPath); + // } catch (fs::filesystem_error const &ex) { + } catch (...) { + std::cerr << "\tError moving " << tempfile.c_str() << " to " << cfgPath << "\n"; + // std::cerr << ex.what() << std::endl; + } } // listModels From 5ad0f5456d46ffb9cba57005b56ec6e8729e61d5 Mon Sep 17 00:00:00 2001 From: Eric Berquist Date: Thu, 31 Aug 2023 09:22:36 -0600 Subject: [PATCH 2/6] remove unused autoconf scripts for past C++ standards --- config/ax_cxx_compile_stdcxx_04.m4 | 117 ----------------------------- config/ax_cxx_compile_stdcxx_14.m4 | 95 ----------------------- 2 files changed, 212 deletions(-) delete mode 100644 config/ax_cxx_compile_stdcxx_04.m4 delete mode 100644 config/ax_cxx_compile_stdcxx_14.m4 diff --git a/config/ax_cxx_compile_stdcxx_04.m4 b/config/ax_cxx_compile_stdcxx_04.m4 deleted file mode 100644 index 37a205d04..000000000 --- a/config/ax_cxx_compile_stdcxx_04.m4 +++ /dev/null @@ -1,117 +0,0 @@ -# ============================================================================ -# http://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx_0x.html -# ============================================================================ -# -# SYNOPSIS -# -# AX_CXX_COMPILE_STDCXX_0X -# -# DESCRIPTION -# -# Check for baseline language coverage in the compiler for the C++0x -# standard. -# -# LICENSE -# -# Copyright (c) 2008 Benjamin Kosnik -# -# Copying and distribution of this file, with or without modification, are -# permitted in any medium without royalty provided the copyright notice -# and this notice are preserved. This file is offered as-is, without any -# warranty. - -#serial 7 - -AU_ALIAS([AC_CXX_COMPILE_STDCXX_0X], [AX_CXX_COMPILE_STDCXX_0X]) - -AC_DEFUN([AX_CXX_COMPILE_STDCXX_0X], [ - SST_CXX0X_FLAGS="" - - AC_CACHE_CHECK(if C++ supports C++0x features without additional flags, - ax_cv_cxx_compile_cxx0x_native, - [AC_LANG_PUSH([C++]) - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ - template - struct check - { - static_assert(sizeof(int) <= sizeof(T), "not big enough"); - }; - - typedef check> right_angle_brackets; - - int a; - decltype(a) b; - - typedef check check_type; - check_type c; - check_type&& cr = static_cast(c);]], [])], - [ax_cv_cxx_compile_cxx0x_native=yes], [ax_cv_cxx_compile_cxx0x_native=no]) - AC_LANG_POP([C++]) - ]) - - SST_CXX0X_FLAGS="" - - AC_CACHE_CHECK(if C++ supports C++0x features with -std=c++11, - ax_cv_cxx_compile_cxx11_cxx, - [AC_LANG_PUSH([C++]) - ac_save_CXXFLAGS="$CXXFLAGS" - CXXFLAGS="$CXXFLAGS -std=c++11 -D__STDC_FORMAT_MACROS" - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ - template - struct check - { - static_assert(sizeof(int) <= sizeof(T), "not big enough"); - }; - - typedef check> right_angle_brackets; - - int a; - decltype(a) b; - - typedef check check_type; - check_type c; - check_type&& cr = static_cast(c);]], [])], - [ax_cv_cxx_compile_cxx11_cxx=yes], [ax_cv_cxx_compile_cxx11_cxx=no]) - CXXFLAGS=$ac_save_CXXFLAGS - AS_IF([test "$ax_cv_cxx_compile_cxx11_cxx" = "yes" ], [SST_CXX0X_FLAGS="-std=c++11 -D__STDC_FORMAT_MACROS"]) - - AC_LANG_POP([C++]) - ]) - - AS_IF([test "$ax_cv_cxx_compile_cxx11_cxx" != "yes"], [ - - AC_CACHE_CHECK(if C++ supports C++0x features with -std=c++0x, - ax_cv_cxx_compile_cxx0x_cxx, - [AC_LANG_PUSH([C++]) - ac_save_CXXFLAGS="$CXXFLAGS" - CXXFLAGS="$CXXFLAGS -std=c++0x -D__STDC_FORMAT_MACROS" - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ - template - struct check - { - static_assert(sizeof(int) <= sizeof(T), "not big enough"); - }; - - typedef check> right_angle_brackets; - - int a; - decltype(a) b; - - typedef check check_type; - check_type c; - check_type&& cr = static_cast(c);]], [])], - [ax_cv_cxx_compile_cxx0x_cxx=yes], [ax_cv_cxx_compile_cxx0x_cxx=no]) - CXXFLAGS=$ac_save_CXXFLAGS - AS_IF([test "$ax_cv_cxx_compile_cxx0x_cxx" = "yes" ], [SST_CXX0X_FLAGS="-std=c++0x -D__STDC_FORMAT_MACROS"]) - AC_LANG_POP([C++]) - - ]) - ]) - - AS_IF( [test "$ax_cv_cxx_compile_cxx0x_native" = "yes" -o "$ax_cv_cxx_compile_cxx0x_cxx" = "yes" -o "$ax_cv_cxx_compile_cxx11_cxx" = "yes" ], - [found_cxx0x="yes"], [found_cxx0x="no"] ) - - AS_IF( [test "x$found_cxx1y" = "xno" -a "x$found_cxx0x" = "xno"], - [AC_MSG_ERROR([Could not found C++14 or C++11 support but this is required for SST to successfully build.], [1]) ]) - AC_SUBST([SST_CXX0X_FLAGS]) -]) diff --git a/config/ax_cxx_compile_stdcxx_14.m4 b/config/ax_cxx_compile_stdcxx_14.m4 deleted file mode 100644 index 523829d7a..000000000 --- a/config/ax_cxx_compile_stdcxx_14.m4 +++ /dev/null @@ -1,95 +0,0 @@ - -AU_ALIAS([AC_CXX_COMPILE_STDCXX_1Y], [AX_CXX_COMPILE_STDCXX_1Y]) - -AC_DEFUN([AX_CXX_COMPILE_STDCXX_1Y], [ - SST_CXX1Y_FLAGS="" - - AC_CACHE_CHECK(if C++ supports C++1y features without additional flags, - ax_cv_cxx_compile_cxx1y_native, - [AC_LANG_PUSH([C++]) - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ - template - struct check - { - static_assert(sizeof(int) <= sizeof(T), "not big enough"); - }; - - typedef check> right_angle_brackets; - - int a; - decltype(a) b; - - typedef check check_type; - check_type c; - check_type&& cr = static_cast(c);]], [])], - [ax_cv_cxx_compile_cxx1y_native=yes], [ax_cv_cxx_compile_cxx1y_native=no]) - AC_LANG_POP([C++]) - ]) - - SST_CXX1Y_FLAGS="" - - AC_CACHE_CHECK(if C++ supports C++1y features with -std=c++14, - ax_cv_cxx_compile_cxx14_cxx, - [AC_LANG_PUSH([C++]) - ac_save_CXXFLAGS="$CXXFLAGS" - CXXFLAGS="$CXXFLAGS -std=c++14 -D__STDC_FORMAT_MACROS" - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ - template - struct check - { - static_assert(sizeof(int) <= sizeof(T), "not big enough"); - }; - - typedef check> right_angle_brackets; - - int a; - decltype(a) b; - - typedef check check_type; - check_type c; - check_type&& cr = static_cast(c);]]), [])], - [ax_cv_cxx_compile_cxx_14_cxx=yes], [ax_cv_cxx_compile_cxx_14_cxx=no]) - CXXFLAGS=$ac_save_CXXFLAGS - AS_IF([test "$ax_cv_cxx_compile_cxx_14_cxx" = "yes" ], [SST_CXX1Y_FLAGS="-std=c++14 -D__STDC_FORMAT_MACROS"]) - - AC_LANG_POP([C++]) - ]) - - AS_IF([test "$ax_cv_cxx_compile_cxx14_cxx" != "yes"], [ - - AC_CACHE_CHECK(if C++ supports C++1y features with -std=c++1y, - ax_cv_cxx_compile_cxx1y_cxx, - [AC_LANG_PUSH([C++]) - ac_save_CXXFLAGS="$CXXFLAGS" - CXXFLAGS="$CXXFLAGS -std=c++1y -D__STDC_FORMAT_MACROS" - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ - template - struct check - { - static_assert(sizeof(int) <= sizeof(T), "not big enough"); - }; - - typedef check> right_angle_brackets; - - int a; - decltype(a) b; - - typedef check check_type; - check_type c; - check_type&& cr = static_cast(c);]], [])], - [ax_cv_cxx_compile_cxx1y_cxx=yes], [ax_cv_cxx_compile_cxx1y_cxx=no]) - CXXFLAGS=$ac_save_CXXFLAGS - AS_IF([test "$ax_cv_cxx_compile_cxx1y_cxx" = "yes" ], [SST_CXX1Y_FLAGS="-std=c++1y -D__STDC_FORMAT_MACROS"]) - AC_LANG_POP([C++]) - - ]) - ]) - - AS_IF( [test "$ax_cv_cxx_compile_cxx1y_native" = "yes" -o "$ax_cv_cxx_compile_cxx1y_cxx" = "yes" -o "$ax_cv_cxx_compile_cxx14_cxx" = "yes" ], - [found_cxx1y="yes"], [found_cxx1y="no"] ) - - AC_DEFINE(HAVE_STDCXX_1Y, [1], [Define if C++ supports C++14 features.]) - AC_SUBST([SST_CXX1Y_FLAGS]) - AM_CONDITIONAL([HAVE_STDCXX_1Y], [test "x$found_cxx1y" = "xyes"]) -]) - From 558caa6e0080a42eeebccb0bd3a745a641791e11 Mon Sep 17 00:00:00 2001 From: Eric Berquist Date: Thu, 31 Aug 2023 09:37:56 -0600 Subject: [PATCH 3/6] update autoconf C++ standard flag checkers --- config/ax_cxx_compile_stdcxx.m4 | 20 ++++++++-- config/ax_cxx_compile_stdcxx_17.m4 | 62 +++++++++++++++--------------- 2 files changed, 47 insertions(+), 35 deletions(-) diff --git a/config/ax_cxx_compile_stdcxx.m4 b/config/ax_cxx_compile_stdcxx.m4 index e9d093242..9ba371396 100644 --- a/config/ax_cxx_compile_stdcxx.m4 +++ b/config/ax_cxx_compile_stdcxx.m4 @@ -43,7 +43,7 @@ # and this notice are preserved. This file is offered as-is, without any # warranty. -#serial 15 +#serial 18 dnl This macro is based on the code from the AX_CXX_COMPILE_STDCXX_11 macro dnl (serial version number 13). @@ -104,9 +104,18 @@ AC_DEFUN([AX_CXX_COMPILE_STDCXX], [dnl dnl HP's aCC needs +std=c++11 according to: dnl http://h21007.www2.hp.com/portal/download/files/unprot/aCxx/PDF_Release_Notes/769149-001.pdf dnl Cray's crayCC needs "-h std=c++11" + dnl MSVC needs -std:c++NN for C++17 and later (default is C++14) for alternative in ${ax_cxx_compile_alternatives}; do - for switch in -std=c++${alternative} +std=c++${alternative} "-h std=c++${alternative}"; do - cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx$1_$switch]) + for switch in -std=c++${alternative} +std=c++${alternative} "-h std=c++${alternative}" MSVC; do + if test x"$switch" = xMSVC; then + dnl AS_TR_SH maps both `:` and `=` to `_` so -std:c++17 would collide + dnl with -std=c++17. We suffix the cache variable name with _MSVC to + dnl avoid this. + switch=-std:c++${alternative} + cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx$1_${switch}_MSVC]) + else + cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx$1_$switch]) + fi AC_CACHE_CHECK(whether $CXX supports C++$1 features with $switch, $cachevar, [ac_save_CXX="$CXX" @@ -116,6 +125,10 @@ AC_DEFUN([AX_CXX_COMPILE_STDCXX], [dnl [eval $cachevar=no]) CXX="$ac_save_CXX"]) if eval test x\$$cachevar = xyes; then + CXX="$CXX $switch" + if test -n "$CXXCPP" ; then + CXXCPP="$CXXCPP $switch" + fi ac_success=yes break fi @@ -1003,4 +1016,3 @@ namespace cxx20 #endif // __cplusplus < 202002L && !defined _MSC_VER ]]) - diff --git a/config/ax_cxx_compile_stdcxx_17.m4 b/config/ax_cxx_compile_stdcxx_17.m4 index c141a0fa2..a68341717 100644 --- a/config/ax_cxx_compile_stdcxx_17.m4 +++ b/config/ax_cxx_compile_stdcxx_17.m4 @@ -1,35 +1,35 @@ # ============================================================================= -# Elements://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx_17.html +# https://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx_17.html # ============================================================================= -# # -# # SYNOPSIS -# # -# # AX_CXX_COMPILE_STDCXX_17([ext|noext], [mandatory|optional]) -# # -# # DESCRIPTION -# # -# # Check for baseline language coverage in the compiler for the C++17 -# # standard; if necessary, add switches to CXX and CXXCPP to enable -# # support. -# # -# # This macro is a convenience alias for calling the AX_CXX_COMPILE_STDCXX -# # macro with the version set to C++17. The two optional arguments are -# # forwarded literally as the second and third argument respectively. -# # Please see the documentation for the AX_CXX_COMPILE_STDCXX macro for -# # more information. If you want to use this macro, you also need to -# # download the ax_cxx_compile_stdcxx.m4 file. -# # -# # LICENSE -# # -# # Copyright (c) 2015 Moritz Klammler -# # Copyright (c) 2016 Krzesimir Nowak -# # -# # Copying and distribution of this file, with or without modification, are -# # permitted in any medium without royalty provided the copyright notice -# # and this notice are preserved. This file is offered as-is, without any -# # warranty. -# -# #serial 2 # +# SYNOPSIS +# +# AX_CXX_COMPILE_STDCXX_17([ext|noext], [mandatory|optional]) +# +# DESCRIPTION +# +# Check for baseline language coverage in the compiler for the C++17 +# standard; if necessary, add switches to CXX and CXXCPP to enable +# support. +# +# This macro is a convenience alias for calling the AX_CXX_COMPILE_STDCXX +# macro with the version set to C++17. The two optional arguments are +# forwarded literally as the second and third argument respectively. +# Please see the documentation for the AX_CXX_COMPILE_STDCXX macro for +# more information. If you want to use this macro, you also need to +# download the ax_cxx_compile_stdcxx.m4 file. +# +# LICENSE +# +# Copyright (c) 2015 Moritz Klammler +# Copyright (c) 2016 Krzesimir Nowak +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 2 + AX_REQUIRE_DEFINED([AX_CXX_COMPILE_STDCXX]) -AC_DEFUN([AX_CXX_COMPILE_STDCXX_17], [AX_CXX_COMPILE_STDCXX([17], [$1], [$2])]) +AC_DEFUN([AX_CXX_COMPILE_STDCXX_17], [AX_CXX_COMPILE_STDCXX([17], [$1], [$2])]) From 5bea7a5f9211677cd5e8f02b5899926914c286ea Mon Sep 17 00:00:00 2001 From: Eric Berquist Date: Fri, 1 Sep 2023 11:38:46 -0400 Subject: [PATCH 4/6] Fix file operations for unregistering components --- src/sst/core/sstregistertool.cc | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/sst/core/sstregistertool.cc b/src/sst/core/sstregistertool.cc index 45578f97d..9707f9f01 100644 --- a/src/sst/core/sstregistertool.cc +++ b/src/sst/core/sstregistertool.cc @@ -151,14 +151,12 @@ namespace fs = std::filesystem; void sstUnregister(const std::string& element) { - std::string str1; - std::string s = ""; - std::string tempfile; - int found = 0; - // setup element names to look for - str1 = START_DELIMITER + element + STOP_DELIMITER; - tempfile = "/tmp/sstsimulator.conf"; + const std::string str1 = START_DELIMITER + element + STOP_DELIMITER; + const fs::path tempfile = fs::temp_directory_path() / "sstsimulator.conf"; + + std::string s = ""; + int found = 0; std::ifstream infile(cfgPath); std::ofstream outfile(tempfile); @@ -181,12 +179,18 @@ sstUnregister(const std::string& element) infile.close(); outfile.close(); - try { - fs::rename(tempfile.c_str(), cfgPath); - // } catch (fs::filesystem_error const &ex) { - } catch (...) { - std::cerr << "\tError moving " << tempfile.c_str() << " to " << cfgPath << "\n"; - // std::cerr << ex.what() << std::endl; + + if ( !fs::remove(cfgPath) ) { + std::cerr << "\tError removing " << cfgPath << " before moving updated config\n"; + return; + } + if ( !fs::copy_file(tempfile, cfgPath) ) { + std::cerr << "\tError copying updated config" << tempfile << " to " << cfgPath << "\n"; + return; + } + if ( !fs::remove(tempfile) ) { + std::cerr << "\tError removing " << tempfile << " after moving updated config\n"; + return; } } From ae8674fc8d7751c1ea8b1bfacf0f2a259c375b23 Mon Sep 17 00:00:00 2001 From: Eric Berquist Date: Wed, 6 Sep 2023 08:45:33 -0600 Subject: [PATCH 5/6] Switch from filesystem library to cstdio --- src/sst/core/sstregistertool.cc | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/sst/core/sstregistertool.cc b/src/sst/core/sstregistertool.cc index 9707f9f01..fe1e88cb0 100644 --- a/src/sst/core/sstregistertool.cc +++ b/src/sst/core/sstregistertool.cc @@ -17,7 +17,6 @@ #include #include #include -#include #include #include #include @@ -142,8 +141,6 @@ sstRegister(char* argv[]) fclose(cfgFile); } -namespace fs = std::filesystem; - // sstUnregister // Takes a string argument and searches the sstsimulator config file for that name. // Removes the component from the file - unregistering it from SST @@ -153,7 +150,7 @@ sstUnregister(const std::string& element) { // setup element names to look for const std::string str1 = START_DELIMITER + element + STOP_DELIMITER; - const fs::path tempfile = fs::temp_directory_path() / "sstsimulator.conf"; + const auto tempfile = "/tmp/sstsimulator.conf"; std::string s = ""; int found = 0; @@ -180,15 +177,14 @@ sstUnregister(const std::string& element) infile.close(); outfile.close(); - if ( !fs::remove(cfgPath) ) { + if ( std::remove(cfgPath) != 0 ) { std::cerr << "\tError removing " << cfgPath << " before moving updated config\n"; return; } - if ( !fs::copy_file(tempfile, cfgPath) ) { - std::cerr << "\tError copying updated config" << tempfile << " to " << cfgPath << "\n"; - return; - } - if ( !fs::remove(tempfile) ) { + infile = std::ifstream(tempfile, std::ios::binary); + outfile = std::ofstream(cfgPath, std::ios::binary); + outfile << infile.rdbuf(); + if ( std::remove(tempfile) != 0 ) { std::cerr << "\tError removing " << tempfile << " after moving updated config\n"; return; } From 581c8af2aa089235ef97ae44c320c4a67ad912e6 Mon Sep 17 00:00:00 2001 From: Eric Berquist Date: Wed, 6 Sep 2023 08:54:49 -0600 Subject: [PATCH 6/6] Use an autogenerated temporary file name --- src/sst/core/sstregistertool.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sst/core/sstregistertool.cc b/src/sst/core/sstregistertool.cc index fe1e88cb0..1a9fa97b2 100644 --- a/src/sst/core/sstregistertool.cc +++ b/src/sst/core/sstregistertool.cc @@ -150,7 +150,7 @@ sstUnregister(const std::string& element) { // setup element names to look for const std::string str1 = START_DELIMITER + element + STOP_DELIMITER; - const auto tempfile = "/tmp/sstsimulator.conf"; + const auto tempfile = std::tmpnam(nullptr); std::string s = ""; int found = 0;