From 81bcb116ebc195a9837beb0e5c20a2ceed9cde24 Mon Sep 17 00:00:00 2001 From: William F Godoy <williamfgc@yahoo.com> Date: Fri, 21 Jul 2017 16:42:49 -0400 Subject: [PATCH] Added more bug/warning fixes Removed ADIOS copy constructor explicitly, as it wasn't allowed by clang compiler in testing/xml/TestXMLConfig.cpp Using more portable preprocessor definitions to avoid warning on Windows for ctime and fopen Introduced std::throw_with_nested for bad_alloc in STLVector Capsule Removed std:: in C function calls to avoid confusion with actual C++ only calls --- source/adios2/core/ADIOS.h | 21 ++++++++++++++----- source/adios2/helper/adiosSystem.cpp | 10 ++++++--- source/adios2/mpidummy.cpp | 7 +++++++ source/adios2/mpidummy.h | 3 --- .../adios2/toolkit/capsule/heap/STLVector.cpp | 17 +++++++-------- .../toolkit/capsule/shmem/ShmSystemV.cpp | 4 ++-- .../adios2/toolkit/capsule/shmem/ShmSystemV.h | 6 ++++++ .../toolkit/transport/file/FilePointer.cpp | 18 +++++++++++----- .../toolkit/transport/file/FilePointer.h | 2 +- testing/adios2/xml/TestXMLConfig.cpp | 9 ++++---- 10 files changed, 64 insertions(+), 33 deletions(-) diff --git a/source/adios2/core/ADIOS.h b/source/adios2/core/ADIOS.h index c9e993707..618a33232 100644 --- a/source/adios2/core/ADIOS.h +++ b/source/adios2/core/ADIOS.h @@ -33,7 +33,9 @@ class ADIOS public: /** Passed from parallel constructor, MPI_Comm is a pointer itself. */ MPI_Comm m_MPIComm; - std::string m_HostLanguage = "C++"; ///< changed by language bindings + + /** Changed by language bindings */ + std::string m_HostLanguage = "C++"; /** * @brief Constructor for MPI applications WITH a XML config file @@ -66,6 +68,13 @@ public: */ ADIOS(const bool debugMode = false); + /** + * Delete copy constructor explicitly. Objects shouldn't be allowed to be + * redefined. Use smart pointers if this is absolutely necessary. + * @param adios reference to another adios object + */ + ADIOS(const ADIOS &adios) = delete; + ~ADIOS() = default; /** @@ -81,16 +90,18 @@ public: IO &DeclareIO(const std::string ioName); /** - * Retrieve an already defined IO object + * Retrieve an already defined IO object. Make sure IO was previously + * created with DeclareIO. Otherwise, throws an exception in debug mode. + * @return reference to existing IO object inside ADIOS */ IO &GetIO(const std::string name); -protected: // no const member to allow default empty and copy constructors +private: /** XML File to be read containing configuration information */ - std::string m_ConfigFile; + const std::string m_ConfigFile; /** if true will do more checks, exceptions, warnings, expect slower code */ - bool m_DebugMode = false; + const bool m_DebugMode = false; /** transforms associated with ADIOS run */ std::vector<std::shared_ptr<Transform>> m_Transforms; diff --git a/source/adios2/helper/adiosSystem.cpp b/source/adios2/helper/adiosSystem.cpp index f4006fc1b..9dcbd42f3 100644 --- a/source/adios2/helper/adiosSystem.cpp +++ b/source/adios2/helper/adiosSystem.cpp @@ -9,7 +9,7 @@ */ #include "adiosSystem.h" -#include <ctime> //std::ctime +#include <ctime> #include <chrono> //system_clock, now @@ -19,8 +19,12 @@ #include "adios2/ADIOSTypes.h" #include "adios2/helper/adiosString.h" -#ifdef _WIN32 -#define _CRT_SECURE_NO_DEPRECATE // remove warning for ctime +// remove ctime warning on Windows +#ifdef _MSC_VER +#define _CRT_SECURE_NO_WARNINGS +#define _CRT_SECURE_NO_DEPRECATE +#define _SCL_SECURE_NO_WARNINGS +#define _SCL_SECURE_NO_DEPRECATE #endif namespace adios2 diff --git a/source/adios2/mpidummy.cpp b/source/adios2/mpidummy.cpp index 9d7f46b79..763d9a6f3 100644 --- a/source/adios2/mpidummy.cpp +++ b/source/adios2/mpidummy.cpp @@ -33,6 +33,13 @@ #include <chrono> #include <string> +#ifdef _MSC_VER +#define _CRT_SECURE_NO_WARNINGS +#define _CRT_SECURE_NO_DEPRECATE +#define _SCL_SECURE_NO_WARNINGS +#define _SCL_SECURE_NO_DEPRECATE +#endif + namespace adios2 { diff --git a/source/adios2/mpidummy.h b/source/adios2/mpidummy.h index f4607ea20..5457f0dd7 100644 --- a/source/adios2/mpidummy.h +++ b/source/adios2/mpidummy.h @@ -14,9 +14,6 @@ #include <cstdint> #include <cstdio> -/// \cond EXCLUDE_FROM_DOXYGEN -/// \endcond - namespace adios2 { diff --git a/source/adios2/toolkit/capsule/heap/STLVector.cpp b/source/adios2/toolkit/capsule/heap/STLVector.cpp index 545fc9a5d..9ff852d3f 100644 --- a/source/adios2/toolkit/capsule/heap/STLVector.cpp +++ b/source/adios2/toolkit/capsule/heap/STLVector.cpp @@ -43,10 +43,10 @@ void STLVector::ResizeData(const size_t size) } catch (std::bad_alloc &e) { - throw std::runtime_error("ERROR: bad_alloc detected when resizing " - "data buffer with size " + - std::to_string(size) + "\ndescription: " + - std::string(e.what()) + "\n"); + std::throw_with_nested( + std::runtime_error("ERROR: bad_alloc detected when resizing " + "data buffer with size " + + std::to_string(size) + "\n")); } } else @@ -65,11 +65,10 @@ void STLVector::ResizeMetadata(const size_t size) } catch (std::bad_alloc &e) { - throw std::runtime_error("ERROR: bad_alloc detected when resizing " - "metadata buffer with size " + - std::to_string(size) + - "\nadditional description: " + - std::string(e.what()) + "\n"); + std::throw_with_nested( + std::runtime_error("ERROR: bad_alloc detected when resizing " + "metadata buffer with size " + + std::to_string(size) + "\n")); } } else diff --git a/source/adios2/toolkit/capsule/shmem/ShmSystemV.cpp b/source/adios2/toolkit/capsule/shmem/ShmSystemV.cpp index 62486da1d..21ba4efcd 100644 --- a/source/adios2/toolkit/capsule/shmem/ShmSystemV.cpp +++ b/source/adios2/toolkit/capsule/shmem/ShmSystemV.cpp @@ -2,10 +2,10 @@ * Distributed under the OSI-approved Apache License, Version 2.0. See * accompanying file Copyright.txt for details. * - * ShmSystemV.cpp + * ShmSystemV.cpp : implementation of ShmSystemV class * * Created on: Dec 22, 2016 - * Author: wfg + * Author: William F Godoy godoywf@ornl.gov */ #include "ShmSystemV.h" diff --git a/source/adios2/toolkit/capsule/shmem/ShmSystemV.h b/source/adios2/toolkit/capsule/shmem/ShmSystemV.h index df997af7b..b1bf0f48e 100644 --- a/source/adios2/toolkit/capsule/shmem/ShmSystemV.h +++ b/source/adios2/toolkit/capsule/shmem/ShmSystemV.h @@ -1,6 +1,12 @@ /* * Distributed under the OSI-approved Apache License, Version 2.0. See * accompanying file Copyright.txt for details. + * + * ShmSystemV.h : ShmSystem class as a thin wrapper to a shared memory capsule + * using POSIX SystemV + * + * Created on: Dec 22, 2016 + * Author: William F Godoy godoywf@ornl.gov */ #ifndef ADIOS2_TOOLKIT_CAPSULE_SHMEM_SHMSYSTEMV_H_ diff --git a/source/adios2/toolkit/transport/file/FilePointer.cpp b/source/adios2/toolkit/transport/file/FilePointer.cpp index a4f9a7121..468b726e1 100644 --- a/source/adios2/toolkit/transport/file/FilePointer.cpp +++ b/source/adios2/toolkit/transport/file/FilePointer.cpp @@ -14,6 +14,14 @@ #include <ios> //std::ios_base::failure /// \endcond +// removes fopen warning on Windows +#ifdef _MSC_VER +#define _CRT_SECURE_NO_WARNINGS +#define _CRT_SECURE_NO_DEPRECATE +#define _SCL_SECURE_NO_WARNINGS +#define _SCL_SECURE_NO_DEPRECATE +#endif + namespace adios2 { namespace transport @@ -60,7 +68,7 @@ void FilePointer::Open(const std::string &name, const OpenMode openMode) m_File = fopen(name.c_str(), "rb"); } - if (std::ferror(m_File)) + if (ferror(m_File)) { throw std::ios_base::failure("ERROR: couldn't open file " + name + ", " @@ -72,7 +80,7 @@ void FilePointer::Open(const std::string &name, const OpenMode openMode) void FilePointer::SetBuffer(char *buffer, size_t size) { - const int status = std::setvbuf(m_File, buffer, _IOFBF, size); + const int status = setvbuf(m_File, buffer, _IOFBF, size); if (!status) { @@ -90,7 +98,7 @@ void FilePointer::Write(const char *buffer, size_t size) { m_Profiler.Timers.at("write").Resume(); } - auto writtenSize = std::fwrite(buffer, sizeof(char), size, m_File); + auto writtenSize = fwrite(buffer, sizeof(char), size, m_File); if (m_Profiler.IsActive) { @@ -133,7 +141,7 @@ void FilePointer::Write(const char *buffer, size_t size) void FilePointer::Flush() { - const int status = std::fflush(m_File); + const int status = fflush(m_File); if (status == EOF) { @@ -149,7 +157,7 @@ void FilePointer::Close() m_Profiler.Timers.at("close").Resume(); } - const int status = std::fclose(m_File); + const int status = fclose(m_File); if (m_Profiler.IsActive) { diff --git a/source/adios2/toolkit/transport/file/FilePointer.h b/source/adios2/toolkit/transport/file/FilePointer.h index 7c14b4806..6d1521a3d 100644 --- a/source/adios2/toolkit/transport/file/FilePointer.h +++ b/source/adios2/toolkit/transport/file/FilePointer.h @@ -45,7 +45,7 @@ public: private: /** C File pointer */ - std::FILE *m_File = nullptr; // NULL or nullptr? + FILE *m_File = nullptr; // NULL or nullptr? }; } // end namespace transport diff --git a/testing/adios2/xml/TestXMLConfig.cpp b/testing/adios2/xml/TestXMLConfig.cpp index 6724a9a88..5d3cb161b 100644 --- a/testing/adios2/xml/TestXMLConfig.cpp +++ b/testing/adios2/xml/TestXMLConfig.cpp @@ -54,14 +54,13 @@ TEST_F(XMLConfigTest, TwoIOs) TEST_F(XMLConfigTest, TwoEnginesException) { std::string configFile = configDir + "/config2.xml"; - adios2::ADIOS adios; #ifdef ADIOS2_HAVE_MPI - EXPECT_THROW(adios = - adios2::ADIOS(configFile, MPI_COMM_WORLD, adios2::DebugON), - std::invalid_argument); + EXPECT_THROW( + adios2::ADIOS adios(configFile, MPI_COMM_WORLD, adios2::DebugON), + std::invalid_argument); #else - EXPECT_THROW(adios = adios2::ADIOS(configFile, adios2::DebugON), + EXPECT_THROW(adios2::ADIOS adios(configFile, adios2::DebugON), std::invalid_argument); #endif } -- GitLab