From 3b07146d57387ad695a7c0745c77c6c891338212 Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Mon, 10 Jul 2023 15:26:44 -0400 Subject: [PATCH] Squashed 'externals/coda-oss/' changes from c2fc5fc66..f70b4202f f70b4202f account for coda-oss.vcxproj being in other SLNs af3faebfc Remove more compiler/code-analysis warnings (#699) 82be2a6db unittests should work w/o install (#698) dbb90a06d add msbuild for coda-oss.sln (#697) 5a417140a reduce compiler warnings (#696) 288619dfa all modules now part of coda-oss.vcxproj (#695) git-subtree-dir: externals/coda-oss git-subtree-split: f70b4202f19f260941a0245e41301ae232348fc7 --- .github/workflows/build_unittest.yml | 36 +- CMakeLists.txt | 1 + UnitTest/UnitTest.vcxproj | 31 +- UnitTest/UnitTest.vcxproj.filters | 21 + UnitTest/avx.cpp | 2 + UnitTest/mem.cpp | 3 + UnitTest/mt.cpp | 11 + UnitTest/pch.h | 78 +- UnitTest/polygon.cpp | 3 + UnitTest/str.cpp | 1 + UnitTest/sys.cpp | 21 + UnitTest/types.cpp | 6 + UnitTest/xml.lite.cpp | 33 + UnitTest/zip.cpp | 1 + cmake/CodaFindSystemDependencies.cmake | 3 - coda-oss-lite.sln => coda-oss.sln | 2 +- modules/CMakeLists.txt | 2 + modules/c++/CMakeLists.txt | 27 +- modules/c++/cli/include/cli/Argument.h | 20 +- modules/c++/cli/source/Argument.cpp | 4 +- modules/c++/cli/source/ArgumentParser.cpp | 12 +- modules/c++/coda-oss.ruleset | 699 ++++++++++++++++++ ...coda-oss-lite.vcxproj => coda-oss.vcxproj} | 114 ++- ...xproj.filters => coda-oss.vcxproj.filters} | 295 +++++++- .../c++/dbi/source/DatabaseClientFactory.cpp | 2 +- modules/c++/dbi/source/OracleConnection.cpp | 18 +- modules/c++/except/source/Backtrace.cpp | 6 +- modules/c++/framework.h | 12 +- modules/c++/gsl/include/gsl/gsl.h | 1 + modules/c++/hdf5.lite/include/hdf5/lite/H5_.h | 69 ++ .../hdf5.lite/include/hdf5/lite/highfive.h | 4 +- modules/c++/include/TestCase.h | 3 +- modules/c++/io/include/io/PipeStream.h | 2 +- modules/c++/io/include/io/Serializable.h | 2 +- modules/c++/io/source/FileInputStreamOS.cpp | 6 +- modules/c++/io/source/InputStream.cpp | 2 +- modules/c++/io/source/MMapInputStream.cpp | 4 +- modules/c++/io/source/PipeStream.cpp | 2 +- modules/c++/io/source/StandardStreams.cpp | 4 +- modules/c++/io/source/StreamSplitter.cpp | 2 +- .../unittests/test_exception_logger.cpp | 2 +- .../include/math/linear/MatrixMxN.h | 2 +- modules/c++/math/include/math/Round.h | 20 +- modules/c++/math/source/Bessel.cpp | 7 +- modules/c++/mem/include/mem/ScratchMemory.h | 7 +- modules/c++/mem/include/mem/ScratchMemory.hpp | 2 +- modules/c++/mem/include/mem/SharedPtrCpp11.h | 2 - modules/c++/mem/source/ScratchMemory.cpp | 25 +- .../c++/mem/tests/ScratchVisualization.cpp | 12 +- .../c++/mt/include/mt/AbstractThreadPool.h | 5 + modules/c++/mt/include/mt/WorkerThread.h | 8 +- .../c++/mt/source/GenerationThreadPool.cpp | 6 +- .../c++/mt/source/GenericRequestHandler.cpp | 2 +- modules/c++/mt/source/ThreadGroup.cpp | 4 +- modules/c++/net.ssl/source/SSLConnection.cpp | 4 +- .../source/SSLConnectionClientFactory.cpp | 4 +- .../c++/net/include/net/NetConnectionServer.h | 9 +- .../net/PerRequestThreadAllocStrategy.h | 8 +- modules/c++/net/include/net/SocketsWin32.h | 19 +- .../net/include/net/ThreadPoolAllocStrategy.h | 10 + modules/c++/net/source/CurlHandle.cpp | 4 +- .../c++/net/source/NetConnectionServer.cpp | 2 +- modules/c++/net/source/NetUtils.cpp | 2 +- modules/c++/net/source/SocketAddress.cpp | 4 +- modules/c++/numpyutils/source/numpyutils.cpp | 6 + modules/c++/pch.h | 109 ++- modules/c++/re/include/re/Regex.h | 4 - modules/c++/re/source/RegexPCRE.cpp | 5 + modules/c++/re/source/RegexSTL.cpp | 33 +- .../sio.lite/include/sio/lite/SioFileWriter.h | 5 + modules/c++/sio.lite/source/StreamReader.cpp | 4 +- modules/c++/std/include/import/cpp14.h | 60 -- modules/c++/std/include/import/cpp17.h | 36 - modules/c++/std/include/import/std.h | 64 +- modules/c++/str/source/Encoding.cpp | 94 ++- modules/c++/str/source/Format.cpp | 19 +- modules/c++/str/source/Manip.cpp | 14 +- .../c++/str/unittests/test_base_convert.cpp | 13 +- modules/c++/str/unittests/test_str.cpp | 6 +- modules/c++/sys/include/sys/AbstractOS.h | 6 +- modules/c++/sys/include/sys/Conf.h | 2 +- modules/c++/sys/include/sys/Dbg.h | 4 +- modules/c++/sys/include/sys/OSWin32.h | 2 +- modules/c++/sys/include/sys/ReadWriteMutex.h | 2 +- modules/c++/sys/include/sys/String.h | 29 - modules/c++/sys/include/sys/ThreadInterface.h | 2 +- modules/c++/sys/include/sys/ThreadPosix.h | 2 +- modules/c++/sys/source/AbstractOS.cpp | 7 + modules/c++/sys/source/ConditionVarPosix.cpp | 6 +- modules/c++/sys/source/ConditionVarWin32.cpp | 15 +- modules/c++/sys/source/Conf.cpp | 5 +- modules/c++/sys/source/DLLUnix.cpp | 4 +- modules/c++/sys/source/DLLWin32.cpp | 6 +- modules/c++/sys/source/DateTime.cpp | 16 +- modules/c++/sys/source/Dbg.cpp | 24 +- modules/c++/sys/source/ErrUnix.cpp | 2 +- modules/c++/sys/source/ErrWin32.cpp | 4 +- modules/c++/sys/source/ExecUnix.cpp | 8 +- modules/c++/sys/source/ExecWin32.cpp | 23 +- modules/c++/sys/source/FileFinder.cpp | 6 +- modules/c++/sys/source/FileUnix.cpp | 2 +- modules/c++/sys/source/FileWin32.cpp | 6 +- modules/c++/sys/source/LocalDateTime.cpp | 2 +- modules/c++/sys/source/MutexWin32.cpp | 4 +- modules/c++/sys/source/OSUnix.cpp | 14 +- modules/c++/sys/source/OSWin32.cpp | 31 +- modules/c++/sys/source/ResourceCheck.cpp | 3 +- .../c++/sys/source/ScopedCPUAffinityUnix.cpp | 7 +- modules/c++/sys/source/SemaphoreWin32.cpp | 10 +- modules/c++/sys/source/StopWatch.cpp | 6 +- modules/c++/sys/source/ThreadPosix.cpp | 8 +- modules/c++/sys/source/ThreadWin32.cpp | 4 +- modules/c++/sys/source/UTCDateTime.cpp | 2 +- modules/c++/sys/source/sys_Backtrace.cpp | 2 +- modules/c++/sys/tests/DLLTest.cpp | 2 +- modules/c++/tiff/source/IFD.cpp | 4 +- modules/c++/tiff/source/IFDEntry.cpp | 4 +- modules/c++/tiff/source/ImageWriter.cpp | 2 +- modules/c++/tiff/source/KnownTags.cpp | 2 +- modules/c++/tiff/source/TypeFactory.cpp | 2 +- modules/c++/tiff/source/Utils.cpp | 6 +- modules/c++/types/include/types/PageRowCol.h | 44 +- modules/c++/types/include/types/RowCol.h | 3 +- .../c++/types/unittests/test_page_row_col.cpp | 4 +- modules/c++/unique/source/UUID.cpp | 2 +- modules/c++/unique/wscript | 1 - .../xml.lite/include/xml/lite/Attributes.h | 10 +- .../include/xml/lite/ContentHandler.h | 8 +- .../c++/xml.lite/include/xml/lite/Document.h | 6 +- .../c++/xml.lite/include/xml/lite/Element.h | 48 +- .../include/xml/lite/MinidomHandler.h | 7 +- .../xml.lite/include/xml/lite/MinidomParser.h | 5 +- modules/c++/xml.lite/include/xml/lite/QName.h | 10 +- .../xml.lite/include/xml/lite/Serializable.h | 6 +- .../include/xml/lite/UtilitiesXerces.h | 36 +- .../include/xml/lite/ValidatorInterface.h | 13 +- .../include/xml/lite/ValidatorXerces.h | 24 +- .../include/xml/lite/XMLReaderInterface.h | 12 +- .../include/xml/lite/XMLReaderXerces.h | 5 +- .../c++/xml.lite/include/xml/lite/xerces_.h | 97 +++ modules/c++/xml.lite/source/Document.cpp | 8 +- modules/c++/xml.lite/source/Element.cpp | 4 +- .../c++/xml.lite/source/MinidomHandler.cpp | 2 +- modules/c++/xml.lite/source/QName.cpp | 2 +- modules/c++/xml.lite/source/Serializable.cpp | 2 +- .../c++/xml.lite/source/ValidatorXerces.cpp | 13 +- .../c++/xml.lite/source/XMLReaderXerces.cpp | 1 + .../xml.lite/unittests/test_soapelements.cpp | 13 +- .../xml.lite/unittests/test_xmlattribute.cpp | 35 +- .../xml.lite/unittests/test_xmlelement.cpp | 32 +- .../c++/xml.lite/unittests/test_xmlparser.cpp | 137 ++-- modules/c++/zip/source/GZipInputStream.cpp | 4 +- modules/c++/zip/source/GZipOutputStream.cpp | 4 +- modules/c++/zip/source/ZipEntry.cpp | 6 +- modules/c++/zip/source/ZipOutputStream.cpp | 8 +- modules/drivers/j2k/openjpeg/CMakeLists.txt | 6 +- modules/drivers/jpeg/CMakeLists.txt | 12 +- modules/drivers/pcre/CMakeLists.txt | 8 +- modules/drivers/uuid/CMakeLists.txt | 2 +- modules/drivers/xml/xerces/CMakeLists.txt | 54 +- 160 files changed, 2366 insertions(+), 833 deletions(-) create mode 100644 UnitTest/xml.lite.cpp rename coda-oss-lite.sln => coda-oss.sln (90%) create mode 100644 modules/c++/coda-oss.ruleset rename modules/c++/{coda-oss-lite.vcxproj => coda-oss.vcxproj} (77%) rename modules/c++/{coda-oss-lite.vcxproj.filters => coda-oss.vcxproj.filters} (79%) create mode 100644 modules/c++/hdf5.lite/include/hdf5/lite/H5_.h delete mode 100644 modules/c++/std/include/import/cpp14.h delete mode 100644 modules/c++/std/include/import/cpp17.h delete mode 100644 modules/c++/sys/include/sys/String.h create mode 100644 modules/c++/xml.lite/include/xml/lite/xerces_.h diff --git a/.github/workflows/build_unittest.yml b/.github/workflows/build_unittest.yml index 3f7b581659..04b2f3fae3 100644 --- a/.github/workflows/build_unittest.yml +++ b/.github/workflows/build_unittest.yml @@ -36,20 +36,33 @@ jobs: cd .. cd target-Debug cmake --build . --config Debug -j - - name: install + - name: test + # should run w/o install run: | cd target-Release - cmake --build . --config Release --target install + ctest -C Release --output-on-failure cd .. cd target-Debug - cmake --build . --config Debug --target install - - name: test + ctest -C Debug --output-on-failure + - name: install run: | cd target-Release - ctest -C Release --output-on-failure + cmake --build . --config Release --target install cd .. cd target-Debug - ctest -C Debug --output-on-failure + cmake --build . --config Debug --target install + cd .. + - name: Add msbuild to PATH + uses: microsoft/setup-msbuild@v1.1 + with: + msbuild-architecture: x64 + - name: msbuild + run: | + msbuild coda-oss.sln /p:configuration=Release + msbuild coda-oss.sln /p:configuration=Debug + #- name: mstest + # run: | + # mstest /testcontainer:${RUNNER_WORKSPACE}\coda-oss\x64\Debug\UnitTest.dll build-linux-cmake: strategy: @@ -79,14 +92,15 @@ jobs: cd target # "-j" spawns too many processes causing GCC to crash cmake --build . -j 12 - - name: install - run: | - cd target - cmake --build . --target install - name: test + # should run w/o install run: | cd target ctest --output-on-failure + - name: install + run: | + cd target + cmake --build . --target install build-waf: strategy: @@ -94,7 +108,7 @@ jobs: os: [ubuntu-latest, windows-2019] python-version: ['3.7'] debugging: ['--enable-debugging', ''] - name: ${{ matrix.os }}-${{ matrix.python-version }}-waf + name: ${{ matrix.os }}-${{ matrix.python-version }}-waf${{ matrix.debugging }} runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v3 diff --git a/CMakeLists.txt b/CMakeLists.txt index f1aa8e5ac9..4b1bc2c645 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,6 +31,7 @@ if (${CMAKE_PROJECT_NAME} STREQUAL coda-oss) endif() elseif (UNIX) add_compile_options(-Werror) # warnings as errors + if (ENABLE_ASAN) # https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html add_compile_options(-fsanitize=address) diff --git a/UnitTest/UnitTest.vcxproj b/UnitTest/UnitTest.vcxproj index 65fb191b71..65b3ca3225 100644 --- a/UnitTest/UnitTest.vcxproj +++ b/UnitTest/UnitTest.vcxproj @@ -57,7 +57,7 @@ Use Level4 true - $(VCInstallDir)UnitTest\include;$(ProjectDir);$(SolutionDir)modules\c++\;$(SolutionDir)modules\c++\avx\include\;$(SolutionDir)modules\c++\cli\include\;$(SolutionDir)modules\c++\config\include\;$(SolutionDir)modules\c++\coda_oss\include\;$(SolutionDir)modules\c++\gsl\include\;$(SolutionDir)modules\c++\hdf5.lite\include\;$(SolutionDir)modules\c++\io\include\;$(SolutionDir)modules\c++\std\include\;$(SolutionDir)modules\c++\str\include\;$(SolutionDir)modules\c++\sys\include\;$(SolutionDir)modules\c++\except\include\;$(SolutionDir)modules\c++\logging\include\;$(SolutionDir)modules\c++\math\include\;$(SolutionDir)modules\c++\math.linear\include\;$(SolutionDir)modules\c++\math.poly\include\;$(SolutionDir)modules\c++\mem\include\;$(SolutionDir)modules\c++\mt\include\;$(SolutionDir)modules\c++\polygon\include\;$(SolutionDir)modules\c++\re\include\;$(SolutionDir)modules\c++\types\include\;$(SolutionDir)modules\c++\units\include\;$(SolutionDir)modules\c++\zip\include\;$(SolutionDir)out\install\$(Platform)-$(Configuration)\include\;%(AdditionalIncludeDirectories) + $(VCInstallDir)UnitTest\include;$(ProjectDir);$(SolutionDir)modules\c++\;$(SolutionDir)modules\c++\avx\include\;$(SolutionDir)modules\c++\cli\include\;$(SolutionDir)modules\c++\config\include\;$(SolutionDir)modules\c++\coda_oss\include\;$(SolutionDir)modules\c++\gsl\include\;$(SolutionDir)modules\c++\hdf5.lite\include\;$(SolutionDir)modules\c++\io\include\;$(SolutionDir)modules\c++\std\include\;$(SolutionDir)modules\c++\str\include\;$(SolutionDir)modules\c++\sys\include\;$(SolutionDir)modules\c++\except\include\;$(SolutionDir)modules\c++\logging\include\;$(SolutionDir)modules\c++\math\include\;$(SolutionDir)modules\c++\math.linear\include\;$(SolutionDir)modules\c++\math.poly\include\;$(SolutionDir)modules\c++\mem\include\;$(SolutionDir)modules\c++\mt\include\;$(SolutionDir)modules\c++\polygon\include\;$(SolutionDir)modules\c++\re\include\;$(SolutionDir)modules\c++\types\include\;$(SolutionDir)modules\c++\units\include\;$(SolutionDir)modules\c++\xml.lite\include\;$(SolutionDir)modules\c++\zip\include\;$(SolutionDir)out\install\$(Platform)-$(Configuration)\include\;$(SolutionDir)\target-$(Configuration)\installwindows-latestCMake-Github\include\;%(AdditionalIncludeDirectories) _DEBUG;%(PreprocessorDefinitions);MT_DEFAULT_PINNING=0;RE_ENABLE_STD_REGEX=1 true pch.h @@ -75,7 +75,7 @@ Windows - $(SolutionDir)\out\install\$(Platform)-$(Configuration)\lib\;$(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories) + $(SolutionDir)\out\install\$(Platform)-$(Configuration)\lib\;$(SolutionDir)\target-$(Configuration)\installwindows-latestCMake-Github\lib\;$(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories) @@ -85,7 +85,7 @@ true true true - $(VCInstallDir)UnitTest\include;$(ProjectDir);$(SolutionDir)modules\c++\;$(SolutionDir)modules\c++\avx\include\;$(SolutionDir)modules\c++\cli\include\;$(SolutionDir)modules\c++\config\include\;$(SolutionDir)modules\c++\coda_oss\include\;$(SolutionDir)modules\c++\gsl\include\;$(SolutionDir)modules\c++\hdf5.lite\include\;$(SolutionDir)modules\c++\io\include\;$(SolutionDir)modules\c++\std\include\;$(SolutionDir)modules\c++\str\include\;$(SolutionDir)modules\c++\sys\include\;$(SolutionDir)modules\c++\except\include\;$(SolutionDir)modules\c++\logging\include\;$(SolutionDir)modules\c++\math\include\;$(SolutionDir)modules\c++\math.linear\include\;$(SolutionDir)modules\c++\math.poly\include\;$(SolutionDir)modules\c++\mem\include\;$(SolutionDir)modules\c++\mt\include\;$(SolutionDir)modules\c++\polygon\include\;$(SolutionDir)modules\c++\re\include\;$(SolutionDir)modules\c++\types\include\;$(SolutionDir)modules\c++\units\include\;$(SolutionDir)modules\c++\zip\include\;$(SolutionDir)out\install\$(Platform)-$(Configuration)\include\;%(AdditionalIncludeDirectories) + $(VCInstallDir)UnitTest\include;$(ProjectDir);$(SolutionDir)modules\c++\;$(SolutionDir)modules\c++\avx\include\;$(SolutionDir)modules\c++\cli\include\;$(SolutionDir)modules\c++\config\include\;$(SolutionDir)modules\c++\coda_oss\include\;$(SolutionDir)modules\c++\gsl\include\;$(SolutionDir)modules\c++\hdf5.lite\include\;$(SolutionDir)modules\c++\io\include\;$(SolutionDir)modules\c++\std\include\;$(SolutionDir)modules\c++\str\include\;$(SolutionDir)modules\c++\sys\include\;$(SolutionDir)modules\c++\except\include\;$(SolutionDir)modules\c++\logging\include\;$(SolutionDir)modules\c++\math\include\;$(SolutionDir)modules\c++\math.linear\include\;$(SolutionDir)modules\c++\math.poly\include\;$(SolutionDir)modules\c++\mem\include\;$(SolutionDir)modules\c++\mt\include\;$(SolutionDir)modules\c++\polygon\include\;$(SolutionDir)modules\c++\re\include\;$(SolutionDir)modules\c++\types\include\;$(SolutionDir)modules\c++\units\include\;$(SolutionDir)modules\c++\xml.lite\include\;$(SolutionDir)modules\c++\zip\include\;$(SolutionDir)out\install\$(Platform)-$(Configuration)\include\;$(SolutionDir)\target-$(Configuration)\installwindows-latestCMake-Github\include\;%(AdditionalIncludeDirectories) NDEBUG;%(PreprocessorDefinitions);MT_DEFAULT_PINNING=0;RE_ENABLE_STD_REGEX=1 true pch.h @@ -103,7 +103,7 @@ Windows true true - $(SolutionDir)\out\install\$(Platform)-$(Configuration)\lib\;$(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories) + $(SolutionDir)\out\install\$(Platform)-$(Configuration)\lib\;$(SolutionDir)\target-$(Configuration)\installwindows-latestCMake-Github\lib\;$(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories) @@ -355,6 +355,26 @@ true true + + true + true + + + true + true + + + true + true + + + true + true + + + true + true + true true @@ -380,6 +400,7 @@ + @@ -387,7 +408,7 @@ - + {9997e895-5161-4ddf-8f3f-099894cb2f21} diff --git a/UnitTest/UnitTest.vcxproj.filters b/UnitTest/UnitTest.vcxproj.filters index c4c85031c1..ab3ead71f4 100644 --- a/UnitTest/UnitTest.vcxproj.filters +++ b/UnitTest/UnitTest.vcxproj.filters @@ -243,6 +243,24 @@ zip + + xml.lite + + + xml.lite + + + xml.lite + + + xml.lite + + + xml.lite + + + xml.lite + @@ -300,5 +318,8 @@ {223c163f-0321-4935-8e20-0e05f048adf0} + + {f4dfc761-e468-4305-84dc-f3579e46107e} + \ No newline at end of file diff --git a/UnitTest/avx.cpp b/UnitTest/avx.cpp index 535dc859f3..907c5ddbcf 100644 --- a/UnitTest/avx.cpp +++ b/UnitTest/avx.cpp @@ -1,6 +1,8 @@ #include "pch.h" #include "CppUnitTest.h" +#include + namespace avx { diff --git a/UnitTest/mem.cpp b/UnitTest/mem.cpp index ea35c94051..375bb9384e 100644 --- a/UnitTest/mem.cpp +++ b/UnitTest/mem.cpp @@ -3,6 +3,9 @@ #include #include +#include +#include +#include namespace mem { diff --git a/UnitTest/mt.cpp b/UnitTest/mt.cpp index 6190f8aa4a..6be7aa9333 100644 --- a/UnitTest/mt.cpp +++ b/UnitTest/mt.cpp @@ -1,6 +1,17 @@ #include "pch.h" #include "CppUnitTest.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + namespace mt { diff --git a/UnitTest/pch.h b/UnitTest/pch.h index 14807bb811..8c2ebbb93c 100644 --- a/UnitTest/pch.h +++ b/UnitTest/pch.h @@ -24,81 +24,35 @@ #include #include "import/std.h" - -#include -#include -#include -#include #include +#include #include -#include // std::endian #include +#include +#include +#include +#include #include "CppUnitTest.h" -#include "coda_oss/span.h" -#include "gsl/gsl.h" -#include "import/sys.h" -#include "import/math.h" -#include "import/str.h" -#include "str/EncodedStringView.h" -#include "import/except.h" -#include "import/mem.h" -#include -#include -#include -#include "import/cli.h" -#include "polygon/DrawPolygon.h" -#include "polygon/PolygonMask.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include #include +#include #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include #include -#include -#include #include #include -#include "io/StringStream.h" -#include +#include +#include +#include + #include +#include #include "TestCase.h" diff --git a/UnitTest/polygon.cpp b/UnitTest/polygon.cpp index 32bc9fd0ba..424f3aa8a9 100644 --- a/UnitTest/polygon.cpp +++ b/UnitTest/polygon.cpp @@ -1,6 +1,9 @@ #include "pch.h" #include "CppUnitTest.h" +#include +#include + namespace polygon { TEST_CLASS(test_polygon_mask){ public: diff --git a/UnitTest/str.cpp b/UnitTest/str.cpp index d7fe5b718e..a3be22b7c9 100644 --- a/UnitTest/str.cpp +++ b/UnitTest/str.cpp @@ -5,6 +5,7 @@ #include #include +#include namespace str { diff --git a/UnitTest/sys.cpp b/UnitTest/sys.cpp index bedfa98188..7ac63c6a10 100644 --- a/UnitTest/sys.cpp +++ b/UnitTest/sys.cpp @@ -1,6 +1,27 @@ #include "pch.h" #include "CppUnitTest.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + namespace sys { TEST_CLASS(test_aligned_alloc){ public: diff --git a/UnitTest/types.cpp b/UnitTest/types.cpp index 3d03155b3f..64bb3a2723 100644 --- a/UnitTest/types.cpp +++ b/UnitTest/types.cpp @@ -1,6 +1,12 @@ #include "pch.h" #include "CppUnitTest.h" +#include +#include +#include +#include +#include + namespace types { TEST_CLASS(test_page_row_col){ public: diff --git a/UnitTest/xml.lite.cpp b/UnitTest/xml.lite.cpp new file mode 100644 index 0000000000..375a17fe54 --- /dev/null +++ b/UnitTest/xml.lite.cpp @@ -0,0 +1,33 @@ +#include "pch.h" +#include "CppUnitTest.h" + +#include +#include +#include +#include +#include + +namespace xml_lite +{ + +TEST_CLASS(test_soapelements){ public: +#include "xml.lite/unittests/test_soapelements.cpp" +}; + +TEST_CLASS(test_xmlattribute){ public: +#include "xml.lite/unittests/test_xmlattribute.cpp" +}; + +TEST_CLASS(test_xmlcreate){ public: +#include "xml.lite/unittests/test_xmlcreate.cpp" +}; + +TEST_CLASS(test_xmlelement){ public: +#include "xml.lite/unittests/test_xmlelement.cpp" +}; + +TEST_CLASS(test_xmlparser){ public: +#include "xml.lite/unittests/test_xmlparser.cpp" +}; + +} \ No newline at end of file diff --git a/UnitTest/zip.cpp b/UnitTest/zip.cpp index b9fc79389f..6dd08743f9 100644 --- a/UnitTest/zip.cpp +++ b/UnitTest/zip.cpp @@ -2,6 +2,7 @@ #include "CppUnitTest.h" #include +#include namespace zip { diff --git a/cmake/CodaFindSystemDependencies.cmake b/cmake/CodaFindSystemDependencies.cmake index 5efe5c73b9..808361823e 100644 --- a/cmake/CodaFindSystemDependencies.cmake +++ b/cmake/CodaFindSystemDependencies.cmake @@ -92,9 +92,6 @@ macro(coda_find_system_dependencies) if (PYTHON_EXTRA_NATIVE) list(APPEND CMAKE_SWIG_FLAGS "-extranative") endif() - if (Python_VERSION_MAJOR GREATER_EQUAL 3) - list(APPEND CMAKE_SWIG_FLAGS "-py3") - endif() endif() else() set(SWIG_FOUND OFF CACHE INTERNAL "") diff --git a/coda-oss-lite.sln b/coda-oss.sln similarity index 90% rename from coda-oss-lite.sln rename to coda-oss.sln index 8310d71fd3..5583590dd7 100644 --- a/coda-oss-lite.sln +++ b/coda-oss.sln @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.1.32421.90 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "coda-oss-lite", "modules\c++\coda-oss-lite.vcxproj", "{9997E895-5161-4DDF-8F3F-099894CB2F21}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "coda-oss", "modules\c++\coda-oss.vcxproj", "{9997E895-5161-4DDF-8F3F-099894CB2F21}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{DEB848DD-4285-4BFA-9B2F-60FA46200205}" ProjectSection(SolutionItems) = preProject diff --git a/modules/CMakeLists.txt b/modules/CMakeLists.txt index d21b6d252c..d7a4f7d71e 100644 --- a/modules/CMakeLists.txt +++ b/modules/CMakeLists.txt @@ -1,5 +1,7 @@ add_subdirectory("drivers") + add_subdirectory("c++") if (BUILD_PYTHON_MODULES) add_subdirectory("python") endif() + diff --git a/modules/c++/CMakeLists.txt b/modules/c++/CMakeLists.txt index 5d6ec9ed88..d242748651 100644 --- a/modules/c++/CMakeLists.txt +++ b/modules/c++/CMakeLists.txt @@ -12,14 +12,27 @@ if (MSVC) elseif (UNIX) add_compile_options(-std=c++14) - add_compile_options(-Wall -pedantic -Wextra) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wregister") # -Wvolatile - #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Weffc++") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wzero-as-null-pointer-constant") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Woverloaded-virtual") + # https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html + add_compile_options(-Werror) # Make all warnings into errors + add_compile_options(-Wall -Wextra -Wpedantic -pedantic-errors -Wunused) + + add_compile_options(-Wzero-as-null-pointer-constant) + add_compile_options(-Wsuggest-final-types -Wsuggest-final-methods) + add_compile_options(-Wsuggest-override) + add_compile_options(-Woverloaded-virtual) + add_compile_options(-Warray-bounds) + add_compile_options(-Wduplicated-branches -Wduplicated-cond) + add_compile_options(-Wtrampolines) + add_compile_options(-Wshadow) #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wold-style-cast") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wsuggest-final-types -Wsuggest-final-methods") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wsuggest-override") + #add_compile_options(-Wfloat-equal) + #add_compile_options(-Wconversion) + #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Weffc++") + + add_compile_options(-Wno-double-promotion) # implicit conversion of `float` to `double` is fine + + # Need a newer compiler than GCC 9 + #add_compile_options(-Wnrvo) endif() # add an interface library for unittests diff --git a/modules/c++/cli/include/cli/Argument.h b/modules/c++/cli/include/cli/Argument.h index e7a90f83b4..65763cebcb 100644 --- a/modules/c++/cli/include/cli/Argument.h +++ b/modules/c++/cli/include/cli/Argument.h @@ -100,20 +100,20 @@ class CODA_OSS_API Argument std::string mName; std::vector mShortFlags; std::vector mLongFlags; - Action mAction; - int mMinArgs; - int mMaxArgs; - Value* mDefaultValue; - bool mOwnDefault; + Action mAction = cli::STORE; + int mMinArgs = 0; + int mMaxArgs = 1; + Value* mDefaultValue = nullptr; + bool mOwnDefault = false; std::vector mChoices; std::string mHelp; std::string mMetavar; std::string mDestination; - Value* mConstValue; - bool mOwnConst; - bool mRequired; - bool mShowsHelp; - ArgumentParser* mParser; + Value* mConstValue = nullptr; + bool mOwnConst = false; + bool mRequired = false; + bool mShowsHelp = true; + ArgumentParser* mParser = nullptr; friend class ArgumentParser; Argument(const std::string& nameOrFlags, ArgumentParser* parser); diff --git a/modules/c++/cli/source/Argument.cpp b/modules/c++/cli/source/Argument.cpp index a925262d16..11c541a2c2 100644 --- a/modules/c++/cli/source/Argument.cpp +++ b/modules/c++/cli/source/Argument.cpp @@ -25,9 +25,7 @@ #include cli::Argument::Argument(const std::string& nameOrFlags, cli::ArgumentParser* parser): - mAction(cli::STORE), mMinArgs(0), mMaxArgs(1), mDefaultValue(NULL), - mOwnDefault(false), mConstValue(NULL), mOwnConst(false), - mRequired(false), mShowsHelp(true), mParser(parser) + mParser(parser) { std::vector < std::string > vars = str::split(nameOrFlags, " "); if (vars.size() == 1 && !str::startsWith(vars[0], "-")) diff --git a/modules/c++/cli/source/ArgumentParser.cpp b/modules/c++/cli/source/ArgumentParser.cpp index 2a31bda458..be702484ef 100644 --- a/modules/c++/cli/source/ArgumentParser.cpp +++ b/modules/c++/cli/source/ArgumentParser.cpp @@ -415,12 +415,12 @@ std::unique_ptr cli::ArgumentParser::parse(const std::string& prog } auto results = std::make_unique(); - cli::Results *currentResults = NULL; + cli::Results* currentResults = nullptr; for (size_t i = 0, s = explodedArgs.size(); i < s; ++i) { currentResults = results.get(); // set the pointer std::string argStr = explodedArgs[i]; - cli::Argument *arg = NULL; + cli::Argument* arg = nullptr; std::string optionsStr(""); if (argStr.size() > 2 && argStr[0] == mPrefixChar && argStr[1] == mPrefixChar) @@ -509,7 +509,7 @@ std::unique_ptr cli::ArgumentParser::parse(const std::string& prog } - if (arg != NULL) + if (arg != nullptr) { std::string argVar = arg->getVariable(); switch (arg->getAction()) @@ -566,7 +566,7 @@ std::unique_ptr cli::ArgumentParser::parse(const std::string& prog case cli::STORE_CONST: { const Value* constVal = arg->getConst(); - currentResults->put(argVar, constVal ? constVal->clone() : NULL); + currentResults->put(argVar, constVal ? constVal->clone() : nullptr); break; } case cli::SUB_OPTIONS: @@ -607,7 +607,7 @@ std::unique_ptr cli::ArgumentParser::parse(const std::string& prog else { // it's a positional argument - cli::Value *lastPosVal = NULL; + cli::Value* lastPosVal = nullptr; for (std::vector::iterator it = positionalArgs.begin(); it != positionalArgs.end(); ++it) { @@ -655,7 +655,7 @@ std::unique_ptr cli::ArgumentParser::parse(const std::string& prog if (!results->hasValue(argVar)) { const Value* defaultVal = arg->getDefault(); - if (defaultVal != NULL) + if (defaultVal != nullptr) results->put(argVar, defaultVal->clone()); else if (arg->getAction() == cli::STORE_FALSE) results->put(argVar, new cli::Value(true)); diff --git a/modules/c++/coda-oss.ruleset b/modules/c++/coda-oss.ruleset new file mode 100644 index 0000000000..0da8c00a63 --- /dev/null +++ b/modules/c++/coda-oss.ruleset @@ -0,0 +1,699 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/modules/c++/coda-oss-lite.vcxproj b/modules/c++/coda-oss.vcxproj similarity index 77% rename from modules/c++/coda-oss-lite.vcxproj rename to modules/c++/coda-oss.vcxproj index 7165b8b151..b0c706116b 100644 --- a/modules/c++/coda-oss-lite.vcxproj +++ b/modules/c++/coda-oss.vcxproj @@ -31,6 +31,12 @@ + + + + + + @@ -43,12 +49,14 @@ + + @@ -164,6 +172,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -185,8 +224,6 @@ - - @@ -242,7 +279,6 @@ - @@ -271,9 +307,29 @@ + + + + + + + + + + + + + + + + + + + + @@ -284,6 +340,10 @@ + + + + @@ -338,6 +398,20 @@ + + + + + + + + + + + + + + @@ -411,6 +485,19 @@ + + + + + + + + + + + + + @@ -418,6 +505,7 @@ + @@ -445,7 +533,7 @@ {9997e895-5161-4ddf-8f3f-099894cb2f21} codaoss 10.0 - coda-oss-lite + coda-oss @@ -474,10 +562,11 @@ true true - AllRules.ruleset + coda-oss.ruleset false + coda-oss.ruleset @@ -485,13 +574,12 @@ true _DEBUG;_LIB;%(PreprocessorDefinitions);CODA_OSS_EXPORTS;CODA_OSS_DLL;MT_DEFAULT_PINNING=0;RE_ENABLE_STD_REGEX=1 pch.h - cli\include\;coda_oss\include;config\include\;except\include\;gsl\include\;hdf5.lite\include\;io\include\;logging\include\;math\include\;math.linear\include\;math.poly\include\;mem\include\;mt\include\;plugin\include\;polygon\include\;re\include\;sio.lite\include\;std\include\;str\include\;sys\include\;tiff\include;types\include\;units\include\;zip\include\;$(SolutionDir)out\install\$(Platform)-$(Configuration)\include\ + cli\include\;coda_oss\include;config\include\;dbi\include\;except\include\;gsl\include\;hdf5.lite\include\;io\include\;logging\include\;math\include\;math.linear\include\;math.poly\include\;mem\include\;mt\include\;net\include\;net.ssl\include\;plugin\include\;polygon\include\;re\include\;sio.lite\include\;std\include\;str\include\;sys\include\;tiff\include;types\include\;unique\include\;units\include\;xml.lite\include\;zip\include\;$(ProjectDir)..\..\out\install\$(Platform)-$(Configuration)\include\;$(SolutionDir)out\install\$(Platform)-$(Configuration)\include\;$(SolutionDir)\target-$(Configuration)\installwindows-latestCMake-Github\include\ Use pch.h true Guard ProgramDatabase - true true true true @@ -499,13 +587,14 @@ /Zc:__cplusplus %(AdditionalOptions) true AdvancedVectorExtensions2 + true true - $(SolutionDir)\out\install\$(Platform)-$(Configuration)\lib\ - hdf5-c++.lib;z.lib;minizip.lib;%(AdditionalDependencies) + $(ProjectDir)..\..\out\install\$(Platform)-$(Configuration)\lib\;$(SolutionDir)\out\install\$(Platform)-$(Configuration)\lib\;$(SolutionDir)\target-$(Configuration)\installwindows-latestCMake-Github\lib\ + hdf5-c++.lib;z.lib;minizip.lib;xerces-c.lib;rpcrt4.lib;%(AdditionalDependencies) @@ -516,12 +605,11 @@ true NDEBUG;_LIB;%(PreprocessorDefinitions);CODA_OSS_EXPORTS;CODA_OSS_DLL;MT_DEFAULT_PINNING=0;RE_ENABLE_STD_REGEX=1 pch.h - cli\include\;coda_oss\include;config\include\;except\include\;gsl\include\;hdf5.lite\include\;io\include\;logging\include\;math\include\;math.linear\include\;math.poly\include\;mem\include\;mt\include\;plugin\include\;polygon\include\;re\include\;sio.lite\include\;std\include\;str\include\;sys\include\;tiff\include;types\include\;units\include\;zip\include\;$(SolutionDir)out\install\$(Platform)-$(Configuration)\include\ + cli\include\;coda_oss\include;config\include\;dbi\include\;except\include\;gsl\include\;hdf5.lite\include\;io\include\;logging\include\;math\include\;math.linear\include\;math.poly\include\;mem\include\;mt\include\;net\include\;net.ssl\include\;plugin\include\;polygon\include\;re\include\;sio.lite\include\;std\include\;str\include\;sys\include\;tiff\include;types\include\;unique\include\;units\include\;xml.lite\include\;zip\include\;$(ProjectDir)..\..\out\install\$(Platform)-$(Configuration)\include\;$(SolutionDir)out\install\$(Platform)-$(Configuration)\include\;$(SolutionDir)\target-$(Configuration)\installwindows-latestCMake-Github\include\ Use pch.h true Guard - true true true true @@ -535,8 +623,8 @@ true true true - $(SolutionDir)\out\install\$(Platform)-$(Configuration)\lib\ - hdf5-c++.lib;z.lib;minizip.lib;%(AdditionalDependencies) + $(ProjectDir)..\..\out\install\$(Platform)-$(Configuration)\lib\;$(SolutionDir)\out\install\$(Platform)-$(Configuration)\lib\;$(SolutionDir)\target-$(Configuration)\installwindows-latestCMake-Github\lib\ + hdf5-c++.lib;z.lib;minizip.lib;xerces-c.lib;rpcrt4.lib;%(AdditionalDependencies) diff --git a/modules/c++/coda-oss-lite.vcxproj.filters b/modules/c++/coda-oss.vcxproj.filters similarity index 79% rename from modules/c++/coda-oss-lite.vcxproj.filters rename to modules/c++/coda-oss.vcxproj.filters index e1e9675be9..2b1f013080 100644 --- a/modules/c++/coda-oss-lite.vcxproj.filters +++ b/modules/c++/coda-oss.vcxproj.filters @@ -219,9 +219,6 @@ sys - - sys - sys @@ -720,12 +717,6 @@ mem - - std - - - std - std @@ -795,6 +786,183 @@ zip + + xml.lite + + + xml.lite + + + xml.lite + + + xml.lite + + + xml.lite + + + xml.lite + + + xml.lite + + + xml.lite + + + xml.lite + + + xml.lite + + + xml.lite + + + xml.lite + + + xml.lite + + + xml.lite + + + xml.lite + + + xml.lite + + + xml.lite + + + dbi + + + dbi + + + dbi + + + dbi + + + dbi + + + dbi + + + net + + + net + + + net + + + net + + + net + + + net + + + net + + + net + + + net + + + net + + + net + + + net + + + net + + + net + + + net + + + net + + + net + + + net + + + net + + + net + + + net + + + net + + + net + + + net + + + net + + + net + + + net + + + net.ssl + + + net.ssl + + + net.ssl + + + net.ssl + + + unique + + + unique + + + hdf5.lite + + + xml.lite + + + hdf5.lite + @@ -1167,6 +1335,99 @@ zip + + xml.lite + + + xml.lite + + + xml.lite + + + xml.lite + + + xml.lite + + + xml.lite + + + xml.lite + + + xml.lite + + + xml.lite + + + xml.lite + + + xml.lite + + + xml.lite + + + dbi + + + dbi + + + dbi + + + dbi + + + net + + + net + + + net + + + net + + + net + + + net + + + net + + + net + + + net + + + net + + + net + + + net + + + net.ssl + + + net.ssl + + + unique + @@ -1247,6 +1508,21 @@ {a2682912-3963-489a-9cf0-c5224b27eb84} + + {1bb6daf3-40dd-44d8-8680-0e77e2c3bd17} + + + {13c98009-f1f9-4297-a2b3-bde23f3bea55} + + + {6575592b-9b28-49eb-be76-27f40825475e} + + + {21ddb4b6-54a2-4618-81ed-4fbbf37b30de} + + + {79aa73a7-ed0d-4826-b7ed-c8d91d96998a} + @@ -1309,5 +1585,6 @@ std + \ No newline at end of file diff --git a/modules/c++/dbi/source/DatabaseClientFactory.cpp b/modules/c++/dbi/source/DatabaseClientFactory.cpp index 170d405131..cd1b387335 100644 --- a/modules/c++/dbi/source/DatabaseClientFactory.cpp +++ b/modules/c++/dbi/source/DatabaseClientFactory.cpp @@ -47,7 +47,7 @@ dbi::DatabaseConnection * dbi::DatabaseClientFactory::create(const std::string& const std::string& host, unsigned int port) { - dbi::DatabaseConnection * connection = NULL; + dbi::DatabaseConnection * connection = nullptr; # if defined(USE_PGSQL) if (mType == dbi::PGSQL) { diff --git a/modules/c++/dbi/source/OracleConnection.cpp b/modules/c++/dbi/source/OracleConnection.cpp index 4f09abaa36..66ff79cb50 100644 --- a/modules/c++/dbi/source/OracleConnection.cpp +++ b/modules/c++/dbi/source/OracleConnection.cpp @@ -30,8 +30,8 @@ dbi::OracleConnection::OracleConnection() { - mEnvHandle = NULL; - mErrorHandle = NULL; + mEnvHandle = nullptr; + mErrorHandle = nullptr; (void) OCIInitialize((ub4) OCI_DEFAULT, (dvoid *)0, (dvoid * (*)(dvoid *, size_t)) 0, (dvoid * (*)(dvoid *, dvoid *, size_t))0, @@ -118,7 +118,7 @@ dbi::pResultSet dbi::OracleConnection::query(const std::string& q) (ub4)countq.length(), (ub4) OCI_NTV_SYNTAX, (ub4) OCI_DEFAULT); OCIStmtExecute(mContextHandle, countHandle, mErrorHandle, (ub4)val, (ub4)0, (CONST OCISnapshot *) NULL, (OCISnapshot *) NULL, OCI_DEFAULT); - OCIDefine * defineHandle = NULL; + OCIDefine * defineHandle = nullptr; OCIDefineByPos(countHandle, &defineHandle, mErrorHandle, 1, &rowCount, sizeof(rowCount), SQLT_UIN, 0, 0, 0, OCI_DEFAULT); OCIStmtFetch(countHandle, mErrorHandle, 1, OCI_FETCH_NEXT, OCI_DEFAULT); @@ -150,7 +150,7 @@ dbi::Row dbi::OracleResultSet::fetchRow() dbi::Row row; ub4 count = 0; sword result = OCIAttrGet(mSQLHandle, OCI_HTYPE_STMT, - &count, NULL, OCI_ATTR_PARAM_COUNT, mErrorHandle); + &count, nullptr, OCI_ATTR_PARAM_COUNT, mErrorHandle); Column * fields = new Column[count]; if (result == OCI_SUCCESS) { @@ -160,9 +160,9 @@ dbi::Row dbi::OracleResultSet::fetchRow() fields[i].type = 0; fields[i].extType = SQLT_STR; fields[i].fieldSize = 0; - fields[i].value = NULL; + fields[i].value = nullptr; - OCIParam* param_handle = NULL; + OCIParam* param_handle = nullptr; ub4 name_len = 0; result = OCIParamGet(mSQLHandle, OCI_HTYPE_STMT, @@ -180,14 +180,14 @@ dbi::Row dbi::OracleResultSet::fetchRow() if (result == OCI_SUCCESS) { result = OCIAttrGet(param_handle, OCI_DTYPE_PARAM, - &fields[i].type, NULL, OCI_ATTR_DATA_TYPE, + &fields[i].type, nullptr, OCI_ATTR_DATA_TYPE, mErrorHandle); } if (result == OCI_SUCCESS) { result = OCIAttrGet(param_handle, OCI_DTYPE_PARAM, - &fields[i].fieldSize, NULL, OCI_ATTR_DATA_SIZE, + &fields[i].fieldSize, nullptr, OCI_ATTR_DATA_SIZE, mErrorHandle); } @@ -210,7 +210,7 @@ dbi::Row dbi::OracleResultSet::fetchRow() int indp = -1; // This means that NULL values will not cause an error fields[i].value = new char[fields[i].fieldSize]; memset(fields[i].value, '\0', fields[i].fieldSize); - OCIDefine* defineHandle = NULL; + OCIDefine* defineHandle = nullptr; result = OCIDefineByPos(mSQLHandle, &defineHandle, mErrorHandle, i + 1, fields[i].value, fieldSize, fields[i].extType, &indp, 0, 0, OCI_DEFAULT); diff --git a/modules/c++/except/source/Backtrace.cpp b/modules/c++/except/source/Backtrace.cpp index a6a326415e..9adb564def 100644 --- a/modules/c++/except/source/Backtrace.cpp +++ b/modules/c++/except/source/Backtrace.cpp @@ -111,7 +111,7 @@ class SymInitialize_RAII final bool result; SymInitialize_RAII(HANDLE process) : process_(process) { - result = SymInitialize(process_, NULL, TRUE) == TRUE ? true : false; // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nf-dbghelp-syminitialize + result = SymInitialize(process_, nullptr, TRUE) == TRUE ? true : false; // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nf-dbghelp-syminitialize } ~SymInitialize_RAII() @@ -134,7 +134,7 @@ static std::string getBacktrace_(bool& supported, std::vector& symb } PVOID stack[100]; - const auto frames = CaptureStackBackTrace(0, 100, stack, NULL); + const auto frames = CaptureStackBackTrace(0, 100, stack, nullptr); auto symbol = reinterpret_cast(calloc(sizeof(SYMBOL_INFO) + 256 * sizeof(char), 1)); if (symbol == nullptr) { @@ -147,7 +147,7 @@ static std::string getBacktrace_(bool& supported, std::vector& symb for (unsigned int i = 0; i < frames; i++) { const auto address = reinterpret_cast(stack[i]); - const auto result = SymFromAddr(process, address, 0, symbol) == TRUE ? true : false; + const auto result = SymFromAddr(process, address, nullptr, symbol) == TRUE ? true : false; if (!result) { continue; diff --git a/modules/c++/framework.h b/modules/c++/framework.h index ced33cae73..1cab8338a0 100644 --- a/modules/c++/framework.h +++ b/modules/c++/framework.h @@ -5,14 +5,18 @@ #pragma warning(disable: 4514) // '...': unreferenced inline function has been removed #pragma warning(disable: 4365) // '...': conversion from '...' to '...', signed/unsigned mismatch #pragma warning(disable: 5204) // '...': class has virtual functions, but its trivial destructor is not virtual; instances of objects derived from this class may not be destructed correctly +#pragma warning(disable: 5105) // macro expansion producing '...' has undefined behavior #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers #define NOMINMAX // no min()/max() macros -#pragma warning(push) -#pragma warning(disable: 5105) // macro expansion producing '...' has undefined behavior #include + +#define _WINSOCK_DEPRECATED_NO_WARNINGS // '...': Use getaddrinfo() or GetAddrInfoW() instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings #include -#include -#pragma warning(pop) +#include #pragma comment(lib, "Ws2_32") + +#include + #pragma warning(pop) + diff --git a/modules/c++/gsl/include/gsl/gsl.h b/modules/c++/gsl/include/gsl/gsl.h index bd7b33a097..4563274f4f 100644 --- a/modules/c++/gsl/include/gsl/gsl.h +++ b/modules/c++/gsl/include/gsl/gsl.h @@ -40,6 +40,7 @@ #pragma warning(disable: 5027) // '...' : move assignment operator was implicitly defined as deleted #pragma warning(disable: 26487) // Don 't return a pointer '...' that may be invalid (lifetime.4). #pragma warning(disable: 4814) // '...': in C++14 '...' will not imply '...'; consider explicitly specifying '...' + #pragma warning(disable: 26823) // Dereferencing a possibly null pointer '...' (lifetime.1). #endif #include "gsl/gsl" diff --git a/modules/c++/hdf5.lite/include/hdf5/lite/H5_.h b/modules/c++/hdf5.lite/include/hdf5/lite/H5_.h new file mode 100644 index 0000000000..74ebc436cb --- /dev/null +++ b/modules/c++/hdf5.lite/include/hdf5/lite/H5_.h @@ -0,0 +1,69 @@ +/* ========================================================================= + * This file is part of hdf5.lite-c++ + * ========================================================================= + * + * (C) Copyright 2022, Maxar Technologies, Inc. + * + * hdf5.lite-c++ is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; If not, + * see . + * + */ + +#pragma once +#ifndef CODA_OSS_hdf5_lite_H5__h_INCLUDED_ +#define CODA_OSS_hdf5_lite_H5__h_INCLUDED_ + +#include "config/compiler_extensions.h" + +CODA_OSS_disable_warning_system_header_push +#if _MSC_VER +#pragma warning(disable: 26493) // Don't use C-style casts (type.4). +#pragma warning(disable: 26494) // Variable '...' is uninitialized. Always initialize an object (type.5). +#pragma warning(disable: 26451) // Arithmetic overflow: Using operator '...' on a 4 byte value and then casting the result to a 8 byte value. Cast the value to the wider type before calling operator '...' to avoid overflow (io.2). +#pragma warning(disable: 26814) // The const variable '...' can be computed at compile-time. Consider using constexpr (con.5). +#pragma warning(disable: 26447) // The function is declared '...' but calls function '...' which may throw exceptions (f.6). +#pragma warning(disable: 26455) // Default constructor should not throw. Declare it '...' (f.6). +#pragma warning(disable: 26440) // Function '...' can be declared '...' (f.6). +#pragma warning(disable: 26496) // The variable '...' does not change after construction, mark it as const (con.4). +#pragma warning(disable: 26462) // The value pointed to by '...' is assigned only once, mark it as a pointer to const (con.4). +#pragma warning(disable: 26435) // Function '...' should specify exactly one of '...', '...', or '...' (c.128). +#pragma warning(disable: 26433) // Function '...' should be marked with '...' (c.128). +#pragma warning(disable: 26497) // You can attempt to make '...' constexpr unless it contains any undefined behavior (f.4). +#pragma warning(disable: 26433) // Function '...' should be marked with '...' (c.128). +#pragma warning(disable: 26456) // Operator '...' hides a non-virtual operator '...' (c.128). +#pragma warning(disable: 26446) // Prefer to use gsl::at() instead of unchecked subscript operator (bounds.4). +#pragma warning(disable: 26477) // Use '...' rather than 0 or NULL(es .47). +#pragma warning(disable: 26457) // (void) should not be used to ignore return values, use '...' instead (es.48). +#pragma warning(disable: 26813) // Use '...' to check if a flag is set. +#else +CODA_OSS_disable_warning(-Wshadow) +CODA_OSS_disable_warning(-Wsuggest-override) +CODA_OSS_disable_warning(-Wzero-as-null-pointer-constant) +#endif + +// see https://docs.hdfgroup.org/archive/support/HDF5/doc1.8/cpplus_RM/readdata_8cpp-example.html +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +CODA_OSS_disable_warning_pop + +#endif // CODA_OSS_hdf5_lite_H5__h_INCLUDED_ diff --git a/modules/c++/hdf5.lite/include/hdf5/lite/highfive.h b/modules/c++/hdf5.lite/include/hdf5/lite/highfive.h index 99f9f0d080..fb276e681c 100644 --- a/modules/c++/hdf5.lite/include/hdf5/lite/highfive.h +++ b/modules/c++/hdf5.lite/include/hdf5/lite/highfive.h @@ -33,9 +33,7 @@ #include #include -#include "highfive/H5Easy.hpp" -#include "highfive/H5DataSet.hpp" - +#include "H5_.h" #include "SpanRC.h" namespace hdf5 diff --git a/modules/c++/include/TestCase.h b/modules/c++/include/TestCase.h index a068260e0d..a433140047 100644 --- a/modules/c++/include/TestCase.h +++ b/modules/c++/include/TestCase.h @@ -119,7 +119,8 @@ inline void assert_almost_eq_eps(const TX1& X1, const TX2& X2, const TEPS& EPS, const std::string& testName, const char* file, const char* func, int line) { const auto abs_difference = std::abs(X1 - X2); - if (abs_difference > EPS || IS_NAN(abs_difference)) + using abs_difference_t = decltype(abs_difference); + if (abs_difference > static_cast(EPS) || IS_NAN(abs_difference)) { diePrintf_("%s (%s,%s,%d): FAILED: Recv'd %s, Expected %s\n", testName, file, func, line, X1, X2); } diff --git a/modules/c++/io/include/io/PipeStream.h b/modules/c++/io/include/io/PipeStream.h index 0a6b910355..33dc707360 100644 --- a/modules/c++/io/include/io/PipeStream.h +++ b/modules/c++/io/include/io/PipeStream.h @@ -23,7 +23,7 @@ #ifndef __IO_PIPE_STREAM_H__ #define __IO_PIPE_STREAM_H__ -#include +#include #include #include diff --git a/modules/c++/io/include/io/Serializable.h b/modules/c++/io/include/io/Serializable.h index 4fb3978b0f..e6d2363ae1 100644 --- a/modules/c++/io/include/io/Serializable.h +++ b/modules/c++/io/include/io/Serializable.h @@ -49,7 +49,7 @@ namespace io struct Serializable { Serializable() = default; - virtual ~Serializable() = default; + virtual ~Serializable() noexcept(false) {} /*! * Transfer this object into a byte stream diff --git a/modules/c++/io/source/FileInputStreamOS.cpp b/modules/c++/io/source/FileInputStreamOS.cpp index a8340b2a14..8ad36f1472 100644 --- a/modules/c++/io/source/FileInputStreamOS.cpp +++ b/modules/c++/io/source/FileInputStreamOS.cpp @@ -39,7 +39,7 @@ sys::Off_T io::FileInputStreamOS::available() sys::Off_T until = mFile.getCurrentOffset(); mFile.seekTo(where, sys::File::FROM_START); - return (until - where); + return until - where; } @@ -49,8 +49,8 @@ sys::SSize_T io::FileInputStreamOS::readImpl(void* buffer, size_t len) sys::Off_T avail = available(); if (!avail) return io::InputStream::IS_EOF; - if (len > (sys::Size_T)avail) - len = (sys::Size_T)avail; + if (len > static_cast(avail)) + len = static_cast(avail); mFile.readInto(buffer, len); return static_cast(len); diff --git a/modules/c++/io/source/InputStream.cpp b/modules/c++/io/source/InputStream.cpp index 3fd81e2f6c..e39ac48a6b 100644 --- a/modules/c++/io/source/InputStream.cpp +++ b/modules/c++/io/source/InputStream.cpp @@ -102,6 +102,6 @@ sys::SSize_T InputStream::readln(sys::byte *cStr, const sys::Size_T strLenPlusNu if (*(cStr + i) == '\n') return i + 1; // Otherwise, append c; } - return (sys::SSize_T)i; + return static_cast(i); } } diff --git a/modules/c++/io/source/MMapInputStream.cpp b/modules/c++/io/source/MMapInputStream.cpp index 9818ffb043..d942ac2231 100644 --- a/modules/c++/io/source/MMapInputStream.cpp +++ b/modules/c++/io/source/MMapInputStream.cpp @@ -38,7 +38,7 @@ void io::MMapInputStream::close() { _unmap(); fclose(mFile); - mFile = NULL; + mFile = nullptr; } void io::MMapInputStream::_map() @@ -50,7 +50,7 @@ void io::MMapInputStream::_unmap() { // std::cout << "Unmapping file... "; mOs.unmapFile(mData, mLength); - mData = NULL; + mData = nullptr; // std::cout << "done!" << std::endl; } diff --git a/modules/c++/io/source/PipeStream.cpp b/modules/c++/io/source/PipeStream.cpp index d256583800..a807299bd4 100644 --- a/modules/c++/io/source/PipeStream.cpp +++ b/modules/c++/io/source/PipeStream.cpp @@ -63,7 +63,7 @@ sys::SSize_T io::PipeStream::readln(sys::byte *cStr, while (!feof(pipe)) { // get the next line or return null - if (fgets(cStr, static_cast(strLenPlusNullByte), pipe) != NULL) + if (fgets(cStr, static_cast(strLenPlusNullByte), pipe) != nullptr) { return gsl::narrow(strlen(cStr)); } diff --git a/modules/c++/io/source/StandardStreams.cpp b/modules/c++/io/source/StandardStreams.cpp index 02f6a61de7..2323613990 100644 --- a/modules/c++/io/source/StandardStreams.cpp +++ b/modules/c++/io/source/StandardStreams.cpp @@ -27,7 +27,7 @@ _STDOUT_DEFINE_MUTEX_SEMICOLON_ void io::StandardOutStream::write(const void* buffer, sys::Size_T len) { _STDSTREAM_BEGIN_CS_SEMICOLON_ - std::cout.write((const char*)buffer, len); + std::cout.write(static_cast(buffer), len); _STDSTREAM_END_CS_SEMICOLON_ //int returnVal = fwrite(b, len, len, stdout); if (!std::cout.good()) @@ -47,7 +47,7 @@ void io::StandardOutStream::flush() void io::StandardErrStream::write(const void* buffer, sys::Size_T len) { _STDSTREAM_BEGIN_CS_SEMICOLON_ - std::cerr.write((const char*)buffer, len); + std::cerr.write(static_cast(buffer), len); //int returnVal = fwrite(b, len, len, stderr); _STDSTREAM_END_CS_SEMICOLON_ if (!std::cerr.good()) diff --git a/modules/c++/io/source/StreamSplitter.cpp b/modules/c++/io/source/StreamSplitter.cpp index b922063838..57d6a2f603 100644 --- a/modules/c++/io/source/StreamSplitter.cpp +++ b/modules/c++/io/source/StreamSplitter.cpp @@ -40,7 +40,7 @@ StreamSplitter::StreamSplitter(io::InputStream& inputStream, mNumDelimitersProcessed(0), mBufferStorage(bufferSize), mBufferCapacity(mBufferStorage.size()), - mBuffer(mBufferStorage.empty() ? NULL : &mBufferStorage[0]), + mBuffer(mBufferStorage.empty() ? nullptr : &mBufferStorage[0]), mInputStream(inputStream), mStreamEmpty(false) { diff --git a/modules/c++/logging/unittests/test_exception_logger.cpp b/modules/c++/logging/unittests/test_exception_logger.cpp index f85d8cc54a..57016a0de9 100644 --- a/modules/c++/logging/unittests/test_exception_logger.cpp +++ b/modules/c++/logging/unittests/test_exception_logger.cpp @@ -43,7 +43,7 @@ class RunNothing final : public sys::Runnable } public: - RunNothing(size_t& c, logging::ExceptionLogger* el, bool getBacktrace=false) : counter(c), exLog(el), getBacktrace(getBacktrace) {} + RunNothing(size_t& c, logging::ExceptionLogger* el, bool getBacktrace_=false) : counter(c), exLog(el), getBacktrace(getBacktrace_) {} virtual void run() override { diff --git a/modules/c++/math.linear/include/math/linear/MatrixMxN.h b/modules/c++/math.linear/include/math/linear/MatrixMxN.h index 39006e1348..ef091020cf 100644 --- a/modules/c++/math.linear/include/math/linear/MatrixMxN.h +++ b/modules/c++/math.linear/include/math/linear/MatrixMxN.h @@ -1298,7 +1298,7 @@ template template inline MatrixMxN<_ND, _ND, _T> inverseLU(const MatrixMxN<_ND, _ND, _T>& mx) { - MatrixMxN<_ND, _ND, _T> a((_T)0); + MatrixMxN<_ND, _ND, _T> a(static_cast<_T>(0)); // Identity for (size_t i = 0; i < _ND; i++) diff --git a/modules/c++/math/include/math/Round.h b/modules/c++/math/include/math/Round.h index d141510040..f3df72c1f7 100644 --- a/modules/c++/math/include/math/Round.h +++ b/modules/c++/math/include/math/Round.h @@ -36,9 +36,11 @@ namespace math * \param value A number to evaluate * \return The 'fixed' number */ -template inline T fix(T value) +template inline T fix(T value_) { - return (value > 0.0 ? std::floor(value) : std::ceil(value)); + const double value = value_; + const auto result = value > 0.0 ? std::floor(value) : std::ceil(value); + return static_cast(result); } /*! @@ -48,9 +50,11 @@ template inline T fix(T value) * \param value A number to evaluate * \return The rounded number */ -template inline T round(T value) +template inline T round(T value_) { - return static_cast(value > 0.0 ? std::floor(value + 0.5) : std::ceil(value - 0.5)); + const double value = value_; + const auto result = value > 0.0 ? std::floor(value + 0.5) : std::ceil(value - 0.5); + return static_cast(result); } /*! @@ -60,7 +64,7 @@ template inline T round(T value) * \param fractionalDigits Number of fractional digits to round to * \return The rounded number */ -template inline T round(T value, size_t fractionalDigits) +template inline T round(T value_, size_t fractionalDigits) { double power10 = 1.0; for (size_t i = 0; i < fractionalDigits; ++i) @@ -68,8 +72,10 @@ template inline T round(T value, size_t fractionalDigits) power10 *= 10.0; } - return static_cast(value > 0.0 ? std::floor(value * power10 + 0.5) / power10 - : std::ceil(value * power10 - 0.5) / power10); + const double value = value_; + const auto result = value > 0.0 ? std::floor(value * power10 + 0.5) / power10 + : std::ceil(value * power10 - 0.5) / power10; + return static_cast(result); } /*! diff --git a/modules/c++/math/source/Bessel.cpp b/modules/c++/math/source/Bessel.cpp index 5c4911c074..b84f4fb8ac 100644 --- a/modules/c++/math/source/Bessel.cpp +++ b/modules/c++/math/source/Bessel.cpp @@ -22,6 +22,7 @@ #include #include +#include #include @@ -147,12 +148,12 @@ double besselIOrderN(size_t order, double x) double bi = 1.0; //Downward recurrence from even n - for (size_t jj = 2 * (order + int(std::sqrt(ACC * order))); jj > 0; jj--) + for (size_t jj = 2 * (order + int(std::sqrt(ACC * static_cast(order)))); jj > 0; jj--) { - double bim = bip + (jj * tox * bi); + double bim = bip + (static_cast(jj) * tox * bi); bip = bi; bi = bim; - std::frexp(bi, &k); + std::ignore = std::frexp(bi, &k); //Renormalize to prevent overflow if (k > IEXP) diff --git a/modules/c++/mem/include/mem/ScratchMemory.h b/modules/c++/mem/include/mem/ScratchMemory.h index 1a89da787e..57724f0a7e 100644 --- a/modules/c++/mem/include/mem/ScratchMemory.h +++ b/modules/c++/mem/include/mem/ScratchMemory.h @@ -50,8 +50,7 @@ namespace mem class CODA_OSS_API ScratchMemory { public: - //! Default constructor - ScratchMemory(); + ScratchMemory() = default; /*! * \brief Reserve a buffer segment within this scratch memory buffer. @@ -183,8 +182,8 @@ class CODA_OSS_API ScratchMemory std::set mConnectedKeys; BufferView mBuffer; - size_t mNumBytesNeeded; - size_t mOffset; + size_t mNumBytesNeeded=0; + size_t mOffset=0; }; } diff --git a/modules/c++/mem/include/mem/ScratchMemory.hpp b/modules/c++/mem/include/mem/ScratchMemory.hpp index 0682c5d830..45c6fcd261 100644 --- a/modules/c++/mem/include/mem/ScratchMemory.hpp +++ b/modules/c++/mem/include/mem/ScratchMemory.hpp @@ -38,7 +38,7 @@ inline void ScratchMemory::put(const std::string& key, size_t alignment) { // invalidate buffer (setup must be called before any subsequent get call) - mBuffer.data = NULL; + mBuffer.data = nullptr; size_t segmentOffset = mOffset; diff --git a/modules/c++/mem/include/mem/SharedPtrCpp11.h b/modules/c++/mem/include/mem/SharedPtrCpp11.h index 619d7b045e..f6832fbcef 100644 --- a/modules/c++/mem/include/mem/SharedPtrCpp11.h +++ b/modules/c++/mem/include/mem/SharedPtrCpp11.h @@ -27,8 +27,6 @@ #include #include -#include "sys/CPlusPlus.h" - namespace mem { // Pretty much give-up on mem::SharedPtr as it's too hard to get something that will diff --git a/modules/c++/mem/source/ScratchMemory.cpp b/modules/c++/mem/source/ScratchMemory.cpp index bcedacaf0f..a3f162daa0 100644 --- a/modules/c++/mem/source/ScratchMemory.cpp +++ b/modules/c++/mem/source/ScratchMemory.cpp @@ -25,20 +25,15 @@ namespace mem { -ScratchMemory::ScratchMemory() : - mNumBytesNeeded(0), - mOffset(0) -{ -} -ScratchMemory::Segment::Segment(size_t numBytes, - size_t numBuffers, - size_t alignment, - size_t offset) : - numBytes(numBytes), - numBuffers(numBuffers), - alignment(alignment), - offset(offset) +ScratchMemory::Segment::Segment(size_t numBytes_, + size_t numBuffers_, + size_t alignment_, + size_t offset_) : + numBytes(numBytes_), + numBuffers(numBuffers_), + alignment(alignment_), + offset(offset_) { } @@ -185,7 +180,7 @@ void ScratchMemory::setup(const BufferView& scratchBuffer) throw except::Exception(Ctxt( "Buffer has insufficient space for scratch memory")); } - if (scratchBuffer.data == NULL) + if (scratchBuffer.data == nullptr) { throw except::Exception(Ctxt( "Invalid external buffer was provided")); @@ -214,7 +209,7 @@ const ScratchMemory::Segment& ScratchMemory::lookupSegment( const std::string& key, size_t indexBuffer) const { - if (mBuffer.data == NULL) + if (mBuffer.data == nullptr) { std::ostringstream oss; oss << "Tried to get scratch memory for \"" << key diff --git a/modules/c++/mem/tests/ScratchVisualization.cpp b/modules/c++/mem/tests/ScratchVisualization.cpp index 2585f7473f..20974a659c 100644 --- a/modules/c++/mem/tests/ScratchVisualization.cpp +++ b/modules/c++/mem/tests/ScratchVisualization.cpp @@ -32,12 +32,12 @@ namespace { struct Operation { - Operation(const std::string& op, - const std::string& name, - const size_t bytes) : - op(op), - name(name), - bytes(bytes) + Operation(const std::string& op_, + const std::string& name_, + const size_t bytes_) : + op(op_), + name(name_), + bytes(bytes_) { } diff --git a/modules/c++/mt/include/mt/AbstractThreadPool.h b/modules/c++/mt/include/mt/AbstractThreadPool.h index c72e9bd32a..92d3de272b 100644 --- a/modules/c++/mt/include/mt/AbstractThreadPool.h +++ b/modules/c++/mt/include/mt/AbstractThreadPool.h @@ -66,6 +66,11 @@ template class AbstractThreadPool join();//destroy(); } + AbstractThreadPool(const AbstractThreadPool&) = delete; + AbstractThreadPool& operator=(const AbstractThreadPool&) = delete; + AbstractThreadPool(AbstractThreadPool&&) = delete; + AbstractThreadPool& operator=(AbstractThreadPool&&) = delete; + /*! * Intialize and start each thread running. * Typically the caller will either join at this point diff --git a/modules/c++/mt/include/mt/WorkerThread.h b/modules/c++/mt/include/mt/WorkerThread.h index 4e865d0fff..2a2e204684 100644 --- a/modules/c++/mt/include/mt/WorkerThread.h +++ b/modules/c++/mt/include/mt/WorkerThread.h @@ -52,8 +52,12 @@ template class WorkerThread : public sys::Thread /*! * Virtual destructor */ - virtual ~WorkerThread() - {} + virtual ~WorkerThread() = default; + + WorkerThread(const WorkerThread&) = delete; + WorkerThread& operator=(const WorkerThread&) = delete; + WorkerThread(WorkerThread&&) = delete; + WorkerThread& operator=(WorkerThread&&) = delete; virtual void initialize() {} diff --git a/modules/c++/mt/source/GenerationThreadPool.cpp b/modules/c++/mt/source/GenerationThreadPool.cpp index a3776c3e84..651756573c 100644 --- a/modules/c++/mt/source/GenerationThreadPool.cpp +++ b/modules/c++/mt/source/GenerationThreadPool.cpp @@ -29,7 +29,7 @@ mt::TiedRequestHandler::~TiedRequestHandler() if (mAffinityInit) { delete mAffinityInit; - mAffinityInit = NULL; + mAffinityInit = nullptr; } } @@ -50,7 +50,7 @@ void mt::TiedRequestHandler::run() while (true) { // Pull a runnable off the queue - sys::Runnable *handler = NULL; + sys::Runnable *handler = nullptr; mRequestQueue->dequeue(handler); if (!handler) return; @@ -93,7 +93,7 @@ void mt::GenerationThreadPool::waitGroup() /*void mt::GenerationThreadPool::shutdown() { size_t size = mPool.size(); - static sys::Runnable* shutdown = NULL; + static sys::Runnable* shutdown = nullptr; for(unsigned int i=0; i < size; i++) { addRequest(shutdown); diff --git a/modules/c++/mt/source/GenericRequestHandler.cpp b/modules/c++/mt/source/GenericRequestHandler.cpp index 015a77f91a..9fe488668c 100644 --- a/modules/c++/mt/source/GenericRequestHandler.cpp +++ b/modules/c++/mt/source/GenericRequestHandler.cpp @@ -29,7 +29,7 @@ void mt::GenericRequestHandler::run() while (true) { // Pull a runnable off the queue - sys::Runnable* handler = NULL; + sys::Runnable* handler = nullptr; mRequest->dequeue(handler); if (!handler) { diff --git a/modules/c++/mt/source/ThreadGroup.cpp b/modules/c++/mt/source/ThreadGroup.cpp index 85bf054c58..0a3616a39f 100644 --- a/modules/c++/mt/source/ThreadGroup.cpp +++ b/modules/c++/mt/source/ThreadGroup.cpp @@ -34,7 +34,7 @@ namespace mt ThreadGroup::ThreadGroup(bool pinToCPU) : - mAffinityInit(pinToCPU ? new CPUAffinityInitializer() : NULL), + mAffinityInit(pinToCPU ? new CPUAffinityInitializer() : nullptr), mLastJoined(0) { } @@ -163,7 +163,7 @@ void ThreadGroup::ThreadGroupRunnable::run() bool ThreadGroup::isPinToCPUEnabled() const { - return mAffinityInit.get() != NULL; + return mAffinityInit.get() != nullptr; } bool ThreadGroup::getDefaultPinToCPU() diff --git a/modules/c++/net.ssl/source/SSLConnection.cpp b/modules/c++/net.ssl/source/SSLConnection.cpp index e0f37d1e70..75c7f5e031 100644 --- a/modules/c++/net.ssl/source/SSLConnection.cpp +++ b/modules/c++/net.ssl/source/SSLConnection.cpp @@ -30,12 +30,12 @@ net::ssl::SSLConnection::SSLConnection(std::unique_ptr&& socket, const std::string& host) : NetConnection(std::move(socket)), mServerAuthentication(serverAuth) { - mSSL = NULL; + mSSL = nullptr; mBioErr = BIO_new_fp(stderr, BIO_NOCLOSE); mSSL = SSL_new(ctx); - if (mSSL == NULL) + if (mSSL == nullptr) { throw net::ssl::SSLException(Ctxt(FmtX("SSL_new failed"))); } diff --git a/modules/c++/net.ssl/source/SSLConnectionClientFactory.cpp b/modules/c++/net.ssl/source/SSLConnectionClientFactory.cpp index c3cefdd410..5a9d441480 100644 --- a/modules/c++/net.ssl/source/SSLConnectionClientFactory.cpp +++ b/modules/c++/net.ssl/source/SSLConnectionClientFactory.cpp @@ -58,12 +58,12 @@ void net::ssl::SSLConnectionClientFactory::initializeContext() const SSL_METHOD *method = SSLv23_client_method(); #endif - if(method == NULL) + if(method == nullptr) { throw net::ssl::SSLException(Ctxt(FmtX("SSLv23_client_method failed"))); } mCtx = SSL_CTX_new(method); - if(mCtx == NULL) + if(mCtx == nullptr) { throw net::ssl::SSLException(Ctxt(FmtX("SSL_CTX_new failed"))); } diff --git a/modules/c++/net/include/net/NetConnectionServer.h b/modules/c++/net/include/net/NetConnectionServer.h index debc58d32c..e27a0d5432 100644 --- a/modules/c++/net/include/net/NetConnectionServer.h +++ b/modules/c++/net/include/net/NetConnectionServer.h @@ -56,9 +56,12 @@ class NetConnectionServer NetConnectionServer(); //! Destructor. - virtual ~NetConnectionServer() - { - } + virtual ~NetConnectionServer() = default; + + NetConnectionServer(const NetConnectionServer&) = delete; + NetConnectionServer& operator=(const NetConnectionServer&) = delete; + NetConnectionServer(NetConnectionServer&&) = default; + NetConnectionServer& operator=(NetConnectionServer&&) = default; /*! * Create a server on the port, with a backlog queue given in the diff --git a/modules/c++/net/include/net/PerRequestThreadAllocStrategy.h b/modules/c++/net/include/net/PerRequestThreadAllocStrategy.h index c02cb530bb..9568610471 100644 --- a/modules/c++/net/include/net/PerRequestThreadAllocStrategy.h +++ b/modules/c++/net/include/net/PerRequestThreadAllocStrategy.h @@ -61,8 +61,12 @@ class RequestHandlerThread : public sys::Thread {} //! Destructor - ~RequestHandlerThread() - {} + ~RequestHandlerThread() = default; + + RequestHandlerThread(const RequestHandlerThread&) = delete; + RequestHandlerThread& operator=(const RequestHandlerThread&) = delete; + RequestHandlerThread(RequestHandlerThread&&) = delete; + RequestHandlerThread& operator=(RequestHandlerThread&&) = delete; /*! * Overloaded run method for handling a connection. diff --git a/modules/c++/net/include/net/SocketsWin32.h b/modules/c++/net/include/net/SocketsWin32.h index b0490a7c3c..9e363c6488 100644 --- a/modules/c++/net/include/net/SocketsWin32.h +++ b/modules/c++/net/include/net/SocketsWin32.h @@ -20,20 +20,28 @@ * */ -#ifndef __NET_SOCKETS_WIN32_H__ -#define __NET_SOCKETS_WIN32_H__ #pragma once +#ifndef CODA_OSS_net_SocketsWin32_h_INCLUDED_ +#define CODA_OSS_net_SocketsWin32_h_INCLUDED_ #include +#include + +#ifndef _WINSOCK2API_ // already #include'd #undef BIGENDIAN // #define'd in +#define _WINSOCK_DEPRECATED_NO_WARNINGS // '...': Use getaddrinfo() or GetAddrInfoW() instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings #include #include -#include + +#endif // _WINSOCK2API_ #ifndef BIGENDIAN #error BIGENDIAN should be #defined! #endif +#include + + /*! * \file * \brief Handle winsock-level callss @@ -97,7 +105,7 @@ inline void Win32SocketInit() inited = true; WORD versionRequested = MAKEWORD(1, 1); WSADATA wsaData; - WSAStartup(versionRequested, &wsaData); + std::ignore = WSAStartup(versionRequested, &wsaData); atexit( net::Win32SocketDestroy ); } } @@ -109,5 +117,4 @@ inline void Win32SocketInit() } - -#endif +#endif // CODA_OSS_net_SocketsWin32_h_INCLUDED_ diff --git a/modules/c++/net/include/net/ThreadPoolAllocStrategy.h b/modules/c++/net/include/net/ThreadPoolAllocStrategy.h index 767e024503..2dc4b0509d 100644 --- a/modules/c++/net/include/net/ThreadPoolAllocStrategy.h +++ b/modules/c++/net/include/net/ThreadPoolAllocStrategy.h @@ -41,6 +41,11 @@ class ConnectionThread: public mt::WorkerThread delete mHandler; } + ConnectionThread(const ConnectionThread&) = delete; + ConnectionThread& operator=(const ConnectionThread&) = delete; + ConnectionThread(ConnectionThread&&) = delete; + ConnectionThread& operator=(ConnectionThread&&) = delete; + /*! * Do this in a loop forever. */ @@ -78,6 +83,11 @@ class ConnectionThreadPool: public mt::AbstractThreadPool delete mFactory; } + ConnectionThreadPool(const ConnectionThreadPool&) = delete; + ConnectionThreadPool& operator=(const ConnectionThreadPool&) = delete; + ConnectionThreadPool(ConnectionThreadPool&&) = delete; + ConnectionThreadPool& operator=(ConnectionThreadPool&&) = delete; + mt::WorkerThread* newWorker() override { return new ConnectionThread(&mRequestQueue, mFactory->create()); diff --git a/modules/c++/net/source/CurlHandle.cpp b/modules/c++/net/source/CurlHandle.cpp index 4840dc8eba..1b3554ccd6 100644 --- a/modules/c++/net/source/CurlHandle.cpp +++ b/modules/c++/net/source/CurlHandle.cpp @@ -31,7 +31,7 @@ namespace net CurlHandle::CurlHandle() : mHandle(curl_easy_init()) { - if (mHandle == NULL) + if (mHandle == nullptr) { throw except::Exception(Ctxt("curl_easy_init() failed")); } @@ -103,7 +103,7 @@ size_t CurlHandle::writeBetterCallback(char* data, size_t nmemb, std::string* writeData) { - if (writeData == NULL) + if (writeData == nullptr) { return 0; } diff --git a/modules/c++/net/source/NetConnectionServer.cpp b/modules/c++/net/source/NetConnectionServer.cpp index e6f4a4c59d..0bb479b621 100644 --- a/modules/c++/net/source/NetConnectionServer.cpp +++ b/modules/c++/net/source/NetConnectionServer.cpp @@ -58,7 +58,7 @@ net::NetConnection* net::NetConnectionServer::accept() void net::NetConnectionServer::initialize(net::RequestHandlerFactory* factory, net::AllocStrategy* newStrategy) { - std::unique_ptr tmp ((newStrategy == NULL) ? + std::unique_ptr tmp ((newStrategy == nullptr) ? new DefaultAllocStrategy() : newStrategy); tmp->setRequestHandlerFactory(factory); diff --git a/modules/c++/net/source/NetUtils.cpp b/modules/c++/net/source/NetUtils.cpp index 98c49d9a6d..5df324fe76 100644 --- a/modules/c++/net/source/NetUtils.cpp +++ b/modules/c++/net/source/NetUtils.cpp @@ -133,7 +133,7 @@ std::string net::unquote(std::string s) { std::string part = parts[i]; std::string hexStr = "0x" + part.substr(0, 2); - long val = strtol(hexStr.c_str(), NULL, 16); + long val = strtol(hexStr.c_str(), nullptr, 16); unquoted << (char) val; if (part.length() > 2) unquoted << part.substr(2); diff --git a/modules/c++/net/source/SocketAddress.cpp b/modules/c++/net/source/SocketAddress.cpp index e5dcf0494c..a6e4e0c9d8 100644 --- a/modules/c++/net/source/SocketAddress.cpp +++ b/modules/c++/net/source/SocketAddress.cpp @@ -20,6 +20,8 @@ * */ +#include + #ifdef _WIN32 #define _WINSOCK_DEPRECATED_NO_WARNINGS #endif @@ -69,7 +71,7 @@ void SocketAddress::setHost(const std::string& host) struct sockaddr saddr; int slen = sizeof(saddr); struct sockaddr_in *paddr = (struct sockaddr_in *)&saddr; - (void) WSAStringToAddress((LPSTR)host.c_str(), AF_INET, NULL, &saddr, &slen); + std::ignore = WSAStringToAddress((LPSTR)host.c_str(), AF_INET, nullptr, &saddr, &slen); mAddress.sin_addr = paddr->sin_addr; #else ::inet_pton(AF_INET, host.c_str(), &mAddress.sin_addr); diff --git a/modules/c++/numpyutils/source/numpyutils.cpp b/modules/c++/numpyutils/source/numpyutils.cpp index 6b8a76a5da..53b8b97b17 100644 --- a/modules/c++/numpyutils/source/numpyutils.cpp +++ b/modules/c++/numpyutils/source/numpyutils.cpp @@ -20,6 +20,12 @@ * */ + +#include "config/compiler_extensions.h" + +#ifndef _MSC_VER +CODA_OSS_disable_warning(-Wold-style-cast) +#endif #include #include #include diff --git a/modules/c++/pch.h b/modules/c++/pch.h index 342ae85267..f39484bc24 100644 --- a/modules/c++/pch.h +++ b/modules/c++/pch.h @@ -4,26 +4,14 @@ // However, files listed here are ALL re-compiled if any one of them is updated between builds. // Do not add files here that you will be updating frequently as this negates the performance advantage. +#pragma once #ifndef CODA_OSS_pch_h_INCLUDED_ #define CODA_OSS_pch_h_INCLUDED_ -#pragma warning(disable: 4619) // #pragma warning: there is no warning number '...' +#include "coda_oss/CPlusPlus.h" +#include "config/disable_compiler_warnings.h" -#pragma warning(disable: 4820) // '...': '...' bytes padding added after data member '...' -#pragma warning(disable: 4668) // '...' is not defined as a preprocessor macro, replacing with '...' for '...' -#pragma warning(disable: 5045) // Compiler will insert Spectre mitigation for memory load if / Qspectre switch specified -#pragma warning(disable: 4514) // '...': unreferenced inline function has been removed - -#pragma warning(push) -#pragma warning(disable: 4710) // '...': function not inlined -#pragma warning(disable: 5027) // '...': move assignment operator was implicitly defined as deleted -#pragma warning(disable: 5026) // '...': move constructor was implicitly defined as deleted -#pragma warning(disable: 4626) // '...': assignment operator was implicitly defined as deleted -#pragma warning(disable: 4625) // '...': copy constructor was implicitly defined as deleted -#pragma warning(disable: 4355) // '...': used in base member initializer list -#pragma warning(disable: 5220) // '...': a non-static data member with a volatile qualified type no longer implies that compiler generated copy/move constructors and copy/move assignment operators are not trivial -#pragma warning(disable: 5204) // '...': class has virtual functions, but its trivial destructor is not virtual; instances of objects derived from this class may not be destructed correctly -#pragma warning(disable: 5264) // '...': '...' variable is not used +CODA_OSS_disable_warning_system_header_push // add headers that you want to pre-compile here #include "framework.h" @@ -36,19 +24,90 @@ #include #include #include +#include + +CODA_OSS_disable_warning_pop #include "import/std.h" -#include -#include -#include -#include -#include -#include -#include -#pragma warning(pop) + +#include +#include +#include #pragma warning(disable: 4251) // '...': class '...' needs to have dll-interface to be used by clients of class '...' -#pragma warning(disable: 5105) // macro expansion producing '...' has undefined behavior +#pragma warning(disable: 4365) // '...': conversion from '...' to '...', signed/unsigned mismatch +#pragma warning(disable: 5039) // '...': pointer or reference to potentially throwing function passed to '...' function under -EHc. Undefined behavior may occur if this function throws an exception. +#pragma warning(disable: 6326) // Potential comparison of a constant with another constant. +#pragma warning(disable: 6054) // String '...' might not be zero-terminated. +#pragma warning(disable: 6387) // '...' could be '...'. +#pragma warning(disable: 6305) // Potential mismatch between sizeof and countof quantities. Use sizeof() to scale byte sizes. +#pragma warning(disable: 6288) // Incorrect operator. Did you intend to use || instead? +#pragma warning(disable: 6011) // Dereferencing NULL pointer '...'. +#pragma warning(disable: 6313) // Incorrect operator. Use an equality test to check for zero-valued flags. +#pragma warning(disable: 6389) // Move '...' to anonymous namespace or put a forward declaration in a common header included in this file. + +#pragma warning(disable: 26432) // If you define or delete any default operation in the type '...', define or delete them all (c.21). +#pragma warning(disable: 26429) // Symbol '...' is never tested for nullness, it can be marked as not_null (f.23). +#pragma warning(disable: 26455) // Default constructor should not throw. Declare it '...' (f.6). +#pragma warning(disable: 26440) // Function '...' can be declared '...' (f.6). +#pragma warning(disable: 26447) // The function is declared '...' but calls function '...' which may throw exceptions (f.6). +#pragma warning(disable: 26446) // Prefer to use gsl::at() instead of unchecked subscript operator (bounds.4). +#pragma warning(disable: 26481) // Don't use pointer arithmetic. Use span instead (bounds.1). +#pragma warning(disable: 26496) // The variable '...' does not change after construction, mark it as const (con.4). +#pragma warning(disable: 26462) // The value pointed to by '...' is assigned only once, mark it as a pointer to const (con.4). +#pragma warning(disable: 26409) // Avoid calling new and delete explicitly, use std::make_unique instead (r.11). +#pragma warning(disable: 26401) // Do not delete a raw pointer that is not an owner (i.11). +#pragma warning(disable: 26482) // Only index into arrays using constant expressions (bounds.2). +#pragma warning(disable: 26472) // Don't use a static_cast for arithmetic conversions. Use brace initialization, gsl::narrow_cast or gsl::narrow (type.1). +#pragma warning(disable: 26485) // Expression '...': No array to pointer decay (bounds.3). +#pragma warning(disable: 26493) // Don't use C-style casts (type.4). +#pragma warning(disable: 26451) // Arithmetic overflow: Using operator '...' on a 4 byte value and then casting the result to a 8 byte value. Cast the value to the wider type before calling operator '...' to avoid overflow (io.2). +#pragma warning(disable: 26494) // Variable '...' is uninitialized. Always initialize an object (type.5). +#pragma warning(disable: 26814) // The const variable '...' can be computed at compile-time. Consider using constexpr (con.5). +#pragma warning(disable: 26826) // Don't use C-style variable arguments (f.55). +#pragma warning(disable: 26435) // Function '...' should specify exactly one of '...', '...', or '...' (c.128). +#pragma warning(disable: 26434) // Function '...' hides a non-virtual function '...'. +#pragma warning(disable: 26400) // Do not assign the result of an allocation or a function call with an owner return value to a raw pointer, use owner instead (i.11). +#pragma warning(disable: 26433) // Function '...' should be marked with '...' (c.128). +#pragma warning(disable: 26456) // Operator '...' hides a non-virtual operator '...' (c.128). +#pragma warning(disable: 26465) // Don't use const_cast to cast away const or volatile. const_cast is not required; constness or volatility is not being removed by this conversion (type.3). +#pragma warning(disable: 26408) // Avoid malloc() and free(), prefer the nothrow version of new with delete (r.10). +#pragma warning(disable: 26471) // Don't use reinterpret_cast. A cast from void* can use static_cast (type.1). +#pragma warning(disable: 26490) // Don't use reinterpret_cast (type.1). +#pragma warning(disable: 26460) // The reference argument '...' for function '...' can be marked as const (con.3). +#pragma warning(disable: 26495) // Variable '...' is uninitialized. Always initialize a member variable (type.6). +#pragma warning(disable: 26461) // The pointer argument '...' for function '...' can be marked as a pointer to const (con.3). +#pragma warning(disable: 26436) // The type '...' with a virtual function needs either public virtual or protected non-virtual destructor (c.35). +#pragma warning(disable: 26467) // Converting from floating point to unsigned integral types results in non-portable code if the double/float has a negative value. Use gsl::narrow_cast or gsl::narrow instead to guard against undefined behavior and potential data loss (es.46). +#pragma warning(disable: 26135) // Missing annotation _Acquires_lock_(this->mNative) at function '...'. +#pragma warning(disable: 28159) // Consider using '...' instead of '...'. Reason: Deprecated. Use VerifyVersionInfo* or IsWindows* macros from VersionHelpers. +#pragma warning(disable: 26439) // This kind of function should not throw. Declare it '...' (f.6). +#pragma warning(disable: 26454) // Arithmetic overflow: '...' operation produces a negative unsigned result at compile time (io.5). +#pragma warning(disable: 26492) // Don't use const_cast to cast away const or volatile (type.3). +#pragma warning(disable: 26110) // Caller failing to hold lock '...' before calling function '...'. +#pragma warning(disable: 26459) // You called an STL function '...' with a raw pointer parameter at position '...' that may be unsafe - this relies on the caller to check that the passed values are correct. Consider wrapping your range in a gsl::span and pass as a span iterator (stl.1). +#pragma warning(disable: 26473) // Don't cast between pointer types where the source type and the target type are the same (type.1). +#pragma warning(disable: 26491) // Don't use static_cast downcasts (type.2). +#pragma warning(disable: 26405) // Do not assign to an owner which may be in valid state (r.3). +#pragma warning(disable: 26403) // Reset or explicitly delete an owner pointer '...' (r.3). +#pragma warning(disable: 26489) // Don't dereference a pointer that may be invalid: '...'. '...' may have been invalidated at line 132 (lifetime.1). +#pragma warning(disable: 26486) // Don't pass a pointer that may be invalid to a function. Parameter 0 '...' in call to '...' may be invalid (lifetime.3). +#pragma warning(disable: 26823) // Dereferencing a possibly null pointer '...' (lifetime.1). +#pragma warning(disable: 26487) // Don't return a pointer '...' that may be invalid (lifetime.4). +#pragma warning(disable: 26812) // The enum type '...' is unscoped. Prefer '...' over '...' (Enum.3). +#pragma warning(disable: 26822) // Dereferencing a null pointer '...' (lifetime.1). +#pragma warning(disable: 26458) // Prefer to use gsl::at() instead of unchecked subscript operator (bounds.4). + +// Yes, these are our files ... but they don't change very often, and if they do +// change we want to rebuild everything anyway. +#include "gsl/gsl.h" +#include "config/Exports.h" +#include "except/Throwable.h" +#include "sys/Conf.h" +#include "sys/filesystem.h" +#include "mem/SharedPtr.h" +#include "xml/lite/xerces_.h" +#include "hdf5/lite/H5_.h" #endif //CODA_OSS_pch_h_INCLUDED_ diff --git a/modules/c++/re/include/re/Regex.h b/modules/c++/re/include/re/Regex.h index 5a6234b4d6..d7dd55dd21 100644 --- a/modules/c++/re/include/re/Regex.h +++ b/modules/c++/re/include/re/Regex.h @@ -205,10 +205,6 @@ class CODA_OSS_API Regex //! The regex object std::regex mRegex; - static const std::regex badDotRegex; - static const std::regex invalidCaret; - static const std::regex invalidDollar; - #else // Internal function for passing flags to pcre2_match() std::string search(const std::string& matchString, diff --git a/modules/c++/re/source/RegexPCRE.cpp b/modules/c++/re/source/RegexPCRE.cpp index e641e2d57d..479d1fac72 100644 --- a/modules/c++/re/source/RegexPCRE.cpp +++ b/modules/c++/re/source/RegexPCRE.cpp @@ -29,6 +29,11 @@ #include +#ifndef _MSC_VER +#include "config/compiler_extensions.h" +CODA_OSS_disable_warning(-Wold-style-cast) +#endif + namespace { std::string getErrorMessage(int errorCode) diff --git a/modules/c++/re/source/RegexSTL.cpp b/modules/c++/re/source/RegexSTL.cpp index 29aed5dd46..ea0bc2bc95 100644 --- a/modules/c++/re/source/RegexSTL.cpp +++ b/modules/c++/re/source/RegexSTL.cpp @@ -30,15 +30,28 @@ namespace re { -// This is a raw literal, so ignore the R"lit( )lit" -const std::regex Regex::badDotRegex( R"lit(((^|[^\\])(\\\\)*)\.)lit", - std::regex::ECMAScript|std::regex::optimize ); -const std::regex Regex::invalidCaret( R"lit([\s\S]*([^\[\\]|[^\\](\\\\)+)\^)lit", +// These are a raw literals, so ignore the R"lit( )lit" +static const std::regex& badDotRegex() +{ + static const std::regex retval(R"lit(((^|[^\\])(\\\\)*)\.)lit", + std::regex::ECMAScript | std::regex::optimize); + return retval; +} + +static const std::regex& invalidCaret() +{ + static const std::regex retval( R"lit([\s\S]*([^\[\\]|[^\\](\\\\)+)\^)lit", std::regex::ECMAScript|std::regex::optimize ); + return retval; +} -const std::regex Regex::invalidDollar( R"lit(^([\s\S]*[^\\](\\\\)*)?\$[\s\S]+$)lit", - std::regex::ECMAScript|std::regex::optimize ); +static const std::regex& invalidDollar() +{ + static const std::regex retval( R"lit(^([\s\S]*[^\\](\\\\)*)?\$[\s\S]+$)lit", + std::regex::ECMAScript|std::regex::optimize ); + return retval; +} Regex::Regex(const std::string& pattern) : mPattern(pattern) @@ -91,8 +104,7 @@ Regex& Regex::compile(const std::string& pattern) std::smatch tmpmatch; // Look for ^ in the middle, but ignore \^ and [^ - if (std::regex_search(mPattern, tmpmatch, - invalidCaret, + if (std::regex_search(mPattern, tmpmatch, invalidCaret(), std::regex_constants::match_continuous)) { std::string msg( @@ -102,8 +114,7 @@ Regex& Regex::compile(const std::string& pattern) } // Look for $ in the middle, but ignore \$ - if (std::regex_match(mPattern, tmpmatch, - invalidDollar)) + if (std::regex_match(mPattern, tmpmatch, invalidDollar())) { std::string msg( "'$' in mid-string is not handled the same by gcc and VS2015!"); @@ -231,7 +242,7 @@ std::string Regex::replaceDot(const std::string& str) const // This makes sure we're not grabbing "\." // Replace just the "." with "[\s\S]" - std::string newstr = std::regex_replace(str, badDotRegex, "$1[\\s\\S]"); + std::string newstr = std::regex_replace(str, badDotRegex(), "$1[\\s\\S]"); return newstr; } diff --git a/modules/c++/sio.lite/include/sio/lite/SioFileWriter.h b/modules/c++/sio.lite/include/sio/lite/SioFileWriter.h index a674a4f60b..8d75266d52 100644 --- a/modules/c++/sio.lite/include/sio/lite/SioFileWriter.h +++ b/modules/c++/sio.lite/include/sio/lite/SioFileWriter.h @@ -78,6 +78,11 @@ struct FileWriter if (!mAdopt) mStream.release(); } + FileWriter(const FileWriter&) = delete; + FileWriter& operator=(const FileWriter&) = delete; + FileWriter(FileWriter&&) = default; + FileWriter& operator=(FileWriter&&) = default; + /*! * Writes the SIO given the FileHeader and InputStreams. */ diff --git a/modules/c++/sio.lite/source/StreamReader.cpp b/modules/c++/sio.lite/source/StreamReader.cpp index d629f809c5..2677d9f9b1 100644 --- a/modules/c++/sio.lite/source/StreamReader.cpp +++ b/modules/c++/sio.lite/source/StreamReader.cpp @@ -30,7 +30,7 @@ union _IntBuffer int sio::lite::StreamReader::getNextInteger() { - if (header == NULL) + if (header == nullptr) throw sio::lite::InvalidHeaderException( Ctxt("Header == null") @@ -94,7 +94,7 @@ void sio::lite::StreamReader::killHeader() { if (header) delete header; - header = NULL; + header = nullptr; // Reset length so we always have a correct value headerLength = 0; } diff --git a/modules/c++/std/include/import/cpp14.h b/modules/c++/std/include/import/cpp14.h deleted file mode 100644 index 1bc2640a5f..0000000000 --- a/modules/c++/std/include/import/cpp14.h +++ /dev/null @@ -1,60 +0,0 @@ -/* ========================================================================= - * This file is part of std-c++ - * ========================================================================= - * - * (C) Copyright 2004 - 2014, MDA Information Systems LLC - * (C) Copyright 2023, Maxar Technologies, Inc. - * - * std-c++ is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; If not, - * see . - * - */ - -#pragma once -#ifndef CODA_OSS_import_cpp14_h_INCLUDED_ -#define CODA_OSS_import_cpp14_h_INCLUDED_ - -// Common C++14 headers -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#endif // CODA_OSS_import_cpp14_h_INCLUDED_ - - diff --git a/modules/c++/std/include/import/cpp17.h b/modules/c++/std/include/import/cpp17.h deleted file mode 100644 index a03b2c5dad..0000000000 --- a/modules/c++/std/include/import/cpp17.h +++ /dev/null @@ -1,36 +0,0 @@ -/* ========================================================================= - * This file is part of std-c++ - * ========================================================================= - * - * (C) Copyright 2004 - 2014, MDA Information Systems LLC - * (C) Copyright 2023, Maxar Technologies, Inc. - * - * std-c++ is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; If not, - * see . - * - */ - -#ifndef CODA_OSS_import_cpp17_h_INCLUDED_ -#define CODA_OSS_import_cpp17_h_INCLUDED_ -#pragma once - -#include "cpp14.h" - -// Common C++17 headers -#include -#include - -#endif // CODA_OSS_import_cpp17_h_INCLUDED_ - - diff --git a/modules/c++/std/include/import/std.h b/modules/c++/std/include/import/std.h index 426a80f0c4..4dee10481c 100644 --- a/modules/c++/std/include/import/std.h +++ b/modules/c++/std/include/import/std.h @@ -29,11 +29,10 @@ #include "coda_oss/CPlusPlus.h" #include "config/disable_compiler_warnings.h" -CODA_OSS_disable_warning_push +CODA_OSS_disable_warning_system_header_push #if _MSC_VER #pragma warning(disable: 4619) // #pragma warning: there is no warning number '...' -#pragma warning(disable: 4710) // '...': function not inlined #pragma warning(disable: 5027) // '...': move assignment operator was implicitly defined as deleted #pragma warning(disable: 5026) // '...': move constructor was implicitly defined as deleted #pragma warning(disable: 4626) // '...': assignment operator was implicitly defined as deleted @@ -44,12 +43,63 @@ CODA_OSS_disable_warning_push #pragma warning(disable: 5264) // '...': '...' variable is not used #endif // _MSC_VER -// Common C++14 headers -#include "cpp14.h" +#include +#include +#include +#include +#include +#include +#include +#include -#if CODA_OSS_cpp17 -#include "cpp17.h" -#endif +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +//#include +#include +#include +#include +#include +#include +#include +#include CODA_OSS_disable_warning_pop diff --git a/modules/c++/str/source/Encoding.cpp b/modules/c++/str/source/Encoding.cpp index 86a879b0c4..46ce45b738 100644 --- a/modules/c++/str/source/Encoding.cpp +++ b/modules/c++/str/source/Encoding.cpp @@ -33,56 +33,74 @@ #include #include +#include "gsl/gsl.h" +#include "config/compiler_extensions.h" + #include "str/Encoding.h" #include "str/Manip.h" #include "str/Convert.h" -#include "str/utf8.h" #include "str/EncodedStringView.h" + +CODA_OSS_disable_warning_push +#if _MSC_VER +#pragma warning(disable: 26818) // Switch statement does not cover all cases. Consider adding a '...' label (es.79). +#else +CODA_OSS_disable_warning(-Wshadow) +#endif +#include "str/utf8.h" +CODA_OSS_disable_warning_pop + // Need to look up characters from \x80 (EURO SIGN) to \x9F (LATIN CAPITAL LETTER Y WITH DIAERESIS) // in a map: http://www.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1252.TXT -inline coda_oss::u8string utf8_(std::u32string::value_type ch) +inline coda_oss::u8string utf8_(uint32_t i) { + const auto ch = gsl::narrow(i); return str::to_u8string(std::u32string{ch}); } -static const std::map Windows1252_x80_x9F_to_u8string{ - {0x80, utf8_(0x20AC) } // EURO SIGN - // , {0x81, replacement_character } // UNDEFINED - , {0x82, utf8_(0x201A) } // SINGLE LOW-9 QUOTATION MARK - , {0x83, utf8_(0x0192) } // LATIN SMALL LETTER F WITH HOOK - , {0x84, utf8_(0x201E) } // DOUBLE LOW-9 QUOTATION MARK - , {0x85, utf8_(0x2026) } // HORIZONTAL ELLIPSIS - , {0x86, utf8_(0x2020) } // DAGGER - , {0x87, utf8_(0x2021) } // DOUBLE DAGGER - , {0x88, utf8_(0x02C6) } // MODIFIER LETTER CIRCUMFLEX ACCENT - , {0x89, utf8_(0x2030) } // PER MILLE SIGN - , {0x8A, utf8_(0x0160) } // LATIN CAPITAL LETTER S WITH CARON - , {0x8B, utf8_(0x2039) } // SINGLE LEFT-POINTING ANGLE QUOTATION MARK - , {0x8C, utf8_(0x0152) } // LATIN CAPITAL LIGATURE OE - //, {0x8D, replacement_character } // UNDEFINED - , {0x8E, utf8_(0x017D) } // LATIN CAPITAL LETTER Z WITH CARON - //, {0x8F, replacement_character } // UNDEFINED - //, {0x90, replacement_character } // UNDEFINED - , {0x91, utf8_(0x2018) } // LEFT SINGLE QUOTATION MARK - , {0x92, utf8_(0x2019) } // RIGHT SINGLE QUOTATION MARK - , {0x93, utf8_(0x201C) } // LEFT DOUBLE QUOTATION MARK - , {0x94, utf8_(0x201D) } // RIGHT DOUBLE QUOTATION MARK - , {0x95, utf8_(0x2022) } // BULLET - , {0x96, utf8_(0x2013) } // EN DASH - , {0x97, utf8_(0x2014) } // EM DASH - , {0x98, utf8_(0x02DC) } // SMALL TILDE - , {0x99, utf8_(0x2122) } // TRADE MARK SIGN - , {0x9A, utf8_(0x0161) } // LATIN SMALL LETTER S WITH CARON - , {0x9B, utf8_(0x203A) } // SINGLE RIGHT-POINTING ANGLE QUOTATION MARK - , {0x9C, utf8_(0x0153) } // LATIN SMALL LIGATURE OE - //, {0x9D, replacement_character } // UNDEFINED - , {0x9E, utf8_(0x017E) } // LATIN SMALL LETTER Z WITH CARON - , {0x9F, utf8_(0x0178) } // LATIN CAPITAL LETTER Y WITH DIAERESIS -}; -static std::map Windows1252_to_u8string() +static const auto& Windows1252_x80_x9F_to_u8string() +{ + static const std::map retval { + {0x80, utf8_(0x20AC) } // EURO SIGN + // , {0x81, replacement_character } // UNDEFINED + , {0x82, utf8_(0x201A) } // SINGLE LOW-9 QUOTATION MARK + , {0x83, utf8_(0x0192) } // LATIN SMALL LETTER F WITH HOOK + , {0x84, utf8_(0x201E) } // DOUBLE LOW-9 QUOTATION MARK + , {0x85, utf8_(0x2026) } // HORIZONTAL ELLIPSIS + , {0x86, utf8_(0x2020) } // DAGGER + , {0x87, utf8_(0x2021) } // DOUBLE DAGGER + , {0x88, utf8_(0x02C6) } // MODIFIER LETTER CIRCUMFLEX ACCENT + , {0x89, utf8_(0x2030) } // PER MILLE SIGN + , {0x8A, utf8_(0x0160) } // LATIN CAPITAL LETTER S WITH CARON + , {0x8B, utf8_(0x2039) } // SINGLE LEFT-POINTING ANGLE QUOTATION MARK + , {0x8C, utf8_(0x0152) } // LATIN CAPITAL LIGATURE OE + //, {0x8D, replacement_character } // UNDEFINED + , {0x8E, utf8_(0x017D) } // LATIN CAPITAL LETTER Z WITH CARON + //, {0x8F, replacement_character } // UNDEFINED + //, {0x90, replacement_character } // UNDEFINED + , {0x91, utf8_(0x2018) } // LEFT SINGLE QUOTATION MARK + , {0x92, utf8_(0x2019) } // RIGHT SINGLE QUOTATION MARK + , {0x93, utf8_(0x201C) } // LEFT DOUBLE QUOTATION MARK + , {0x94, utf8_(0x201D) } // RIGHT DOUBLE QUOTATION MARK + , {0x95, utf8_(0x2022) } // BULLET + , {0x96, utf8_(0x2013) } // EN DASH + , {0x97, utf8_(0x2014) } // EM DASH + , {0x98, utf8_(0x02DC) } // SMALL TILDE + , {0x99, utf8_(0x2122) } // TRADE MARK SIGN + , {0x9A, utf8_(0x0161) } // LATIN SMALL LETTER S WITH CARON + , {0x9B, utf8_(0x203A) } // SINGLE RIGHT-POINTING ANGLE QUOTATION MARK + , {0x9C, utf8_(0x0153) } // LATIN SMALL LIGATURE OE + //, {0x9D, replacement_character } // UNDEFINED + , {0x9E, utf8_(0x017E) } // LATIN SMALL LETTER Z WITH CARON + , {0x9F, utf8_(0x0178) } // LATIN CAPITAL LETTER Y WITH DIAERESIS + }; + return retval; +} + +static auto Windows1252_to_u8string() { - auto retval = Windows1252_x80_x9F_to_u8string; + auto retval = Windows1252_x80_x9F_to_u8string(); // Add the ISO8859-1 values to the map too. 1) We're already looking // in the map anyway for Windows-1252 characters. 2) Need map diff --git a/modules/c++/str/source/Format.cpp b/modules/c++/str/source/Format.cpp index 2d24470881..b89c974e8f 100644 --- a/modules/c++/str/source/Format.cpp +++ b/modules/c++/str/source/Format.cpp @@ -22,8 +22,11 @@ #include "str/Format.h" + #include +#include +#include static std::string vformat(const char* format, va_list& args) { @@ -36,12 +39,24 @@ static std::string vformat(const char* format, va_list& args) return std::string(buffer); } +inline void va_end_(va_list& args) +{ + CODA_OSS_disable_warning_push + #if _MSC_VER + #pragma warning(disable : 26477) // Use '...' rather than 0 or NULL(es .47). + #endif + + va_end(args); + + CODA_OSS_disable_warning_pop +} + std::string str::format(const char *format, ...) { va_list args; va_start(args, format); auto retval = vformat(format, args); - va_end(args); + va_end_(args); return retval; } @@ -50,6 +65,6 @@ str::Format::Format(const char* format, ...) va_list args; va_start(args, format); auto result = vformat(format, args); - va_end(args); + va_end_(args); mString = std::move(result); } diff --git a/modules/c++/str/source/Manip.cpp b/modules/c++/str/source/Manip.cpp index 9efdac7166..f8dbce7db7 100644 --- a/modules/c++/str/source/Manip.cpp +++ b/modules/c++/str/source/Manip.cpp @@ -33,6 +33,8 @@ #include #include +#include "gsl/gsl.h" + #include "str/Convert.h" #include "str/Encoding.h" @@ -81,7 +83,7 @@ inline void trim_(std::basic_string & s) } s.erase(0, i); - for (i = s.length() - 1; (int) i >= 0; i--) + for (i = s.length() - 1; static_cast(i) >= 0; i--) { if (!iswspace(static_cast(s[i]))) break; @@ -251,10 +253,16 @@ bool containsOnly(const std::string& s, const std::string& validChars) typedef std::string::const_iterator StringIter; std::vector chars(255, false); for (StringIter it = validChars.begin(); it != validChars.end(); ++it) - chars[(unsigned int)*it] = true; + { + const auto i = gsl::narrow(*it); + chars[i] = true; + } for (StringIter it = s.begin(); it != s.end(); ++it) - if (!chars[(unsigned int)*it]) + { + const auto i = gsl::narrow(*it); + if (!chars[i]) return false; + } return true; } diff --git a/modules/c++/str/unittests/test_base_convert.cpp b/modules/c++/str/unittests/test_base_convert.cpp index 358fa6827a..71ee45016d 100644 --- a/modules/c++/str/unittests/test_base_convert.cpp +++ b/modules/c++/str/unittests/test_base_convert.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include "TestCase.h" @@ -44,14 +45,14 @@ inline static void test_assert_eq(const std::string& testName, const std::u8stri TEST_CASE(testConvert) { - TEST_ASSERT_EQ(str::toType("0x3BC7", 16), (long long) 0x3BC7); - TEST_ASSERT_EQ(str::toType("1101", 2), (long long) 13); - TEST_ASSERT_EQ(str::toType("231", 5), (long long) 66); + TEST_ASSERT_EQ(str::toType("0x3BC7", 16), gsl::narrow(0x3BC7)); + TEST_ASSERT_EQ(str::toType("1101", 2), gsl::narrow(13)); + TEST_ASSERT_EQ(str::toType("231", 5), gsl::narrow(66)); TEST_ASSERT_EQ(str::toType("0xFFFFFFFFFFFFFFFF", 16), - (unsigned long long) 0xFFFFFFFFFFFFFFFF); + gsl::narrow(0xFFFFFFFFFFFFFFFF)); TEST_ASSERT_EQ(str::toType("-10", 10), - (unsigned long long) -10); - TEST_ASSERT_EQ(str::toType("13", 4), (short) 7); + gsl::narrow_cast(-10)); + TEST_ASSERT_EQ(str::toType("13", 4), gsl::narrow(7)); } TEST_CASE(testBadConvert) diff --git a/modules/c++/str/unittests/test_str.cpp b/modules/c++/str/unittests/test_str.cpp index e04b8ce7ba..a3381632d8 100644 --- a/modules/c++/str/unittests/test_str.cpp +++ b/modules/c++/str/unittests/test_str.cpp @@ -199,9 +199,9 @@ TEST_CASE(testRoundDouble) nv *= denom; TEST_ASSERT_ALMOST_EQ_EPS(nv, numerator, eps); std::cout << nv << std::endl; - std::cout << (nv - (int)nv) << std::endl; + std::cout << (nv - static_cast(nv)) << std::endl; std::cout << std::numeric_limits::epsilon() << std::endl; - TEST_ASSERT_EQ((int)std::ceil(nv), (int)numerator); + TEST_ASSERT_EQ(static_cast(std::ceil(nv)), static_cast(numerator)); } TEST_CASE(testEscapeForXMLNoReplace) @@ -335,4 +335,4 @@ TEST_MAIN( TEST_CHECK(test_toTypeComplexFloat); TEST_CHECK(test_toStringComplexShort); TEST_CHECK(test_toTypeComplexShort); - ) \ No newline at end of file + ) diff --git a/modules/c++/sys/include/sys/AbstractOS.h b/modules/c++/sys/include/sys/AbstractOS.h index 8457c16b6d..1b040790e0 100644 --- a/modules/c++/sys/include/sys/AbstractOS.h +++ b/modules/c++/sys/include/sys/AbstractOS.h @@ -352,10 +352,8 @@ struct CODA_OSS_API AbstractOS class AbstractDirectory { public: - AbstractDirectory() - { - } - virtual ~AbstractDirectory() + AbstractDirectory() = default; + virtual ~AbstractDirectory() noexcept(false) { } virtual void close() = 0; diff --git a/modules/c++/sys/include/sys/Conf.h b/modules/c++/sys/include/sys/Conf.h index 111e5f9c86..45cf7da292 100644 --- a/modules/c++/sys/include/sys/Conf.h +++ b/modules/c++/sys/include/sys/Conf.h @@ -21,9 +21,9 @@ * */ +#pragma once #ifndef CODA_OSS_sys_Conf_h_INCLUDED_ #define CODA_OSS_sys_Conf_h_INCLUDED_ -#pragma once // In case there is still a WIN32 (should be "_WIN32" with a leading '_') someplace. #if defined(_WIN32) && !defined(WIN32) diff --git a/modules/c++/sys/include/sys/Dbg.h b/modules/c++/sys/include/sys/Dbg.h index acd05b980e..5c896f354a 100644 --- a/modules/c++/sys/include/sys/Dbg.h +++ b/modules/c++/sys/include/sys/Dbg.h @@ -196,14 +196,14 @@ namespace sys * \param format * \param ... Put in any format value here */ -CODA_OSS_API void dbgPrintf(const char *format, ...); +CODA_OSS_API void dbgPrintf(const char *format, ...) noexcept; /*! * Prints to DEBUG_STREAM and kills the program * \param format * \param ... Put in any format value here */ -void diePrintf(const char *format, ...); +void diePrintf(const char* format, ...) noexcept; } #define dbg_printf sys::dbgPrintf diff --git a/modules/c++/sys/include/sys/OSWin32.h b/modules/c++/sys/include/sys/OSWin32.h index ffba1f30b2..c39d3b8460 100644 --- a/modules/c++/sys/include/sys/OSWin32.h +++ b/modules/c++/sys/include/sys/OSWin32.h @@ -270,7 +270,7 @@ struct CODA_OSS_API OSWin32 final : public AbstractOS struct DirectoryWin32 final : public AbstractDirectory { DirectoryWin32() = default; - virtual ~DirectoryWin32() + virtual ~DirectoryWin32() noexcept(false) { close(); } diff --git a/modules/c++/sys/include/sys/ReadWriteMutex.h b/modules/c++/sys/include/sys/ReadWriteMutex.h index e3141a7ddc..1200514cbf 100644 --- a/modules/c++/sys/include/sys/ReadWriteMutex.h +++ b/modules/c++/sys/include/sys/ReadWriteMutex.h @@ -51,7 +51,7 @@ struct ReadWriteMutex } //! Destructor - virtual ~ReadWriteMutex() + virtual ~ReadWriteMutex() { dbg_printf("Destroying a read/write mutex\n"); } diff --git a/modules/c++/sys/include/sys/String.h b/modules/c++/sys/include/sys/String.h deleted file mode 100644 index 5adc016f11..0000000000 --- a/modules/c++/sys/include/sys/String.h +++ /dev/null @@ -1,29 +0,0 @@ -/* ========================================================================= - * This file is part of sys-c++ - * ========================================================================= - * - * (C) Copyright 2004 - 2014, MDA Information Systems LLC - * - * sys-c++ is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; If not, - * see . - * - */ - -#ifndef CODA_OSS_sys_String_h_INCLUDED_ -#define CODA_OSS_sys_String_h_INCLUDED_ -#pragma once - -#include "str/String_.h" - -#endif // CODA_OSS_sys_String_h_INCLUDED_ diff --git a/modules/c++/sys/include/sys/ThreadInterface.h b/modules/c++/sys/include/sys/ThreadInterface.h index 576f643471..e536fe48e7 100644 --- a/modules/c++/sys/include/sys/ThreadInterface.h +++ b/modules/c++/sys/include/sys/ThreadInterface.h @@ -47,7 +47,7 @@ namespace sys * { * // declare this function. * STANDARD_START_CALL(Win32Thread, v); - * return NULL; + * return nullptr; * } * \endcode */ diff --git a/modules/c++/sys/include/sys/ThreadPosix.h b/modules/c++/sys/include/sys/ThreadPosix.h index 5e5efe8c29..26a17b1751 100644 --- a/modules/c++/sys/include/sys/ThreadPosix.h +++ b/modules/c++/sys/include/sys/ThreadPosix.h @@ -49,7 +49,7 @@ namespace sys */ inline long getThreadID() { - return (long)pthread_self(); + return static_cast(pthread_self()); } /*! diff --git a/modules/c++/sys/source/AbstractOS.cpp b/modules/c++/sys/source/AbstractOS.cpp index 773067c1be..e32b44d879 100644 --- a/modules/c++/sys/source/AbstractOS.cpp +++ b/modules/c++/sys/source/AbstractOS.cpp @@ -31,6 +31,7 @@ #include #include +#include #include #include #include @@ -405,7 +406,13 @@ static std::string getSpecialEnv_SECONDS(const AbstractOS&, const std::string& e #endif return getSpecialEnv_SECONDS_(); } + +CODA_OSS_disable_warning_push +#if _MSC_VER +#pragma warning(disable: 26426) // Global initializer calls a non-constexpr function '...' (i.22). +#endif static std::string strUnusedSeconds = getSpecialEnv_SECONDS_(); // "start" the "shell" +CODA_OSS_disable_warning_pop // See https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html // and https://wiki.bash-hackers.org/syntax/shellvars diff --git a/modules/c++/sys/source/ConditionVarPosix.cpp b/modules/c++/sys/source/ConditionVarPosix.cpp index 267a339275..505a17634b 100644 --- a/modules/c++/sys/source/ConditionVarPosix.cpp +++ b/modules/c++/sys/source/ConditionVarPosix.cpp @@ -22,6 +22,8 @@ #include +#include "gsl/gsl.h" + #if CODA_OSS_POSIX_SOURCE #include @@ -85,8 +87,8 @@ void sys::ConditionVarPosix::wait(double seconds) if ( seconds > 0 ) { timespec tout; - tout.tv_sec = time(NULL) + (int)seconds; - tout.tv_nsec = (int)((seconds - (int)(seconds)) * 1e9); + tout.tv_sec = time(NULL) + gsl::narrow_cast(seconds); + tout.tv_nsec = gsl::narrow_cast((seconds - gsl::narrow_cast(seconds)) * 1e9); if (::pthread_cond_timedwait(&mNative, &(mMutex->getNative()), &tout) != 0) diff --git a/modules/c++/sys/source/ConditionVarWin32.cpp b/modules/c++/sys/source/ConditionVarWin32.cpp index 45ffac49a7..eb719a428e 100644 --- a/modules/c++/sys/source/ConditionVarWin32.cpp +++ b/modules/c++/sys/source/ConditionVarWin32.cpp @@ -41,6 +41,11 @@ namespace LeaveCriticalSection(&mCriticalSection); } + ScopedCriticalSection(const ScopedCriticalSection&) = delete; + ScopedCriticalSection& operator=(const ScopedCriticalSection&) = delete; + ScopedCriticalSection(ScopedCriticalSection&&) = delete; + ScopedCriticalSection& operator=(ScopedCriticalSection&&) = delete; + private: CRITICAL_SECTION& mCriticalSection; }; @@ -48,12 +53,12 @@ namespace sys::ConditionVarDataWin32::ConditionVarDataWin32(): mNumWaiters(0), - mSemaphore(CreateSemaphore(NULL, 0, 0x7FFFFFFF, NULL)), - mWaitersAreDone(CreateEvent(NULL, FALSE, FALSE, NULL)), + mSemaphore(CreateSemaphore(nullptr, 0, 0x7FFFFFFF, nullptr)), + mWaitersAreDone(CreateEvent(nullptr, FALSE, FALSE, nullptr)), mWasBroadcast(false) { InitializeCriticalSection(&mNumWaitersCS); - if (mSemaphore == NULL || mWaitersAreDone == NULL) + if (mSemaphore == nullptr || mWaitersAreDone == nullptr) { throw sys::SystemException( "ConditionVarDataWin32 Initializer failed"); @@ -163,7 +168,7 @@ void sys::ConditionVarDataWin32::signal() // If there are waiters, increment the semaphore by 1 to wake one up if (haveWaiters) { - ReleaseSemaphore(mSemaphore, 1, NULL); + ReleaseSemaphore(mSemaphore, 1, nullptr); } } @@ -179,7 +184,7 @@ void sys::ConditionVarDataWin32::broadcast() { mWasBroadcast = true; haveWaiters = true; - ReleaseSemaphore(mSemaphore, static_cast(mNumWaiters), 0); + ReleaseSemaphore(mSemaphore, static_cast(mNumWaiters), nullptr); } else { diff --git a/modules/c++/sys/source/Conf.cpp b/modules/c++/sys/source/Conf.cpp index 326b3cac71..1358a1e81e 100644 --- a/modules/c++/sys/source/Conf.cpp +++ b/modules/c++/sys/source/Conf.cpp @@ -85,8 +85,9 @@ constexpr inline bool is_big_or_little_endian() inline bool testIsBigEndianSystem() { // This is an endian test - int intVal = 1; - unsigned char* endianTest = (unsigned char*)&intVal; + static const int intVal = 1; + const void* const pIntVal = &intVal; + const auto endianTest = static_cast(pIntVal); return endianTest[0] != 1; } inline auto isBigEndianSystem_() diff --git a/modules/c++/sys/source/DLLUnix.cpp b/modules/c++/sys/source/DLLUnix.cpp index a0bb26ecfb..f43457e69a 100644 --- a/modules/c++/sys/source/DLLUnix.cpp +++ b/modules/c++/sys/source/DLLUnix.cpp @@ -58,7 +58,7 @@ void sys::DLL::unload() throw sys::DLLException("Failed to close library"); // Now we reset member data - mLib = NULL; + mLib = nullptr; mLibName.clear(); } } @@ -72,7 +72,7 @@ sys::DLL::retrieve(const std::string& functionName) DLL_FUNCTION_PTR ptr = dlsym( mLib , functionName.c_str()); // Now we check the ptr value - if (ptr == NULL) + if (ptr == nullptr) throw sys::DLLException("Failed to load function"); return ptr; diff --git a/modules/c++/sys/source/DLLWin32.cpp b/modules/c++/sys/source/DLLWin32.cpp index d3d6ff48ba..466f7d2952 100644 --- a/modules/c++/sys/source/DLLWin32.cpp +++ b/modules/c++/sys/source/DLLWin32.cpp @@ -58,7 +58,7 @@ void sys::DLL::unload() FreeLibrary( mLib ); // Now we reset member data - mLib = NULL; + mLib = nullptr; mLibName.clear(); } } @@ -67,14 +67,14 @@ DLL_FUNCTION_PTR sys::DLL:: retrieve(const std::string& functionName) { // Check to make sure we have a library - if ( mLib != NULL ) + if ( mLib != nullptr ) { // Now we get a ptr DLL_FUNCTION_PTR ptr = (DLL_FUNCTION_PTR) GetProcAddress(mLib, functionName.c_str()); // Now we check the ptr value - if (ptr == NULL) + if (ptr == nullptr) throw sys::DLLException(FmtX("Failed to load function: %s", functionName.c_str())); return ptr; diff --git a/modules/c++/sys/source/DateTime.cpp b/modules/c++/sys/source/DateTime.cpp index 9aaa96a7bf..e0f411d5bc 100644 --- a/modules/c++/sys/source/DateTime.cpp +++ b/modules/c++/sys/source/DateTime.cpp @@ -349,7 +349,7 @@ char* strptime(const char *buf, const char *fmt, struct tm& tm, double& millis) } // LINTED functional specification - return ((char *) bp); + return const_cast(bp); } } @@ -371,14 +371,14 @@ void sys::DateTime::fromMillis(const tm& t) mHour = t.tm_hour; mMinute = t.tm_min; - const size_t timeInSeconds = (size_t)(mTimeInMillis / 1000); - const double timediff = ((double)mTimeInMillis / 1000.0) - timeInSeconds; + const auto timeInSeconds = gsl::narrow_cast(mTimeInMillis / 1000); + const auto timediff = (gsl::narrow_cast(mTimeInMillis) / 1000.0) - gsl::narrow_cast(timeInSeconds); mSecond = t.tm_sec + timediff; } double sys::DateTime::toMillis(tm t) const { - time_t timeInSeconds = mktime(&t); + const auto timeInSeconds = gsl::narrow_cast(mktime(&t)); double timediff = mSecond - t.tm_sec; return (timeInSeconds + timediff) * 1000.0; } @@ -404,9 +404,9 @@ static double getNowInMillis() // does not need millisecond accuracy SYSTEMTIME now; GetLocalTime(&now); - return (double)time(NULL) * 1000 + now.wMilliseconds; + return (double)time(nullptr) * 1000 + now.wMilliseconds; #else - return (double)time(NULL) * 1000; + return (double)time(nullptr) * 1000; #endif } void sys::DateTime::setNow() @@ -634,7 +634,7 @@ void sys::DateTime::localtime(time_t numSecondsSinceEpoch, tm& t) // our fingers and hope the regular function actually is reentrant // (supposedly this is the case on Windows). #if CODA_OSS_POSIX_SOURCE - if (::localtime_r(&numSecondsSinceEpoch, &t) == NULL) + if (::localtime_r(&numSecondsSinceEpoch, &t) == nullptr) { int const errnum = errno; throw except::Exception(Ctxt("localtime_r() failed (" + @@ -664,7 +664,7 @@ void sys::DateTime::gmtime(time_t numSecondsSinceEpoch, tm& t) // our fingers and hope the regular function actually is reentrant // (supposedly this is the case on Windows). #if CODA_OSS_POSIX_SOURCE - if (::gmtime_r(&numSecondsSinceEpoch, &t) == NULL) + if (::gmtime_r(&numSecondsSinceEpoch, &t) == nullptr) { int const errnum = errno; throw except::Exception(Ctxt("gmtime_r() failed (" + diff --git a/modules/c++/sys/source/Dbg.cpp b/modules/c++/sys/source/Dbg.cpp index 804d504ed3..3fa6f37a03 100644 --- a/modules/c++/sys/source/Dbg.cpp +++ b/modules/c++/sys/source/Dbg.cpp @@ -24,7 +24,23 @@ #include "sys/Dbg.h" -void sys::dbgPrintf(const char *format, ...) +#include + +#include + +inline void va_end_(va_list& args) noexcept +{ + CODA_OSS_disable_warning_push + #if _MSC_VER + #pragma warning(disable : 26477) // Use '...' rather than 0 or NULL(es .47). + #endif + + va_end(args); + + CODA_OSS_disable_warning_pop +} + +void sys::dbgPrintf(const char *format, ...) noexcept { if (sys::debugging) { @@ -32,16 +48,16 @@ void sys::dbgPrintf(const char *format, ...) va_start(args, format); fprintf(DEBUG_STREAM, " "); vfprintf(DEBUG_STREAM, format, args); - va_end(args); + va_end_(args); } } -void sys::diePrintf(const char *format, ...) +void sys::diePrintf(const char* format, ...) noexcept { va_list args; va_start(args, format); vfprintf(DEBUG_STREAM, format, args); - va_end(args); + va_end_(args); exit(EXIT_FAILURE); } diff --git a/modules/c++/sys/source/ErrUnix.cpp b/modules/c++/sys/source/ErrUnix.cpp index f2db39499c..6fcf3699f3 100644 --- a/modules/c++/sys/source/ErrUnix.cpp +++ b/modules/c++/sys/source/ErrUnix.cpp @@ -33,7 +33,7 @@ int sys::Err::getLast() const std::string sys::Err::toString() const { char *temp = strerror(mErrId); - if (temp == NULL) + if (temp == nullptr) return std::string(""); std::string stringError = temp; diff --git a/modules/c++/sys/source/ErrWin32.cpp b/modules/c++/sys/source/ErrWin32.cpp index bac96d0af3..cb82416877 100644 --- a/modules/c++/sys/source/ErrWin32.cpp +++ b/modules/c++/sys/source/ErrWin32.cpp @@ -35,9 +35,9 @@ std::string sys::Err::toString() const { LPTSTR buffer; if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | - FORMAT_MESSAGE_FROM_SYSTEM, NULL, + FORMAT_MESSAGE_FROM_SYSTEM, nullptr, static_cast(mErrId), 0, - (LPTSTR)&buffer, 0, NULL) == 0) + (LPTSTR)&buffer, 0, nullptr) == 0) { return std::string("Unknown error code"); } diff --git a/modules/c++/sys/source/ExecUnix.cpp b/modules/c++/sys/source/ExecUnix.cpp index 6a5f20912f..24ea231038 100644 --- a/modules/c++/sys/source/ExecUnix.cpp +++ b/modules/c++/sys/source/ExecUnix.cpp @@ -39,13 +39,13 @@ namespace sys FILE* ExecPipe::openPipe(const std::string& command, const std::string& type) { - FILE* ioFile = NULL; + FILE* ioFile = nullptr; int pIO[2]; //! create the IO pipes for stdin/out if (pipe(pIO) < 0) { - return NULL; + return nullptr; } //! fork a subprocess for running our command -- @@ -58,7 +58,7 @@ FILE* ExecPipe::openPipe(const std::string& command, // there was an error while forking close(pIO[READ_PIPE]); close(pIO[WRITE_PIPE]); - return NULL; + return nullptr; case 0: { // we are now in the forked process -- @@ -144,7 +144,7 @@ int ExecPipe::closePipe() if (mOutStream) { fclose(mOutStream); - mOutStream = NULL; + mOutStream = nullptr; } int exitStatus = 0; diff --git a/modules/c++/sys/source/ExecWin32.cpp b/modules/c++/sys/source/ExecWin32.cpp index 86bfa17cdc..f49271d6b1 100644 --- a/modules/c++/sys/source/ExecWin32.cpp +++ b/modules/c++/sys/source/ExecWin32.cpp @@ -20,6 +20,7 @@ * */ +#include #ifdef _WIN32 @@ -42,22 +43,22 @@ FILE* ExecPipe::openPipe(const std::string& command, const std::string& type) { FILE* ioFile = nullptr; - HANDLE outIO[2] = {NULL, NULL}; + HANDLE outIO[2] = {nullptr, nullptr}; //! inherit the pipe handles SECURITY_ATTRIBUTES saAttr; saAttr.nLength = sizeof(SECURITY_ATTRIBUTES); saAttr.bInheritHandle = TRUE; - saAttr.lpSecurityDescriptor = NULL; + saAttr.lpSecurityDescriptor = nullptr; if (!CreatePipe(&outIO[READ_PIPE], &outIO[WRITE_PIPE], &saAttr, 0)) { - return NULL; + return nullptr; } // check the pipes themselves are not inherited if (!SetHandleInformation(outIO[READ_PIPE], HANDLE_FLAG_INHERIT, 0)) { - return NULL; + return nullptr; } // the startInfo structure is where the pipes are connected @@ -75,11 +76,11 @@ FILE* ExecPipe::openPipe(const std::string& command, //! create the subprocess -- // this is equivalent to a fork + exec - if (CreateProcess(NULL, const_cast(command.c_str()), - NULL, NULL, TRUE, 0, NULL, NULL, + if (CreateProcess(nullptr, const_cast(command.c_str()), + nullptr, nullptr, TRUE, 0, nullptr, nullptr, &mStartInfo, &mProcessInfo) == 0) { - return NULL; + return nullptr; } // connect the pipes currently connected in the subprocess @@ -92,7 +93,7 @@ FILE* ExecPipe::openPipe(const std::string& command, if ((readDescriptor = _open_osfhandle( (intptr_t)outIO[READ_PIPE], _O_RDONLY)) == -1) { - return NULL; + return nullptr; } ioFile = _fdopen(readDescriptor, type.c_str()); CloseHandle(outIO[WRITE_PIPE]); @@ -121,13 +122,13 @@ int ExecPipe::closePipe() } // in case it fails - mOutStream = NULL; + mOutStream = nullptr; DWORD dwMillisec = INFINITE; - (void) WaitForSingleObject(mProcessInfo.hProcess, dwMillisec); + std::ignore = WaitForSingleObject(mProcessInfo.hProcess, dwMillisec); //! get the exit code - DWORD exitCode = NULL; + DWORD exitCode = 0; GetExitCodeProcess(mProcessInfo.hProcess, &exitCode); const int exitStatus = static_cast(exitCode); if (exitStatus == -1) diff --git a/modules/c++/sys/source/FileFinder.cpp b/modules/c++/sys/source/FileFinder.cpp index b95600aa32..6b47dda795 100644 --- a/modules/c++/sys/source/FileFinder.cpp +++ b/modules/c++/sys/source/FileFinder.cpp @@ -102,7 +102,7 @@ sys::NotPredicate::~NotPredicate() if (mPredicate.second && mPredicate.first) { FilePredicate* tmp = mPredicate.first; - mPredicate.first = NULL; + mPredicate.first = nullptr; delete tmp; } } @@ -125,7 +125,7 @@ sys::LogicalPredicate::~LogicalPredicate() if (p.first && p.second) { sys::FilePredicate* tmp = p.first; - p.first = NULL; + p.first = nullptr; delete tmp; } } @@ -265,7 +265,7 @@ fs::path sys::findFirstDirectory(const fs::path& startingDirectory, const fs::pa fs::path sys::test::findRootDirectory(const fs::path& p, const std::string& rootName, std::function isRoot) { - const auto isRootDirectory = [&](const fs::path& p) { return is_directory(p) && isRoot(p); }; + const auto isRootDirectory = [&](const fs::path& v) { return is_directory(v) && isRoot(v); }; // Does the given path look good? if (isRootDirectory(p)) diff --git a/modules/c++/sys/source/FileUnix.cpp b/modules/c++/sys/source/FileUnix.cpp index f046f7db3d..e603835a32 100644 --- a/modules/c++/sys/source/FileUnix.cpp +++ b/modules/c++/sys/source/FileUnix.cpp @@ -118,7 +118,7 @@ void sys::File::writeFrom(const void* buffer, size_t size) sys::Off_T sys::File::seekTo(sys::Off_T offset, int whence) { sys::Off_T off = ::lseek(mHandle, offset, whence); - if (off == (sys::Off_T) - 1) + if (off == static_cast(-1)) throw sys::SystemException(Ctxt("Seeking in file")); return off; } diff --git a/modules/c++/sys/source/FileWin32.cpp b/modules/c++/sys/source/FileWin32.cpp index 1b60a02010..5e2f2b23d0 100644 --- a/modules/c++/sys/source/FileWin32.cpp +++ b/modules/c++/sys/source/FileWin32.cpp @@ -49,7 +49,7 @@ _SYS_HANDLE_TYPE sys::File::createFile(const coda_oss::filesystem::path& str_, i nullptr /*lpSecurityAttributes*/, dwCreationDisposition, FILE_ATTRIBUTE_NORMAL, - static_cast(0) /*hTemplateFile*/); + static_cast(nullptr) /*hTemplateFile*/); } void sys::File::create(const std::string& str, int accessFlags, @@ -83,7 +83,7 @@ void sys::File::readInto(void* buffer, size_t size) bufferPtr + bytesRead, bytesToRead, &bytesThisRead, - NULL)) + nullptr)) { throw sys::SystemException(Ctxt("Error reading from file")); } @@ -120,7 +120,7 @@ void sys::File::writeFrom(const void* buffer, size_t size) bufferPtr + bytesWritten, bytesToWrite, &bytesThisWrite, - NULL)) + nullptr)) { throw sys::SystemException(Ctxt("Writing from file")); } diff --git a/modules/c++/sys/source/LocalDateTime.cpp b/modules/c++/sys/source/LocalDateTime.cpp index 5f72154805..d0df8a2134 100644 --- a/modules/c++/sys/source/LocalDateTime.cpp +++ b/modules/c++/sys/source/LocalDateTime.cpp @@ -47,7 +47,7 @@ void LocalDateTime::toMillis() t.tm_yday = mDayOfYear - 1; t.tm_hour = mHour; t.tm_min = mMinute; - t.tm_sec = (int)mSecond; + t.tm_sec = static_cast(mSecond); t.tm_isdst = mDST; mTimeInMillis = DateTime::toMillis(t); diff --git a/modules/c++/sys/source/MutexWin32.cpp b/modules/c++/sys/source/MutexWin32.cpp index 62786f0ee0..d04d74511d 100644 --- a/modules/c++/sys/source/MutexWin32.cpp +++ b/modules/c++/sys/source/MutexWin32.cpp @@ -29,8 +29,8 @@ sys::MutexWin32::MutexWin32() { - mNative = CreateMutex(NULL, FALSE, NULL); - if (mNative == NULL) + mNative = CreateMutex(nullptr, FALSE, nullptr); + if (mNative == nullptr) throw sys::SystemException("Mutex initializer failed"); } diff --git a/modules/c++/sys/source/OSUnix.cpp b/modules/c++/sys/source/OSUnix.cpp index 355245e3b7..e2b96cf18c 100644 --- a/modules/c++/sys/source/OSUnix.cpp +++ b/modules/c++/sys/source/OSUnix.cpp @@ -257,7 +257,7 @@ std::string sys::OSUnix::getTempName(const std::string& path, } #else CharWrapper tempname = tempnam(path.c_str(), prefix.c_str()); - if (tempname.get() == NULL) + if (tempname.get() == nullptr) name = ""; else { @@ -299,7 +299,7 @@ std::string sys::OSUnix::operator[](const std::string& s) const std::string sys::OSUnix::getEnv(const std::string& s) const { const char* envVal = getenv(s.c_str()); - if (envVal == NULL) + if (envVal == nullptr) throw sys::SystemException( Ctxt("Unable to get unix environment variable " + s)); return std::string(envVal); @@ -324,7 +324,7 @@ void sys::OSUnix::setEnv(const std::string& var, // putenv() will overwrite the value if it already exists, so if we don't // want to overwrite, we do nothing when getenv() indicates the variable's // already set - if (overwrite || getenv(var.c_str()) == NULL) + if (overwrite || getenv(var.c_str()) == nullptr) { // putenv() isn't guaranteed to make a copy of the string, so we need // to allocate it and let it leak. Ugh. @@ -560,23 +560,23 @@ void sys::DirectoryUnix::close() if (mDir) { closedir( mDir); - mDir = NULL; + mDir = nullptr; } } std::string sys::DirectoryUnix::findFirstFile(const std::string& dir) { // First file is always . on Unix mDir = ::opendir(dir.c_str()); - if (mDir == NULL) + if (mDir == nullptr) return ""; return findNextFile(); } std::string sys::DirectoryUnix::findNextFile() { - struct dirent* entry = NULL; + struct dirent* entry = nullptr; entry = ::readdir(mDir); - if (entry == NULL) + if (entry == nullptr) return ""; return entry->d_name; } diff --git a/modules/c++/sys/source/OSWin32.cpp b/modules/c++/sys/source/OSWin32.cpp index b8a1f39e64..e381f2f917 100644 --- a/modules/c++/sys/source/OSWin32.cpp +++ b/modules/c++/sys/source/OSWin32.cpp @@ -81,12 +81,12 @@ bool sys::OSWin32::exists(const std::string& path) const const DWORD errCode = GetLastError(); if (errCode != ERROR_FILE_NOT_FOUND && errCode != ERROR_PATH_NOT_FOUND) { - char* err = NULL; + char* err = nullptr; FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, - NULL, errCode, + nullptr, errCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (LPTSTR) &err, 0, NULL); + (LPTSTR) &err, 0, nullptr); throw except::Exception(Ctxt( "Problem while testing file existence for " + path + " with Error: " + std::string(err))); @@ -166,7 +166,7 @@ bool sys::OSWin32::isDirectory(const std::string& path) const bool sys::OSWin32::makeDirectory(const std::string& path) const { - return (CreateDirectory(path.c_str(), NULL)) ? (true): (false); + return (CreateDirectory(path.c_str(), nullptr)) ? (true) : (false); } std::string sys::OSWin32::getCurrentWorkingDirectory() const @@ -224,7 +224,7 @@ std::string sys::OSWin32::operator[](const std::string& s) const static std::string getEnv(const std::string& s) { - const DWORD size = GetEnvironmentVariable(s.c_str(), NULL, 0); + const DWORD size = GetEnvironmentVariable(s.c_str(), nullptr, 0); if (size == 0) { throw sys::SystemException(Ctxt( @@ -266,7 +266,7 @@ std::string sys::OSWin32::getEnv(const std::string& s) const bool sys::OSWin32::isEnvSet(const std::string& s) const { - const DWORD size = GetEnvironmentVariable(s.c_str(), NULL, 0); + const DWORD size = GetEnvironmentVariable(s.c_str(), nullptr, 0); if (size != 0) { return true; @@ -283,8 +283,14 @@ static void setEnv(const std::string& var, throw sys::SystemException(Ctxt( "Unable to set windows environment variable " + var)); } + const auto s = var + "=" + val; - _putenv(s.c_str()); + const auto result = _putenv(s.c_str()); + if (result != 0) // "The functions return 0 if successful, or -1 if there's an error." + { + throw sys::SystemException(Ctxt("Unable to set windows environment variable " + var)); + } + } void sys::OSWin32::setEnv(const std::string& var, const std::string& val, @@ -298,13 +304,18 @@ void sys::OSWin32::setEnv(const std::string& var, void sys::OSWin32::unsetEnv(const std::string& var) { - const BOOL ret = SetEnvironmentVariable(var.c_str(), NULL); + const BOOL ret = SetEnvironmentVariable(var.c_str(), nullptr); if (!ret) { throw sys::SystemException(Ctxt("Unable to unset windows environment variable " + var)); } + const auto s = var + "="; - _putenv(s.c_str()); + const auto result = _putenv(s.c_str()); + if (result != 0) // "The functions return 0 if successful, or -1 if there's an error." + { + throw sys::SystemException(Ctxt("Unable to unset windows environment variable " + var)); + } } size_t sys::OSWin32::getNumCPUs() const @@ -433,7 +444,7 @@ std::string sys::OSWin32::getCurrentExecutable( char buffer[MAX_PATH + 2]; memset(buffer, 0, MAX_PATH + 2); - size_t bytesRead = GetModuleFileName(NULL, buffer, MAX_PATH + 1); + size_t bytesRead = GetModuleFileName(nullptr, buffer, MAX_PATH + 1); if (bytesRead == MAX_PATH + 1 || bytesRead == 0) { diff --git a/modules/c++/sys/source/ResourceCheck.cpp b/modules/c++/sys/source/ResourceCheck.cpp index ab4eacc999..9bfcaea46c 100644 --- a/modules/c++/sys/source/ResourceCheck.cpp +++ b/modules/c++/sys/source/ResourceCheck.cpp @@ -22,6 +22,7 @@ #include #include +#include namespace sys { @@ -40,7 +41,7 @@ size_t getAvailableMem(size_t systemMemBytes, size_t reservedBytes, double margin) { - const auto relativeAvailable = static_cast(systemMemBytes * margin); + const auto relativeAvailable = gsl::narrow_cast(gsl::narrow_cast(systemMemBytes) * margin); if (reservedBytes > systemMemBytes) { return 0; diff --git a/modules/c++/sys/source/ScopedCPUAffinityUnix.cpp b/modules/c++/sys/source/ScopedCPUAffinityUnix.cpp index f56e45e779..2b7fbc8445 100644 --- a/modules/c++/sys/source/ScopedCPUAffinityUnix.cpp +++ b/modules/c++/sys/source/ScopedCPUAffinityUnix.cpp @@ -26,6 +26,7 @@ #include #include +#include #include @@ -51,7 +52,7 @@ void ScopedCPUMaskUnix::initialize(int numCPUs) mSize = CPU_ALLOC_SIZE(numCPUs); mMask = CPU_ALLOC(numCPUs); - if (mMask == NULL) + if (mMask == nullptr) { std::ostringstream msg; msg << "Failed to allocate CPU mask for " << numCPUs << "CPUs"; @@ -84,12 +85,12 @@ std::string ScopedCPUMaskUnix::toString() const int ScopedCPUMaskUnix::getNumOnlineCPUs() { #ifdef _SC_NPROCESSORS_ONLN - const int numOnlineCPUs = sysconf(_SC_NPROCESSORS_ONLN); + const auto numOnlineCPUs = sysconf(_SC_NPROCESSORS_ONLN); if (numOnlineCPUs == -1) { throw except::Exception(Ctxt("Failed to get online CPU count")); } - return numOnlineCPUs; + return gsl::narrow(numOnlineCPUs); #else throw except::NotImplementedException(Ctxt("Unable to get the number of CPUs")); #endif diff --git a/modules/c++/sys/source/SemaphoreWin32.cpp b/modules/c++/sys/source/SemaphoreWin32.cpp index fcfd8255bf..6d136b4b66 100644 --- a/modules/c++/sys/source/SemaphoreWin32.cpp +++ b/modules/c++/sys/source/SemaphoreWin32.cpp @@ -30,11 +30,11 @@ sys::SemaphoreWin32::SemaphoreWin32(unsigned int count, size_t _maxCount) { // Ensure maxCount never becomes negative due to casting between signed/unsigned types - const LONG maxLong = std::numeric_limits::max(); - LONG maxCount = (_maxCount > maxLong) ? maxLong : static_cast(_maxCount); + constexpr auto maxLong = std::numeric_limits::max(); + const auto maxCount = (_maxCount > maxLong) ? maxLong : static_cast(_maxCount); - mNative = CreateSemaphore(NULL, static_cast(count), maxCount, NULL); - if (mNative == NULL) + mNative = CreateSemaphore(nullptr, static_cast(count), maxCount, nullptr); + if (mNative == nullptr) throw sys::SystemException("CreateSemaphore Failed"); } @@ -53,7 +53,7 @@ void sys::SemaphoreWin32::signal() { if (!ReleaseSemaphore(mNative, 1, - NULL) ) + nullptr) ) { throw sys::SystemException("Semaphore signal failed"); } diff --git a/modules/c++/sys/source/StopWatch.cpp b/modules/c++/sys/source/StopWatch.cpp index 81b27ed99f..ca33000107 100644 --- a/modules/c++/sys/source/StopWatch.cpp +++ b/modules/c++/sys/source/StopWatch.cpp @@ -114,7 +114,7 @@ double sys::CPUStopWatch::start() else mStartTime = now; - return ((double)now/mClocksPerMillis); + return static_cast(now)/mClocksPerMillis; } double sys::CPUStopWatch::stop() @@ -128,7 +128,7 @@ double sys::CPUStopWatch::stop() } // If start time was never set (or reset) then don't bother calculating elapsed time if(mStartTime != -1) - return ((double)(end - mStartTime - mTimePaused)/mClocksPerMillis); + return static_cast(end - mStartTime - mTimePaused)/mClocksPerMillis; else return 0; } @@ -140,7 +140,7 @@ double sys::CPUStopWatch::pause() mPauseStartTime = clock(); mPaused = true; } - return ((double)mPauseStartTime/mClocksPerMillis); + return static_cast(mPauseStartTime)/mClocksPerMillis; } void sys::CPUStopWatch::clear() diff --git a/modules/c++/sys/source/ThreadPosix.cpp b/modules/c++/sys/source/ThreadPosix.cpp index 4892ab3961..4ee1f24112 100644 --- a/modules/c++/sys/source/ThreadPosix.cpp +++ b/modules/c++/sys/source/ThreadPosix.cpp @@ -52,7 +52,7 @@ void sys::ThreadPosix::start() if (::pthread_create(&mNative, &attr, - (void *(*)(void *))this->__start, + static_cast(this->__start), this) != 0) throw sys::SystemException("pthread_create()"); pthread_attr_destroy(&attr); @@ -60,8 +60,8 @@ void sys::ThreadPosix::start() else { if (::pthread_create(&mNative, - NULL, - (void *(*)(void *))this->__start, + nullptr, + static_cast(this->__start), this) != 0) throw sys::SystemException("pthread_create()"); } @@ -81,7 +81,7 @@ void *sys::ThreadPosix::__start(void *v) */ pthread_exit(NULL); - return NULL; + return nullptr; } void sys::ThreadPosix::kill() diff --git a/modules/c++/sys/source/ThreadWin32.cpp b/modules/c++/sys/source/ThreadWin32.cpp index 43ee313b65..0b0521b00d 100644 --- a/modules/c++/sys/source/ThreadWin32.cpp +++ b/modules/c++/sys/source/ThreadWin32.cpp @@ -39,13 +39,13 @@ void sys::ThreadWin32::start() { DWORD threadId; - mNative = __CREATETHREAD(NULL, + mNative = __CREATETHREAD(nullptr, 0, __start, (void*)this, 0, &threadId); - if (mNative == NULL) + if (mNative == nullptr) throw sys::SystemException("Thread creation failed"); diff --git a/modules/c++/sys/source/UTCDateTime.cpp b/modules/c++/sys/source/UTCDateTime.cpp index 36a166ee97..1ed9951210 100644 --- a/modules/c++/sys/source/UTCDateTime.cpp +++ b/modules/c++/sys/source/UTCDateTime.cpp @@ -49,7 +49,7 @@ const int DAYS_PER_YEAR[2] = {365, 366}; // Returns the appropriate index into CUMULATIVE_DAYS_PER_MONTH based on // whether 'year' is a leap year or not -int yearIndex(int year) +constexpr int yearIndex(int year) { return (!(year % 4) && ((year % 100) || !(year % 400))); } diff --git a/modules/c++/sys/source/sys_Backtrace.cpp b/modules/c++/sys/source/sys_Backtrace.cpp index 13098be08b..ce5bdb03e8 100644 --- a/modules/c++/sys/source/sys_Backtrace.cpp +++ b/modules/c++/sys/source/sys_Backtrace.cpp @@ -24,7 +24,7 @@ std::string sys::getBacktrace(bool* pSupported) { - bool supported; + bool supported = false; std::vector frames; bool& supported_ = pSupported != nullptr ? *pSupported : supported; return getBacktrace(supported_, frames); diff --git a/modules/c++/sys/tests/DLLTest.cpp b/modules/c++/sys/tests/DLLTest.cpp index dcaa92a44a..1e37e2587f 100644 --- a/modules/c++/sys/tests/DLLTest.cpp +++ b/modules/c++/sys/tests/DLLTest.cpp @@ -46,7 +46,7 @@ int main(int argc, char** argv) DLL dso(dsoPath); - HOOK_FN theHook = (HOOK_FN) dso.retrieve(hook); + auto theHook = reinterpret_cast(dso.retrieve(hook)); // Call the hook if (!theHook()) diff --git a/modules/c++/tiff/source/IFD.cpp b/modules/c++/tiff/source/IFD.cpp index 96de554d58..fb145461db 100644 --- a/modules/c++/tiff/source/IFD.cpp +++ b/modules/c++/tiff/source/IFD.cpp @@ -53,7 +53,7 @@ tiff::IFDEntry *tiff::IFD::operator[](unsigned short tag) // not exist. This is to make sure that the map doesn't get full // of invalid key/value pairs if you're just trying to verify whether // a key already exists of not. - return exists(tag) ? mIFD[tag] : NULL; + return exists(tag) ? mIFD[tag] : nullptr; } const tiff::IFDEntry* tiff::IFD::operator[](unsigned short tag) const { @@ -123,7 +123,7 @@ void tiff::IFD::serialize(io::OutputStream& output) { io::Seekable *seekable = dynamic_cast(&output); - if (seekable == NULL) + if (seekable == nullptr) throw except::Exception(Ctxt("Can only serialize IFD to seekable stream")); // Makes sure all data offsets are defined for each entry. diff --git a/modules/c++/tiff/source/IFDEntry.cpp b/modules/c++/tiff/source/IFDEntry.cpp index bb05316af7..1ac612aeac 100644 --- a/modules/c++/tiff/source/IFDEntry.cpp +++ b/modules/c++/tiff/source/IFDEntry.cpp @@ -38,7 +38,7 @@ void tiff::IFDEntry::serialize(io::OutputStream& output) { io::Seekable *seekable = dynamic_cast(&output); - if (seekable == NULL) + if (seekable == nullptr) throw except::Exception(Ctxt("Can only serialize IFDEntry to seekable stream")); output.write((sys::byte *)&mTag, sizeof(mTag)); @@ -88,7 +88,7 @@ void tiff::IFDEntry::deserialize(io::InputStream& input, const bool reverseBytes { io::Seekable *seekable = dynamic_cast(&input); - if (seekable == NULL) + if (seekable == nullptr) throw except::Exception(Ctxt("Can only deserialize IFDEntry from seekable stream")); input.read((char *)&mTag, sizeof(mTag)); diff --git a/modules/c++/tiff/source/ImageWriter.cpp b/modules/c++/tiff/source/ImageWriter.cpp index 284ffd52f0..d293fed738 100644 --- a/modules/c++/tiff/source/ImageWriter.cpp +++ b/modules/c++/tiff/source/ImageWriter.cpp @@ -210,7 +210,7 @@ void tiff::ImageWriter::validate() // if (mGeoTIFFReader) // { - // tiff::IFDEntry *entry = NULL; + // tiff::IFDEntry *entry = nullptr; // if ((entry = (*mGeoTIFFReader)["ModelPixelScaleTag"])) // mIFD.addEntry(entry); // if ((entry = (*mGeoTIFFReader)["ModelTiepointTag"])) diff --git a/modules/c++/tiff/source/KnownTags.cpp b/modules/c++/tiff/source/KnownTags.cpp index 946818b279..60b3290794 100644 --- a/modules/c++/tiff/source/KnownTags.cpp +++ b/modules/c++/tiff/source/KnownTags.cpp @@ -161,6 +161,6 @@ tiff::IFDEntry *tiff::KnownTags::operator[] (const unsigned short tagKey) { std::map::iterator pos = mKnownTags.find(tagKey); - return pos != mKnownTags.end() ? pos->second : NULL; + return pos != mKnownTags.end() ? pos->second : nullptr; } diff --git a/modules/c++/tiff/source/TypeFactory.cpp b/modules/c++/tiff/source/TypeFactory.cpp index 5f5715a6cb..1e7f52b2a7 100644 --- a/modules/c++/tiff/source/TypeFactory.cpp +++ b/modules/c++/tiff/source/TypeFactory.cpp @@ -28,7 +28,7 @@ tiff::TypeInterface *tiff::TypeFactory::create(const unsigned char *data, const unsigned short type) { - tiff::TypeInterface *tiffType = NULL; + tiff::TypeInterface* tiffType = nullptr; switch (type) { case tiff::Const::Type::BYTE: diff --git a/modules/c++/tiff/source/Utils.cpp b/modules/c++/tiff/source/Utils.cpp index 59de597e3b..ff6e60d044 100644 --- a/modules/c++/tiff/source/Utils.cpp +++ b/modules/c++/tiff/source/Utils.cpp @@ -30,7 +30,7 @@ bool tiff::Utils::hasGeoTiffIFD(const tiff::IFD* ifd) tiff::IFD* tiff::Utils::createGeoTiffIFD(tiff::IFD* ifd) { if (!tiff::Utils::hasGeoTiffIFD(ifd)) - return NULL; + return nullptr; std::map keyMap; keyMap[1024] = "GTModelTypeGeoKey"; @@ -85,10 +85,10 @@ tiff::IFD* tiff::Utils::createGeoTiffIFD(tiff::IFD* ifd) tiff::IFDEntry *geoDir = (*ifd)["GeoKeyDirectoryTag"]; tiff::IFDEntry* const doubleParams = ifd->exists("GeoDoubleParamsTag") ? (*ifd)["GeoDoubleParamsTag"] - : NULL; + : nullptr; tiff::IFDEntry* const asciiParams = ifd->exists("GeoAsciiParamsTag") ? (*ifd)["GeoAsciiParamsTag"] - : NULL; + : nullptr; std::vector geoVals = geoDir->getValues(); size_t idx = 0; diff --git a/modules/c++/types/include/types/PageRowCol.h b/modules/c++/types/include/types/PageRowCol.h index 1900d23d62..5c4b5ce280 100644 --- a/modules/c++/types/include/types/PageRowCol.h +++ b/modules/c++/types/include/types/PageRowCol.h @@ -52,7 +52,7 @@ struct PageRowCol // especially when doing scalar operations that might otherwise // create ambiguities PageRowCol() : - page((T)0.0), row((T)0.0), col((T)0.0) {} + page(static_cast(0.0)), row(static_cast(0.0)), col(static_cast(0.0)) {} PageRowCol(T p, T r, T c) : @@ -61,17 +61,17 @@ struct PageRowCol template explicit PageRowCol(const PageRowCol& p) { - page = (T)p.page; - row = (T)p.row; - col = (T)p.col; + page = static_cast(p.page); + row = static_cast(p.row); + col = static_cast(p.col); } template PageRowCol(Other_T1 p, const RowCol& rc) { - page = (T)p; - row = (T)rc.row; - col = (T)rc.col; + page = static_cast(p); + row = static_cast(rc.row); + col = static_cast(rc.col); } template @@ -79,9 +79,9 @@ struct PageRowCol { if (this != (PageRowCol*)&p) { - page = (T)p.page; - row = (T)p.row; - col = (T)p.col; + page = static_cast(p.page); + row = static_cast(p.row); + col = static_cast(p.col); } return *this; } @@ -89,9 +89,9 @@ struct PageRowCol template PageRowCol& operator+=(const PageRowCol& p) { - page += (T)p.page; - row += (T)p.row; - col += (T)p.col; + page += static_cast(p.page); + row += static_cast(p.row); + col += static_cast(p.col); return *this; } @@ -105,9 +105,9 @@ struct PageRowCol template PageRowCol& operator*=(const PageRowCol& p) { - page *= (T)p.page; - row *= (T)p.row; - col *= (T)p.col; + page *= static_cast(p.page); + row *= static_cast(p.row); + col *= static_cast(p.col); return *this; } @@ -121,9 +121,9 @@ struct PageRowCol template PageRowCol& operator-=(const PageRowCol& p) { - page -= (T)p.page; - row -= (T)p.row; - col -= (T)p.col; + page -= static_cast(p.page); + row -= static_cast(p.row); + col -= static_cast(p.col); return *this; } @@ -137,9 +137,9 @@ struct PageRowCol template PageRowCol& operator/=(const PageRowCol& p) { - page /= (T)p.page; - row /= (T)p.row; - col /= (T)p.col; + page /= static_cast(p.page); + row /= static_cast(p.row); + col /= static_cast(p.col); return *this; } diff --git a/modules/c++/types/include/types/RowCol.h b/modules/c++/types/include/types/RowCol.h index 1b55265cab..e13f125a2e 100644 --- a/modules/c++/types/include/types/RowCol.h +++ b/modules/c++/types/include/types/RowCol.h @@ -50,9 +50,8 @@ namespace types template class RowCol { template - static U cast(const Other_T& t) + static U cast(const Other_T& t) noexcept { - //return static_cast(t); return gsl::narrow_cast(t); } diff --git a/modules/c++/types/unittests/test_page_row_col.cpp b/modules/c++/types/unittests/test_page_row_col.cpp index edf926bab8..a2e6702cb7 100644 --- a/modules/c++/types/unittests/test_page_row_col.cpp +++ b/modules/c++/types/unittests/test_page_row_col.cpp @@ -97,8 +97,8 @@ TEST_CASE(TestPageRowColDouble) pageRowColAssign.page += std::numeric_limits::epsilon() * 2.0; TEST_ASSERT(pageRowColAssign != pageRowColA); - TEST_ASSERT_EQ(pageRowColA.volume(), 3.1 * 5.2 * 11.3); - TEST_ASSERT_EQ(pageRowColA.normL2(), std::sqrt(3.1 * 3.1 + 5.2 * 5.2 + 11.3 * 11.3)); + TEST_ASSERT_ALMOST_EQ(pageRowColA.volume(), 3.1 * 5.2 * 11.3); + TEST_ASSERT_ALMOST_EQ(pageRowColA.normL2(), std::sqrt(3.1 * 3.1 + 5.2 * 5.2 + 11.3 * 11.3)); // test arithmetic operators const types::PageRowCol sum = pageRowColA + pageRowColB; diff --git a/modules/c++/unique/source/UUID.cpp b/modules/c++/unique/source/UUID.cpp index 682dac8433..0a79a77d97 100644 --- a/modules/c++/unique/source/UUID.cpp +++ b/modules/c++/unique/source/UUID.cpp @@ -32,7 +32,7 @@ std::string unique::generateUUID() { #ifdef _WIN32 GUID uuid; - unsigned char *cResult = NULL; + unsigned char* cResult = nullptr; if ((UuidCreateSequential (&uuid) != RPC_S_OK) || (UuidToString(&uuid, &cResult) != RPC_S_OK)) diff --git a/modules/c++/unique/wscript b/modules/c++/unique/wscript index ffaf6c7239..bd30e6da78 100644 --- a/modules/c++/unique/wscript +++ b/modules/c++/unique/wscript @@ -1,5 +1,4 @@ NAME = 'unique' -MAINTAINER = 'jmrandol@users.sourceforge.net' VERSION = '1.0' MODULE_DEPS = 'except' USELIB = 'RPC' diff --git a/modules/c++/xml.lite/include/xml/lite/Attributes.h b/modules/c++/xml.lite/include/xml/lite/Attributes.h index b8823164d4..8dac07f8f6 100644 --- a/modules/c++/xml.lite/include/xml/lite/Attributes.h +++ b/modules/c++/xml.lite/include/xml/lite/Attributes.h @@ -20,19 +20,21 @@ * */ +#pragma once #ifndef CODA_OSS_xml_lite_Attributes_h_INCLUDED_ #define CODA_OSS_xml_lite_Attributes_h_INCLUDED_ -#pragma once #include #include +#include + #include "sys/Conf.h" #include "except/Exception.h" -#include "xml/lite/QName.h" #include "str/Convert.h" #include "gsl/gsl.h" +#include "xml/lite/QName.h" /*! * \file Attributes.h * \brief Implementation of SAX 2.0 Attributes @@ -55,7 +57,7 @@ namespace lite * internal organs. We have a URI, a QName, and a local part * as well. We also need a value, of course. */ -struct AttributeNode final +struct CODA_OSS_API AttributeNode final { AttributeNode() = default; @@ -158,7 +160,7 @@ struct AttributeNode final * this data structure everywhere. That also allows us to * simplify future dom classes */ -struct Attributes final +struct CODA_OSS_API Attributes final { typedef std::vector Attributes_T; //! Default constructor diff --git a/modules/c++/xml.lite/include/xml/lite/ContentHandler.h b/modules/c++/xml.lite/include/xml/lite/ContentHandler.h index 9e03adeaeb..f7e8da6f0a 100644 --- a/modules/c++/xml.lite/include/xml/lite/ContentHandler.h +++ b/modules/c++/xml.lite/include/xml/lite/ContentHandler.h @@ -20,9 +20,9 @@ * */ +#pragma once #ifndef CODA_OSS_xml_lite_ContentHandler_h_INCLUDED_ #define CODA_OSS_xml_lite_ContentHandler_h_INCLUDED_ -#pragma once #include #include @@ -30,6 +30,8 @@ #include #include +#include + #include "xml/lite/QName.h" // Uri #include "xml/lite/Attributes.h" @@ -68,12 +70,12 @@ namespace lite * which should increase performance and efficiency. */ -class ContentHandler +class CODA_OSS_API ContentHandler { protected: //! Constructor ContentHandler() = default; - virtual ~ContentHandler() = default; + virtual ~ContentHandler() noexcept(false) {} public: //! Receive notification of the beginning of a document. diff --git a/modules/c++/xml.lite/include/xml/lite/Document.h b/modules/c++/xml.lite/include/xml/lite/Document.h index 76ab1dd13a..6d6bdf2664 100644 --- a/modules/c++/xml.lite/include/xml/lite/Document.h +++ b/modules/c++/xml.lite/include/xml/lite/Document.h @@ -20,9 +20,9 @@ * */ +#pragma once #ifndef CODA_OSS_xml_lite_Doocument_h_INCLUDED_ #define CODA_OSS_xml_lite_Doocument_h_INCLUDED_ -#pragma once /*! * \file Document.h @@ -42,6 +42,8 @@ #include #include "coda_oss/string.h" +#include + #include "xml/lite/Element.h" #include "xml/lite/QName.h" @@ -56,7 +58,7 @@ namespace lite * Use the Document to access the Element nodes contained within. * The DocumentParser will build a tree that you can use. */ -struct Document // SOAPDocument derives :-( +struct CODA_OSS_API Document // SOAPDocument derives :-( { //! Constructor Document(Element* rootNode = nullptr, bool own = true) : diff --git a/modules/c++/xml.lite/include/xml/lite/Element.h b/modules/c++/xml.lite/include/xml/lite/Element.h index 911a50f864..14e23a900e 100644 --- a/modules/c++/xml.lite/include/xml/lite/Element.h +++ b/modules/c++/xml.lite/include/xml/lite/Element.h @@ -20,9 +20,9 @@ * */ +#pragma once #ifndef CODA_OSS_xml_lite_Element_h_INCLUDED_ #define CODA_OSS_xml_lite_Element_h_INCLUDED_ -#pragma once #include #include @@ -30,15 +30,17 @@ #include #include +#include #include #include #include #include +#include "sys/Conf.h" +#include "mem/SharedPtr.h" + #include "xml/lite/XMLException.h" #include "xml/lite/Attributes.h" #include "xml/lite/QName.h" -#include "sys/Conf.h" -#include "mem/SharedPtr.h" /*! * \file Element.h @@ -63,7 +65,7 @@ struct AttributeNode; * This class stores all of the element information about an XML * document. */ -struct Element // SOAPElement derives :-( +struct CODA_OSS_API Element // SOAPElement derives :-( { Element() = default; @@ -597,28 +599,28 @@ inline Element* addNewOptionalElement(const xml::lite::QName& name, const coda_o #endif // SWIG -Element& setChild(Element&, std::unique_ptr&&); // destroyChildren() + addChild() +CODA_OSS_API Element& setChild(Element&, std::unique_ptr&&); // destroyChildren() + addChild() -void operator+=(Element&, std::unique_ptr&&); // addChild() +CODA_OSS_API void operator+=(Element&, std::unique_ptr&&); // addChild() -Element& addChild(Element&, const std::string& qname); -void operator+=(Element&, const std::string& qname); // addChild() -Element& addChild(Element&, const xml::lite::QName&); // there is also a QName in the xerces namespace -void operator+=(Element&, const xml::lite::QName&); // addChild() -Element& addChild(Element&, const std::string& qname, const coda_oss::u8string& characterData); +CODA_OSS_API Element& addChild(Element&, const std::string& qname); +CODA_OSS_API void operator+=(Element&, const std::string& qname); // addChild() +CODA_OSS_API Element& addChild(Element&, const xml::lite::QName&); // there is also a QName in the xerces namespace +CODA_OSS_API void operator+=(Element&, const xml::lite::QName&); // addChild() +CODA_OSS_API Element& addChild(Element&, const std::string& qname, const coda_oss::u8string& characterData); Element& addChild(Element&, const std::string&, const std::string&) = delete; // NO, order matters! -Element& addChild(Element&, const xml::lite::QName&, const coda_oss::u8string& characterData); -Element& addChild(Element&, const xml::lite::QName&, const std::string& characterData); -Element& addChild(Element&, const std::string& qname, const xml::lite::Uri&); -Element& addChild(Element&, const std::string& qname, const xml::lite::Uri&, const coda_oss::u8string& characterData); - -coda_oss::u8string getCharacterData(const Element&); - -xml::lite::AttributeNode& addAttribute(Element&, const xml::lite::AttributeNode&); -void operator+=(Element&, const xml::lite::AttributeNode&); // addAttribute() -xml::lite::AttributeNode& addAttribute(Element&, const std::string& qname); -xml::lite::AttributeNode& addAttribute(Element&, const xml::lite::QName&); -xml::lite::AttributeNode& addAttribute(Element&, const xml::lite::QName&, const std::string& value); +CODA_OSS_API Element& addChild(Element&, const xml::lite::QName&, const coda_oss::u8string& characterData); +CODA_OSS_API Element& addChild(Element&, const xml::lite::QName&, const std::string& characterData); +CODA_OSS_API Element& addChild(Element&, const std::string& qname, const xml::lite::Uri&); +CODA_OSS_API Element& addChild(Element&, const std::string& qname, const xml::lite::Uri&, const coda_oss::u8string& characterData); + +CODA_OSS_API coda_oss::u8string getCharacterData(const Element&); + +CODA_OSS_API xml::lite::AttributeNode& addAttribute(Element&, const xml::lite::AttributeNode&); +CODA_OSS_API void operator+=(Element&, const xml::lite::AttributeNode&); // addAttribute() +CODA_OSS_API xml::lite::AttributeNode& addAttribute(Element&, const std::string& qname); +CODA_OSS_API xml::lite::AttributeNode& addAttribute(Element&, const xml::lite::QName&); +CODA_OSS_API xml::lite::AttributeNode& addAttribute(Element&, const xml::lite::QName&, const std::string& value); xml::lite::AttributeNode& addAttribute(Element&, const std::string&, const std::string&) = delete; // NO, order matters! } diff --git a/modules/c++/xml.lite/include/xml/lite/MinidomHandler.h b/modules/c++/xml.lite/include/xml/lite/MinidomHandler.h index e8d9e25678..ac9590662b 100644 --- a/modules/c++/xml.lite/include/xml/lite/MinidomHandler.h +++ b/modules/c++/xml.lite/include/xml/lite/MinidomHandler.h @@ -20,9 +20,9 @@ * */ +#pragma once #ifndef CODA_OSS_xml_lite_MinidomHandler_h_INCLUDED_ #define CODA_OSS_xml_lite_MinidomHandler_h_INCLUDED_ -#pragma once /*! * \file MinidomHandler.h @@ -49,6 +49,7 @@ #include #include "coda_oss/string.h" +#include #include "str/EncodedString.h" #include "str/EncodedStringView.h" #include "XMLReader.h" @@ -68,7 +69,7 @@ namespace lite * whether it is allocated externally or not. DONT delete it * explicitly unless you are looking for disaster. */ -struct MinidomHandler final : public ContentHandler +struct CODA_OSS_API MinidomHandler final : public ContentHandler { //! Constructor. Uses default document MinidomHandler() @@ -77,7 +78,7 @@ struct MinidomHandler final : public ContentHandler } //! Destructor - ~ MinidomHandler() + ~MinidomHandler() noexcept(false) { setDocument(nullptr, true); } diff --git a/modules/c++/xml.lite/include/xml/lite/MinidomParser.h b/modules/c++/xml.lite/include/xml/lite/MinidomParser.h index a701e70dd5..9fd151ab11 100644 --- a/modules/c++/xml.lite/include/xml/lite/MinidomParser.h +++ b/modules/c++/xml.lite/include/xml/lite/MinidomParser.h @@ -20,12 +20,13 @@ * */ +#pragma once #ifndef CODA_OSS_xml_lite_MinidomParser_h_INCLUDED_ #define CODA_OSS_xml_lite_MinidomParser_h_INCLUDED_ -#pragma once #include +#include #include "xml/lite/XMLReader.h" #include "xml/lite/Document.h" @@ -56,7 +57,7 @@ namespace lite * bloat of the spec. It was inspired by python's xml.dom.minidom * module. */ -struct MinidomParser // SOAPParser inherits :-( +struct CODA_OSS_API MinidomParser // SOAPParser inherits :-( { /*! * Constructor. Set our SAX ContentHandler. diff --git a/modules/c++/xml.lite/include/xml/lite/QName.h b/modules/c++/xml.lite/include/xml/lite/QName.h index 78fc2fb616..b537b5262d 100644 --- a/modules/c++/xml.lite/include/xml/lite/QName.h +++ b/modules/c++/xml.lite/include/xml/lite/QName.h @@ -20,11 +20,11 @@ * */ +#pragma once #ifndef CODA_OSS_xml_lite_QName_h_INCLLUDED_ #define CODA_OSS_xml_lite_QName_h_INCLLUDED_ -#pragma once -/*! + /*! * \file QName.h * \brief A Qualified name (includes the namespace stuff) * @@ -42,6 +42,8 @@ #include #include +#include + #include "sys/OS.h" #include "str/Manip.h" @@ -66,7 +68,7 @@ namespace lite * to a namespace URI */ -struct Uri final // help prevent mixups with std::string +struct CODA_OSS_API Uri final // help prevent mixups with std::string { Uri(); explicit Uri(const std::string& v); // validate=false @@ -93,7 +95,7 @@ inline std::ostream& operator<<(std::ostream& os, const Uri& uri) return os; } -class QName final +class CODA_OSS_API QName final { //! Prefix (Qualified) std::string mPrefix; diff --git a/modules/c++/xml.lite/include/xml/lite/Serializable.h b/modules/c++/xml.lite/include/xml/lite/Serializable.h index a1e486447c..3a6da62e51 100644 --- a/modules/c++/xml.lite/include/xml/lite/Serializable.h +++ b/modules/c++/xml.lite/include/xml/lite/Serializable.h @@ -58,7 +58,7 @@ struct Serializable : public io::Serializable } //! Destructor - virtual ~Serializable() {} + virtual ~Serializable() noexcept(false) {} Serializable(const Serializable&) = delete; Serializable& operator=(const Serializable&) = delete; @@ -94,13 +94,13 @@ struct Serializable : public io::Serializable * Transfer this object into a byte stream * \param os The object to serialize this to */ - virtual void serialize(io::OutputStream& os); + void serialize(io::OutputStream& os) override; /*! * Unpack this input stream to the object * \param is Stream to read object from */ - virtual void deserialize(io::InputStream& is); + void deserialize(io::InputStream& is) override; protected: //! The parser diff --git a/modules/c++/xml.lite/include/xml/lite/UtilitiesXerces.h b/modules/c++/xml.lite/include/xml/lite/UtilitiesXerces.h index ba587a91be..ef20391231 100644 --- a/modules/c++/xml.lite/include/xml/lite/UtilitiesXerces.h +++ b/modules/c++/xml.lite/include/xml/lite/UtilitiesXerces.h @@ -20,6 +20,7 @@ * */ +#pragma once #ifndef CODA_OSS_xml_lite_UtilitiesXerces_h_INCLUDED_ #define CODA_OSS_xml_lite_UtilitiesXerces_h_INCLUDED_ @@ -30,34 +31,7 @@ #include #include "config/compiler_extensions.h" -#include "xml/lite/xml_lite_config.h" - -#if defined(USE_XERCES) - -CODA_OSS_disable_warning_system_header_push -#include -#include -#include -#include -#include -#include - -#include -#include - -#include - -#include -#include -#include -#include -#include -#include - -#include -#include - -CODA_OSS_disable_warning_pop +#include "config/Exports.h" #include #include @@ -66,6 +40,10 @@ CODA_OSS_disable_warning_pop #include #include +#include +#if defined(USE_XERCES) +#include "xerces_.h" + #include "xml/lite/XMLException.h" #include "xml/lite/ContentHandler.h" #include "xml/lite/Attributes.h" @@ -429,7 +407,7 @@ struct XercesErrorHandler final : public XercesErrorHandlerInterface_T * \class XercesContext * \brief This class safely creates and destroys Xerces */ -struct XercesContext final +struct CODA_OSS_API XercesContext final { //! Constructor XercesContext(); diff --git a/modules/c++/xml.lite/include/xml/lite/ValidatorInterface.h b/modules/c++/xml.lite/include/xml/lite/ValidatorInterface.h index c8066b1b17..4e50656eff 100644 --- a/modules/c++/xml.lite/include/xml/lite/ValidatorInterface.h +++ b/modules/c++/xml.lite/include/xml/lite/ValidatorInterface.h @@ -20,9 +20,9 @@ * */ +#pragma once #ifndef CODA_OSS_xml_lite_ValidatorInterface_h_INCLUDED_ #define CODA_OSS_xml_lite_ValidatorInterface_h_INCLUDED_ -#pragma once /*! * \file ValidatorInterface.h @@ -35,14 +35,17 @@ #include #include +#include + +#include #include #include #include #include +#include + #include #include -#include -#include namespace xml { @@ -94,7 +97,7 @@ struct ValidationInfo final * * This class is the interface for schema validators */ -class ValidatorInterface +class CODA_OSS_API ValidatorInterface { public: @@ -184,4 +187,4 @@ inline std::ostream& operator<< (std::ostream& out, } } -#endif // CODA_OSS_xml_lite_ValidatorInterface_h_INCLUDED_ \ No newline at end of file +#endif // CODA_OSS_xml_lite_ValidatorInterface_h_INCLUDED_ diff --git a/modules/c++/xml.lite/include/xml/lite/ValidatorXerces.h b/modules/c++/xml.lite/include/xml/lite/ValidatorXerces.h index 3cdde68844..8d5d79ba0b 100644 --- a/modules/c++/xml.lite/include/xml/lite/ValidatorXerces.h +++ b/modules/c++/xml.lite/include/xml/lite/ValidatorXerces.h @@ -20,30 +20,22 @@ * */ +#pragma once #ifndef CODA_OSS_xml_lite_ValidatorXerces_h_INCLUDED_ #define CODA_OSS_xml_lite_ValidatorXerces_h_INCLUDED_ -#include - -#ifdef USE_XERCES - #include #include #include -#include -#include +#include "config/Exports.h" -#include -#include -#include -#include -#include -#include +#include +#ifdef USE_XERCES +#include "xerces_.h" -#include -#include -#include +#include +#include namespace xml { @@ -97,7 +89,7 @@ struct ValidationErrorHandler final : public xercesc::DOMErrorHandler * * This class is the Xercesc schema validator */ -class ValidatorXerces : public ValidatorInterface +class CODA_OSS_API ValidatorXerces : public ValidatorInterface { XercesContext mCtxt; //! this must be the first member listed diff --git a/modules/c++/xml.lite/include/xml/lite/XMLReaderInterface.h b/modules/c++/xml.lite/include/xml/lite/XMLReaderInterface.h index c0540b8cbe..f39bb47eaf 100644 --- a/modules/c++/xml.lite/include/xml/lite/XMLReaderInterface.h +++ b/modules/c++/xml.lite/include/xml/lite/XMLReaderInterface.h @@ -20,17 +20,21 @@ * */ -#ifndef __XML_LITE_ABSTRACT_XML_READER_H__ -#define __XML_LITE_ABSTRACT_XML_READER_H__ +#pragma once +#ifndef CODA_OSS_xml_lite_XMLReaderInterface_h_INCLUDED_ +#define CODA_OSS_xml_lite_XMLReaderInterface_h_INCLUDED_ #include + +#include + #include "XMLException.h" namespace xml { namespace lite { -class XMLReaderInterface : public io::OutputStream +class CODA_OSS_API XMLReaderInterface : public io::OutputStream { public: @@ -77,4 +81,4 @@ class XMLReaderInterface : public io::OutputStream } } -#endif +#endif // CODA_OSS_xml_lite_XMLReaderInterface_h_INCLUDED_ diff --git a/modules/c++/xml.lite/include/xml/lite/XMLReaderXerces.h b/modules/c++/xml.lite/include/xml/lite/XMLReaderXerces.h index 52b78befbc..a808be8d86 100644 --- a/modules/c++/xml.lite/include/xml/lite/XMLReaderXerces.h +++ b/modules/c++/xml.lite/include/xml/lite/XMLReaderXerces.h @@ -20,6 +20,7 @@ * */ +#pragma once #ifndef CODA_OSS_xml_lite_XMLReaderXerces_h_INCLUDED_ #define CODA_OSS_xml_lite_XMLReaderXerces_h_INCLUDED_ @@ -29,6 +30,8 @@ #include +#include + #include #include #include @@ -56,7 +59,7 @@ namespace lite * the Expat C Parser underneath, and wiring it to * generic event calls, via the content handler. */ -class XMLReaderXerces final : public XMLReaderInterface +class CODA_OSS_API XMLReaderXerces final : public XMLReaderInterface { XercesContext mCtxt; //! this must be the first member listed std::unique_ptr mNative; diff --git a/modules/c++/xml.lite/include/xml/lite/xerces_.h b/modules/c++/xml.lite/include/xml/lite/xerces_.h new file mode 100644 index 0000000000..51d2ca436f --- /dev/null +++ b/modules/c++/xml.lite/include/xml/lite/xerces_.h @@ -0,0 +1,97 @@ +/* ========================================================================= + * This file is part of xml.lite-c++ + * ========================================================================= + * + * (C) Copyright 2004 - 2014, MDA Information Systems LLC + * + * xml.lite-c++ is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; If not, + * see . + * + */ + +#pragma once +#ifndef CODA_OSS_xml_lite_xerces_h_INCLUDED_ +#define CODA_OSS_xml_lite_xerces_h_INCLUDED_ + +#include "config/compiler_extensions.h" +#include + +#if defined(USE_XERCES) + +CODA_OSS_disable_warning_system_header_push +#if _MSC_VER +#pragma warning(disable: 26493) // Don't use C-style casts (type.4). +#pragma warning(disable: 26494) // Variable '...' is uninitialized. Always initialize an object (type.5). +#pragma warning(disable: 26451) // Arithmetic overflow: Using operator '...' on a 4 byte value and then casting the result to a 8 byte value. Cast the value to the wider type before calling operator '...' to avoid overflow (io.2). +#pragma warning(disable: 26814) // The const variable '...' can be computed at compile-time. Consider using constexpr (con.5). +#pragma warning(disable: 26447) // The function is declared '...' but calls function '...' which may throw exceptions (f.6). +#pragma warning(disable: 26455) // Default constructor should not throw. Declare it '...' (f.6). +#pragma warning(disable: 26440) // Function '...' can be declared '...' (f.6). +#pragma warning(disable: 26496) // The variable '...' does not change after construction, mark it as const (con.4). +#pragma warning(disable: 26462) // The value pointed to by '...' is assigned only once, mark it as a pointer to const (con.4). +#pragma warning(disable: 26435) // Function '...' should specify exactly one of '...', '...', or '...' (c.128). +#pragma warning(disable: 26433) // Function '...' should be marked with '...' (c.128). +#pragma warning(disable: 26497) // You can attempt to make '...' constexpr unless it contains any undefined behavior (f.4). +#pragma warning(disable: 26433) // Function '...' should be marked with '...' (c.128). +#pragma warning(disable: 26456) // Operator '...' hides a non-virtual operator '...' (c.128). +#pragma warning(disable: 26446) // Prefer to use gsl::at() instead of unchecked subscript operator (bounds.4). +#pragma warning(disable: 26488) // Do not dereference a potentially null pointer: '...'. '...' was null at line 133 (lifetime.1). +#pragma warning(disable : 26477) // Use '...' rather than 0 or NULL(es .47). +#pragma warning(disable: 26457) // (void) should not be used to ignore return values, use '...' instead (es.48). +#pragma warning(disable: 26475) // Do not use function style casts (es.49). Prefer '...' over '...'.. +#else +CODA_OSS_disable_warning(-Wshadow) +CODA_OSS_disable_warning(-Wsuggest-override) +CODA_OSS_disable_warning(-Wzero-as-null-pointer-constant) +#endif + +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +CODA_OSS_disable_warning_pop + +#endif + +#endif // CODA_OSS_xml_lite_xerces_h_INCLUDED_ + diff --git a/modules/c++/xml.lite/source/Document.cpp b/modules/c++/xml.lite/source/Document.cpp index 20fec58da3..3e61a3af7b 100644 --- a/modules/c++/xml.lite/source/Document.cpp +++ b/modules/c++/xml.lite/source/Document.cpp @@ -43,7 +43,7 @@ void xml::lite::Document::remove(Element * toDelete) { if (mRootNode && mOwnRoot) delete mRootNode; - mRootNode = NULL; + mRootNode = nullptr; } else remove(toDelete, mRootNode); @@ -88,14 +88,14 @@ std::unique_ptr xml::lite::Document::createElement(const QNa void xml::lite::Document::insert(xml::lite::Element * element, xml::lite::Element * underThis) { - if (element != NULL && underThis != NULL) + if (element != nullptr && underThis != nullptr) underThis->addChild(element); } void xml::lite::Document::remove(xml::lite::Element * toDelete, xml::lite::Element * fromHere) { - if (fromHere != NULL && toDelete != NULL) + if (fromHere != nullptr && toDelete != nullptr) { for (std::vector::iterator i = fromHere->getChildren().begin(); i @@ -105,7 +105,7 @@ void xml::lite::Document::remove(xml::lite::Element * toDelete, { fromHere->getChildren().erase(i); delete toDelete; - toDelete = NULL; + toDelete = nullptr; return; } else diff --git a/modules/c++/xml.lite/source/Element.cpp b/modules/c++/xml.lite/source/Element.cpp index ddb7177d81..150588e5e4 100644 --- a/modules/c++/xml.lite/source/Element.cpp +++ b/modules/c++/xml.lite/source/Element.cpp @@ -19,6 +19,7 @@ * see . * */ +#include "xml/lite/Element.h" #include @@ -26,7 +27,6 @@ #include #include -#include "xml/lite/Element.h" #include #include #include @@ -69,7 +69,7 @@ void xml::lite::Element::clone(const xml::lite::Element& node) *this = node; clearChildren(); - mParent = NULL; + mParent = nullptr; std::vector::const_iterator iter; iter = node.getChildren().begin(); diff --git a/modules/c++/xml.lite/source/MinidomHandler.cpp b/modules/c++/xml.lite/source/MinidomHandler.cpp index fe33084b70..3e2e1334cd 100644 --- a/modules/c++/xml.lite/source/MinidomHandler.cpp +++ b/modules/c++/xml.lite/source/MinidomHandler.cpp @@ -34,7 +34,7 @@ void xml::lite::MinidomHandler::setDocument(Document *newDocument, bool own) { - if (mDocument != NULL && mOwnDocument) + if (mDocument != nullptr && mOwnDocument) { if (newDocument != mDocument) delete mDocument; diff --git a/modules/c++/xml.lite/source/QName.cpp b/modules/c++/xml.lite/source/QName.cpp index 1893cf4a32..5ce60dfff7 100644 --- a/modules/c++/xml.lite/source/QName.cpp +++ b/modules/c++/xml.lite/source/QName.cpp @@ -19,10 +19,10 @@ * see . * */ +#include "xml/lite/QName.h" #include -#include "xml/lite/QName.h" #include "str/Manip.h" std::string xml::lite::QName::getName() const diff --git a/modules/c++/xml.lite/source/Serializable.cpp b/modules/c++/xml.lite/source/Serializable.cpp index c03969ee38..d5f55479ce 100644 --- a/modules/c++/xml.lite/source/Serializable.cpp +++ b/modules/c++/xml.lite/source/Serializable.cpp @@ -25,7 +25,7 @@ void xml::lite::Serializable::serialize(io::OutputStream& os) { xml::lite::Element *root = getDocument()->getRootElement(); - if (root != NULL) + if (root != nullptr) os.write("\n"); root->print(os); } diff --git a/modules/c++/xml.lite/source/ValidatorXerces.cpp b/modules/c++/xml.lite/source/ValidatorXerces.cpp index 7e794d4e4b..cc1a1b516a 100644 --- a/modules/c++/xml.lite/source/ValidatorXerces.cpp +++ b/modules/c++/xml.lite/source/ValidatorXerces.cpp @@ -28,11 +28,18 @@ #include #include // std::ignore +#include +#include +CODA_OSS_disable_warning_push +#ifndef _MSC_VER +CODA_OSS_disable_warning(-Wshadow) +#endif +#include +CODA_OSS_disable_warning_pop + #include #include #include -#include -#include namespace fs = std::filesystem; @@ -126,7 +133,7 @@ ValidatorXerces::ValidatorXerces( xercesc::DOMImplementationRegistry:: getDOMImplementation (ls_id)->createLSParser( xercesc::DOMImplementationLS::MODE_SYNCHRONOUS, - 0, + nullptr, xercesc::XMLPlatformUtils::fgMemoryManager, mSchemaPool.get())); diff --git a/modules/c++/xml.lite/source/XMLReaderXerces.cpp b/modules/c++/xml.lite/source/XMLReaderXerces.cpp index 3ecf8d79fc..a776842d90 100644 --- a/modules/c++/xml.lite/source/XMLReaderXerces.cpp +++ b/modules/c++/xml.lite/source/XMLReaderXerces.cpp @@ -19,6 +19,7 @@ * see . * */ +#include "xml/lite/XMLReaderXerces.h" #include diff --git a/modules/c++/xml.lite/unittests/test_soapelements.cpp b/modules/c++/xml.lite/unittests/test_soapelements.cpp index 55de517a95..e1ec61504c 100644 --- a/modules/c++/xml.lite/unittests/test_soapelements.cpp +++ b/modules/c++/xml.lite/unittests/test_soapelements.cpp @@ -25,7 +25,12 @@ #include "xml/lite/Document.h" #include "xml/lite/Element.h" #include "xml/lite/QName.h" -static const std::string test_text = "SOAP Test"; + +static const std::string& test_text() +{ + static const std::string retval = "SOAP Test"; + return retval; +} struct SOAPBody final : public xml::lite::Element { @@ -44,7 +49,7 @@ struct SOAP final : public xml::lite::Document const xml::lite::QName asQName(uri, qname); xml::lite::Element* elem = new SOAPBody(asQName); elem->setCharacterData(characterData); // avoid unused parameter warning - elem->setCharacterData(test_text); + elem->setCharacterData(test_text()); return elem; } }; @@ -55,8 +60,8 @@ TEST_CASE(test_overrideCreateElement) std::unique_ptr a(soap_test.createElement("a","b","Not SOAP Test")); auto b = dynamic_cast(a.get()); TEST_ASSERT_NOT_NULL(b); - TEST_ASSERT_EQ(a->getCharacterData(), test_text); - TEST_ASSERT_EQ(b->getCharacterData(), test_text); + TEST_ASSERT_EQ(a->getCharacterData(), test_text()); + TEST_ASSERT_EQ(b->getCharacterData(), test_text()); } TEST_MAIN diff --git a/modules/c++/xml.lite/unittests/test_xmlattribute.cpp b/modules/c++/xml.lite/unittests/test_xmlattribute.cpp index 011bb79d1c..8df82c970f 100644 --- a/modules/c++/xml.lite/unittests/test_xmlattribute.cpp +++ b/modules/c++/xml.lite/unittests/test_xmlattribute.cpp @@ -28,18 +28,31 @@ #include "xml/lite/MinidomParser.h" #include "xml/lite/QName.h" -static const std::string strUri = "urn:example.com"; -static const xml::lite::Uri uri(strUri); -static const std::string strXml_1_ = R"( +static const std::string& strUri() +{ + static const std::string retval("urn:example.com"); + return retval; +} +static const xml::lite::Uri& uri() +{ + static const xml::lite::Uri retval(strUri()); + return retval; +} + +static const auto& strXml() +{ + static const std::string strXml_1_ = R"( TEXT + static const std::string strXml_2_ = R"(" ns:int="314" /> )"; -static const auto strXml = strXml_1_ + strUri + strXml_2_; + static const auto retval = strXml_1_ + strUri() + strXml_2_; + return retval; +} struct test_MinidomParser final { @@ -47,7 +60,7 @@ struct test_MinidomParser final xml::lite::Element* getRootElement() { io::StringStream ss; - ss.stream() << strXml; + ss.stream() << strXml(); xmlParser.parse(ss); return getDocument(xmlParser).getRootElement(); @@ -88,19 +101,19 @@ TEST_CASE(test_getAttributeByNS) using namespace xml::lite; std::string strValue; - strValue = attributes.getValue(xml::lite::QName(uri, "int")); + strValue = attributes.getValue(xml::lite::QName(uri(), "int")); TEST_ASSERT_EQ("314", strValue); - strValue = getValue(attributes, uri, "int"); + strValue = getValue(attributes, uri(), "int"); TEST_ASSERT_EQ("314", strValue); - const auto key = xml::lite::QName(uri, "int"); + const auto key = xml::lite::QName(uri(), "int"); strValue = getValue(attributes, key); TEST_ASSERT_EQ("314", strValue); int value; - auto result = getValue(attributes, uri, "int", value); + auto result = getValue(attributes, uri(), "int", value); TEST_ASSERT_TRUE(result); TEST_ASSERT_EQ(314, value); - value = getValue(attributes, uri, "int"); + value = getValue(attributes, uri(), "int"); TEST_ASSERT_EQ(314, value); result = getValue(attributes, key, value); diff --git a/modules/c++/xml.lite/unittests/test_xmlelement.cpp b/modules/c++/xml.lite/unittests/test_xmlelement.cpp index a9890ab004..0c252e12a7 100644 --- a/modules/c++/xml.lite/unittests/test_xmlelement.cpp +++ b/modules/c++/xml.lite/unittests/test_xmlelement.cpp @@ -37,12 +37,18 @@ #define U8(s) static_cast(static_cast(s)) #endif -static const std::string text = "TEXT"; -static const std::string strXml1_ = R"( +static const std::string& text() +{ + static const std::string retval("TEXT"); + return retval; +} +static const auto& strXml() +{ + static const std::string strXml1_ = R"( )"; -static const std::string strXml2_ = R"( + static const std::string strXml2_ = R"( 314 3.14 @@ -51,7 +57,9 @@ static const std::string strXml2_ = R"( )"; -static const auto strXml = strXml1_ + text + strXml2_; + static const auto retval = strXml1_ + text() + strXml2_; + return retval; +} struct test_MinidomParser final { @@ -59,7 +67,7 @@ struct test_MinidomParser final const xml::lite::Element& getRootElement() const { io::StringStream ss; - ss.stream() << strXml; + ss.stream() << strXml(); xmlParser.parse(ss); return xml::lite::getRootElement(xmlParser.getDocument()); @@ -67,7 +75,7 @@ struct test_MinidomParser final xml::lite::Element& getRootElement() { io::StringStream ss; - ss.stream() << strXml; + ss.stream() << strXml(); xmlParser.parse(ss); return xml::lite::getRootElement(xmlParser.getDocument()); @@ -77,8 +85,8 @@ struct test_MinidomParser final TEST_CASE(test_getRootElement) { io::StringStream ss; - ss.stream() << strXml; - TEST_ASSERT_EQ(ss.stream().str(), strXml); + ss.stream() << strXml(); + TEST_ASSERT_EQ(ss.stream().str(), strXml()); xml::lite::MinidomParser xmlParser; xmlParser.parse(ss); @@ -97,7 +105,7 @@ TEST_CASE(test_getElementsByTagName) const auto& a = *(aElements[0]); const auto characterData = a.getCharacterData(); - TEST_ASSERT_EQ(characterData, text); + TEST_ASSERT_EQ(characterData, text()); } const auto docElements = root.getElementsByTagName("doc"); @@ -109,7 +117,7 @@ TEST_CASE(test_getElementsByTagName) const auto& a = *(aElements[0]); const auto characterData = a.getCharacterData(); - TEST_ASSERT_EQ(characterData, text); + TEST_ASSERT_EQ(characterData, text()); } } @@ -148,14 +156,14 @@ TEST_CASE(test_getElementByTagName) { const auto& a = root.getElementByTagName("a", true /*recurse*/); const auto characterData = a.getCharacterData(); - TEST_ASSERT_EQ(characterData, text); + TEST_ASSERT_EQ(characterData, text()); } const auto& doc = root.getElementByTagName("doc"); { const auto& a = doc.getElementByTagName("a"); const auto characterData = a.getCharacterData(); - TEST_ASSERT_EQ(characterData, text); + TEST_ASSERT_EQ(characterData, text()); } } diff --git a/modules/c++/xml.lite/unittests/test_xmlparser.cpp b/modules/c++/xml.lite/unittests/test_xmlparser.cpp index 6a4ff8bf18..b0e88e33b3 100644 --- a/modules/c++/xml.lite/unittests/test_xmlparser.cpp +++ b/modules/c++/xml.lite/unittests/test_xmlparser.cpp @@ -43,22 +43,71 @@ static inline std::u8string fromUtf8(const std::string& utf8) return str::EncodedStringView::fromUtf8(utf8).u8string(); } -static const std::string text("TEXT"); -static const std::string strXml = "" + text + ""; -static const std::u8string text8 = fromUtf8(text); +static const std::string& text() +{ + static const std::string retval("TEXT"); + return retval; +} +static const std::string& strXml() +{ + static const std::string retval = "" + text() + ""; + return retval; +} +static const std::u8string& text8() +{ + static const auto retval = fromUtf8(text()); + return retval; +} + +static const str::EncodedString& iso88591Text() +{ + static const str::EncodedString retval(str::cast("T\xc9XT")); // ISO8859-1, "TÉXT" + return retval; +} +static const auto& iso88591Text1252() +{ + static const auto retval = str::EncodedStringView::details::w1252string(iso88591Text().view()); + return retval; +} +static auto pIso88591Text_() +{ + static const auto retval = str::c_str(iso88591Text1252()); + return retval; +} -static const str::EncodedString iso88591Text(str::cast("T\xc9XT")); // ISO8859-1, "TÉXT" -static const auto iso88591Text1252 = str::EncodedStringView::details::w1252string(iso88591Text.view()); -static const auto pIso88591Text_ = str::c_str(iso88591Text1252); +static const str::EncodedString& utf8Text() +{ + static const str::EncodedString retval(str::cast("T\xc3\x89XT")); // UTF-8, "TÉXT" + return retval; +} -static const str::EncodedString utf8Text(str::cast("T\xc3\x89XT")); // UTF-8, "TÉXT" -static const auto utf8Text8 = utf8Text.u8string(); -static const auto pUtf8Text_ = str::c_str(utf8Text8); +static const auto& utf8Text8() +{ + static const auto retval = utf8Text().u8string(); + return retval; +} +static const auto pUtf8Text_() +{ + static const auto retval = str::c_str(utf8Text8()); + return retval; +} -static const auto strUtf8Xml8 = fromUtf8("") + utf8Text8 + fromUtf8(""); -static const std::string strUtf8Xml = str::c_str(strUtf8Xml8); +static const auto& strUtf8Xml8() +{ + static const auto retval = fromUtf8("") + utf8Text8() + fromUtf8(""); + return retval; +} +static const std::string& strUtf8Xml() +{ + static const std::string retval = str::c_str(strUtf8Xml8()); + return retval; +} -static const std::string platfromText_ = sys::Platform == sys::PlatformType::Windows ? pIso88591Text_ : pUtf8Text_; +static const std::string platfromText_() +{ + static const std::string retval = sys::Platform == sys::PlatformType::Windows ? pIso88591Text_() : pUtf8Text_(); + return retval; +} static std::filesystem::path find_unittest_file(const std::filesystem::path& name) { @@ -73,13 +122,13 @@ static void test_a_element(const std::string& testName, const xml::lite::Element const auto& a = *(aElements[0]); const auto characterData = a.getCharacterData(); - TEST_ASSERT_EQ(characterData, text); + TEST_ASSERT_EQ(characterData, text()); } TEST_CASE(testXmlParseSimple) { io::StringStream ss; - ss.stream() << strXml; - TEST_ASSERT_EQ(ss.stream().str(), strXml); + ss.stream() << strXml(); + TEST_ASSERT_EQ(ss.stream().str(), strXml()); xml::lite::MinidomParser xmlParser; xmlParser.parse(ss); @@ -95,8 +144,8 @@ TEST_CASE(testXmlParseSimple) TEST_CASE(testXmlPreserveCharacterData) { io::StringStream stream; - stream.stream() << strUtf8Xml; - TEST_ASSERT_EQ(stream.stream().str(), strUtf8Xml); + stream.stream() << strUtf8Xml(); + TEST_ASSERT_EQ(stream.stream().str(), strUtf8Xml()); xml::lite::MinidomParser xmlParser; // This is needed in Windows, because the default locale is *.1252 (more-or-less ISO8859-1) @@ -111,7 +160,7 @@ TEST_CASE(testXmlPreserveCharacterData) static xml::lite::Element& testXmlUtf8_(xml::lite::MinidomParser& xmlParser) { io::StringStream stream; - stream.stream() << strUtf8Xml; + stream.stream() << strUtf8Xml(); xmlParser.preserveCharacterData(true); xmlParser.parse(stream); @@ -127,7 +176,7 @@ TEST_CASE(testXmlUtf8_u8string) const auto& a = testXmlUtf8_(xmlParser); const auto actual = getCharacterData(a); - TEST_ASSERT_EQ(actual, utf8Text8); + TEST_ASSERT_EQ(actual, utf8Text8()); } TEST_CASE(testXmlUtf8) @@ -136,7 +185,7 @@ TEST_CASE(testXmlUtf8) const auto& a = testXmlUtf8_(xmlParser); auto actual = a.getCharacterData(); - const auto expected = platfromText_; + const auto expected = platfromText_(); TEST_ASSERT_EQ(actual, expected); } @@ -144,7 +193,7 @@ TEST_CASE(testXml_setCharacterData) { xml::lite::MinidomParser xmlParser; auto& a = testXmlUtf8_(xmlParser); - a.setCharacterData(utf8Text8); + a.setCharacterData(utf8Text8()); TEST_ASSERT_TRUE(true); // need to use hidden "testName" parameter } @@ -163,7 +212,7 @@ static std::string testXmlPrint_(std::string& expected, const std::string& chara TEST_CASE(testXmlPrintSimple) { std::string expected; - const auto actual = testXmlPrint_(expected, text); + const auto actual = testXmlPrint_(expected, text()); TEST_ASSERT_EQ(actual, expected); } @@ -177,12 +226,12 @@ TEST_CASE(testXmlPrintUtf8) { static const xml::lite::QName root(xml::lite::Uri(), "root"); - const auto expected = std::string("") + pUtf8Text_ + ""; + const auto expected = std::string("") + pUtf8Text_() + ""; { xml::lite::MinidomParser xmlParser; auto& document = getDocument(xmlParser); - const auto s8_w1252 = fromWindows1252(pIso88591Text_); + const auto s8_w1252 = fromWindows1252(pIso88591Text_()); const auto pRootElement = document.createElement(root, s8_w1252); io::StringStream output; @@ -194,7 +243,7 @@ TEST_CASE(testXmlPrintUtf8) xml::lite::MinidomParser xmlParser; auto& document = getDocument(xmlParser); - const auto pRootElement = document.createElement(root, utf8Text8); + const auto pRootElement = document.createElement(root, utf8Text8()); io::StringStream output; pRootElement->print(output); @@ -205,7 +254,7 @@ TEST_CASE(testXmlPrintUtf8) xml::lite::MinidomParser xmlParser; auto& document = getDocument(xmlParser); - const auto pRootElement = document.createElement(root, platfromText_); + const auto pRootElement = document.createElement(root, platfromText_()); io::StringStream output; pRootElement->print(output); @@ -218,12 +267,12 @@ TEST_CASE(testXmlConsoleOutput) { static const xml::lite::QName root(xml::lite::Uri(), "root"); - const auto expected = "" + platfromText_ + ""; + const auto expected = "" + platfromText_() + ""; { xml::lite::MinidomParser xmlParser; auto& document = getDocument(xmlParser); - const auto s8_w1252 = fromWindows1252(pIso88591Text_); + const auto s8_w1252 = fromWindows1252(pIso88591Text_()); const auto pRootElement = document.createElement(root, s8_w1252); io::StringStream output; @@ -235,7 +284,7 @@ TEST_CASE(testXmlConsoleOutput) xml::lite::MinidomParser xmlParser; auto& document = getDocument(xmlParser); - const auto pRootElement = document.createElement(root, utf8Text8); + const auto pRootElement = document.createElement(root, utf8Text8()); io::StringStream output; pRootElement->consoleOutput_(output); @@ -246,7 +295,7 @@ TEST_CASE(testXmlConsoleOutput) xml::lite::MinidomParser xmlParser; auto& document = getDocument(xmlParser); - const auto pRootElement = document.createElement(root, platfromText_); + const auto pRootElement = document.createElement(root, platfromText_()); io::StringStream output; pRootElement->consoleOutput_(output); @@ -258,7 +307,7 @@ TEST_CASE(testXmlConsoleOutput) TEST_CASE(testXmlParseAndPrintUtf8) { io::StringStream input; - input.stream() << strUtf8Xml; + input.stream() << strUtf8Xml(); xml::lite::MinidomParser xmlParser; xmlParser.preserveCharacterData(true); @@ -268,7 +317,7 @@ TEST_CASE(testXmlParseAndPrintUtf8) io::StringStream output; pRootElement->print(output); const auto actual = output.stream().str(); - TEST_ASSERT_EQ(actual, strUtf8Xml); + TEST_ASSERT_EQ(actual, strUtf8Xml()); } static void testReadEncodedXmlFile(const std::string& testName, const std::string& xmlFile, bool preserveCharacterData, @@ -308,12 +357,12 @@ static void testReadEncodedXmlFile(const std::string& testName, const std::strin TEST_CASE(testReadEncodedXmlFiles) { // these have "" - testReadEncodedXmlFile(testName, "encoding_utf-8.xml", true /*preserveCharacterData*/, platfromText_ , utf8Text8); - testReadEncodedXmlFile(testName, "encoding_utf-8.xml", false /*preserveCharacterData*/, platfromText_ , utf8Text8); - testReadEncodedXmlFile(testName, "encoding_windows-1252.xml", true /*preserveCharacterData*/, platfromText_ , utf8Text8); - testReadEncodedXmlFile(testName, "encoding_windows-1252.xml", false /*preserveCharacterData*/, platfromText_ , utf8Text8); - testReadEncodedXmlFile(testName, "ascii_encoding_utf-8.xml", true /*preserveCharacterData*/, text , text8); - testReadEncodedXmlFile(testName, "ascii_encoding_utf-8.xml", false /*preserveCharacterData*/, text , text8); + testReadEncodedXmlFile(testName, "encoding_utf-8.xml", true /*preserveCharacterData*/, platfromText_() , utf8Text8()); + testReadEncodedXmlFile(testName, "encoding_utf-8.xml", false /*preserveCharacterData*/, platfromText_(), utf8Text8()); + testReadEncodedXmlFile(testName, "encoding_windows-1252.xml", true /*preserveCharacterData*/, platfromText_(), utf8Text8()); + testReadEncodedXmlFile(testName, "encoding_windows-1252.xml", false /*preserveCharacterData*/, platfromText_(), utf8Text8()); + testReadEncodedXmlFile(testName, "ascii_encoding_utf-8.xml", true /*preserveCharacterData*/, text() , text8()); + testReadEncodedXmlFile(testName, "ascii_encoding_utf-8.xml", false /*preserveCharacterData*/, text(), text8()); } static void testReadXmlFile(const std::string& testName, const std::string& xmlFile, bool preserveCharacterData, @@ -357,12 +406,12 @@ static void testReadXmlFile(const std::string& testName, const std::string& xmlF TEST_CASE(testReadXmlFiles) { // These do NOT have "" - testReadXmlFile(testName, "utf-8.xml", true /*preserveCharacterData*/, platfromText_ , utf8Text8); - testReadXmlFile(testName, "utf-8.xml", false /*preserveCharacterData*/, platfromText_ , utf8Text8); - testReadXmlFile(testName, "windows-1252.xml", true /*preserveCharacterData*/, platfromText_ , utf8Text8); - testReadXmlFile(testName, "windows-1252.xml", false /*preserveCharacterData*/, platfromText_ , utf8Text8); - testReadXmlFile(testName, "ascii.xml", true /*preserveCharacterData*/, text , text8); - testReadXmlFile(testName, "ascii.xml", false /*preserveCharacterData*/, text , text8); + testReadXmlFile(testName, "utf-8.xml", true /*preserveCharacterData*/, platfromText_() , utf8Text8()); + testReadXmlFile(testName, "utf-8.xml", false /*preserveCharacterData*/, platfromText_(), utf8Text8()); + testReadXmlFile(testName, "windows-1252.xml", true /*preserveCharacterData*/, platfromText_(), utf8Text8()); + testReadXmlFile(testName, "windows-1252.xml", false /*preserveCharacterData*/, platfromText_(), utf8Text8()); + testReadXmlFile(testName, "ascii.xml", true /*preserveCharacterData*/, text(), text8()); + testReadXmlFile(testName, "ascii.xml", false /*preserveCharacterData*/, text(), text8()); } static bool find_string(io::FileInputStream& stream, const std::string& s) diff --git a/modules/c++/zip/source/GZipInputStream.cpp b/modules/c++/zip/source/GZipInputStream.cpp index 2fa47bcda0..9a3fd3b397 100644 --- a/modules/c++/zip/source/GZipInputStream.cpp +++ b/modules/c++/zip/source/GZipInputStream.cpp @@ -27,7 +27,7 @@ using namespace zip; GZipInputStream::GZipInputStream(const std::string& file) { mFile = gzopen(file.c_str(), "rb"); - if (mFile == NULL) + if (mFile == nullptr) { throw except::IOException(Ctxt( "Failed to open gzip stream [" + file + "]")); @@ -37,7 +37,7 @@ GZipInputStream::GZipInputStream(const std::string& file) void GZipInputStream::close() { gzclose( mFile); - mFile = NULL; + mFile = nullptr; } sys::SSize_T GZipInputStream::readImpl(void* buffer, size_t len) diff --git a/modules/c++/zip/source/GZipOutputStream.cpp b/modules/c++/zip/source/GZipOutputStream.cpp index b14e540f8c..6c83a1fdfa 100644 --- a/modules/c++/zip/source/GZipOutputStream.cpp +++ b/modules/c++/zip/source/GZipOutputStream.cpp @@ -27,7 +27,7 @@ using namespace zip; GZipOutputStream::GZipOutputStream(const std::string& file) { mFile = gzopen(file.c_str(), "wb"); - if (mFile == NULL) + if (mFile == nullptr) { throw except::IOException(Ctxt( "Failed to open gzip stream [" + file + "]")); @@ -59,5 +59,5 @@ void GZipOutputStream::write(const void* buffer, size_t len) void GZipOutputStream::close() { gzclose( mFile); - mFile = NULL; + mFile = nullptr; } diff --git a/modules/c++/zip/source/ZipEntry.cpp b/modules/c++/zip/source/ZipEntry.cpp index 9f71cbef32..4c93526729 100644 --- a/modules/c++/zip/source/ZipEntry.cpp +++ b/modules/c++/zip/source/ZipEntry.cpp @@ -29,7 +29,7 @@ const static char* sZipFileMadeByStr[] = { "OpenVMS", "UNIX", "VM/CMS", "Atari ST", "OS/2 H.P.F.S.", "Macintosh", "Z-System", "CP/M", "Windows NTFS", "MVS (OS/390 - Z/OS)", "VSE", "Acorn Risc", "VFAT", "alternative MVS", "BeOS", "Tandem", "OS/400", - "OS/X (Darwin)", NULL }; + "OS/X (Darwin)", nullptr }; namespace zip { @@ -69,7 +69,7 @@ const char* ZipEntry::getVersionMadeByString() const { if (mVersionMadeBy >= 20) - return NULL; + return nullptr; return sZipFileMadeByStr[mVersionMadeBy]; } @@ -97,7 +97,7 @@ std::ostream& operator<<(std::ostream& os, const zip::ZipEntry& ze) { const char* madeBy = ze.getVersionMadeByString(); std::string asStr = "Unknown"; - if (madeBy != NULL) + if (madeBy != nullptr) { asStr = madeBy; } diff --git a/modules/c++/zip/source/ZipOutputStream.cpp b/modules/c++/zip/source/ZipOutputStream.cpp index 3f7302e3dc..f4e09e34c6 100644 --- a/modules/c++/zip/source/ZipOutputStream.cpp +++ b/modules/c++/zip/source/ZipOutputStream.cpp @@ -29,7 +29,7 @@ namespace zip ZipOutputStream::ZipOutputStream(const std::string& pathname) { mZip = zipOpen64(pathname.c_str(), APPEND_STATUS_CREATE); - if (mZip == NULL) + if (mZip == nullptr) throw except::IOException(Ctxt("Failed to open zip stream " + pathname)); @@ -52,14 +52,14 @@ void ZipOutputStream::createFileInZip(const std::string& pathname, 0, NULL, 0, - comment.empty() ? NULL : comment.c_str(), + comment.empty() ? nullptr : comment.c_str(), Z_DEFLATED, Z_DEFAULT_COMPRESSION, 0, -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, - password.empty() ? NULL : password.c_str(), + password.empty() ? nullptr : password.c_str(), 0, 0); @@ -96,7 +96,7 @@ void ZipOutputStream::write(const void* buffer, size_t len) void ZipOutputStream::close() { - sys::Int32_T results = zipClose(mZip, NULL); + sys::Int32_T results = zipClose(mZip, nullptr); if (results != Z_OK) throw except::IOException(Ctxt("Failed to save zip file.")); } diff --git a/modules/drivers/j2k/openjpeg/CMakeLists.txt b/modules/drivers/j2k/openjpeg/CMakeLists.txt index 51338f6c50..ea00968039 100644 --- a/modules/drivers/j2k/openjpeg/CMakeLists.txt +++ b/modules/drivers/j2k/openjpeg/CMakeLists.txt @@ -59,12 +59,12 @@ else() set(SOURCE_DIR "${${CMAKE_PROJECT_NAME}_${TARGET_NAME}_SOURCE_DIR}") - check_include_file("stdint.h" OPJ_HAVE_STDINT_H) + set(OPJ_HAVE_STDINT_H true) set(OPENJPEG_VERSION_MAJOR 2) set(OPENJPEG_VERSION_MINOR 3) set(OPENJPEG_VERSION_BUILD 1) - check_include_file("inttypes.h" OPJ_HAVE_INTTYPES_H) + set(OPJ_HAVE_INTTYPES_H true) set(PACKAGE_VERSION 2.3.1) set(_FILE_OFFSET_BITS 64) set(_LARGEFILE_SOURCE 1) @@ -72,7 +72,7 @@ else() set(CMAKE_REQUIRED_DEFINITIONS -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE) check_symbol_exists("fseeko" "stdio.h" OPJ_HAVE_FSEEKO) unset(CMAKE_REQUIRED_DEFINITIONS) - check_include_file("malloc.h" OPJ_HAVE_MALLOC_H) + set(OPJ_HAVE_MALLOC_H true) check_symbol_exists("aligned_alloc" "malloc.h" OPJ_HAVE_ALIGNED_ALLOC) check_symbol_exists("_aligned_malloc" "malloc.h" OPJ_HAVE__ALIGNED_MALLOC) check_symbol_exists("memalign" "malloc.h" OPJ_HAVE_MEMALIGN) diff --git a/modules/drivers/jpeg/CMakeLists.txt b/modules/drivers/jpeg/CMakeLists.txt index 39b773bd71..dea7767094 100644 --- a/modules/drivers/jpeg/CMakeLists.txt +++ b/modules/drivers/jpeg/CMakeLists.txt @@ -53,13 +53,11 @@ else() HASH "SHA256=898C46BFE9152D51220C6679E905DE4DF75D2A67DCF315BF80459673AB1EB797" ) set(HAVE_PROTOTYPES 1) - check_cxx_source_compiles("int main() { unsigned short; return 0; }" - HAVE_UNSIGNED_SHORT) - check_cxx_source_compiles("int main() { unsigned char; return 0; }" - HAVE_UNSIGNED_CHAR) - check_include_file("stddef.h" HAVE_STDDEF_H) - check_include_file("stdlib.h" HAVE_STDLIB_H) - check_include_file("locale.h" HAVE_LOCALE_H) + set(HAVE_UNSIGNED_SHORT true) + set(HAVE_UNSIGNED_CHAR true) + set(HAVE_STDDEF_H true) + set(HAVE_STDLIB_H true) + set(HAVE_STDLIB_H true) set(SOURCE_DIR "${${CMAKE_PROJECT_NAME}_${TARGET_NAME}_SOURCE_DIR}") foreach(src "cdjpeg.c" "jaricom.c" "jcapimin.c" "jcapistd.c" diff --git a/modules/drivers/pcre/CMakeLists.txt b/modules/drivers/pcre/CMakeLists.txt index a1fe672848..ac2c2960a3 100644 --- a/modules/drivers/pcre/CMakeLists.txt +++ b/modules/drivers/pcre/CMakeLists.txt @@ -54,10 +54,10 @@ else() ) check_symbol_exists("bcopy" "strings.h" HAVE_BCOPY) - check_include_file("inttypes.h" HAVE_INTTYPES_H) - check_symbol_exists("memmove" "string.h" HAVE_MEMMOVE) - check_include_file("stdint.h" HAVE_STDINT_H) - check_symbol_exists("strerror" "string.h" HAVE_STRERROR) + set(HAVE_INTTYPES_H true) + set(HAVE_MEMMOVE true) + set(HAVE_STDINT_H true) + set(HAVE_STRERROR true) set(SUPPORT_PCRE2_8 1) set(PCRE2_LINK_SIZE 2) set(PCRE2_MATCH_LIMIT 10000000) diff --git a/modules/drivers/uuid/CMakeLists.txt b/modules/drivers/uuid/CMakeLists.txt index 7885376cd5..319b35d55c 100644 --- a/modules/drivers/uuid/CMakeLists.txt +++ b/modules/drivers/uuid/CMakeLists.txt @@ -47,7 +47,7 @@ else() set(SOURCE_DIR "${${CMAKE_PROJECT_NAME}_${TARGET_NAME}_SOURCE_DIR}") - check_include_file("inttypes.h" HAVE_INTTYPES_H) + set(HAVE_INTTYPES_H true) check_type_size("int" SIZEOF_INT) check_type_size("short" SIZEOF_SHORT) check_type_size("long" SIZEOF_LONG) diff --git a/modules/drivers/xml/xerces/CMakeLists.txt b/modules/drivers/xml/xerces/CMakeLists.txt index c1de78a61a..664d68d0d4 100644 --- a/modules/drivers/xml/xerces/CMakeLists.txt +++ b/modules/drivers/xml/xerces/CMakeLists.txt @@ -63,48 +63,48 @@ else() HASH "SHA256=61981c7a464e33913a093e0dfe7daf8a45f21e46b1924eb97f92bdbb746e2e6e" ) - check_include_file("inttypes.h" HAVE_INTTYPES_H) + set(HAVE_INTTYPES_H true) check_include_file("netinet/in.h" HAVE_NETINET_IN_H) check_include_file("arpa/inet.h" HAVE_ARPA_INET_H) check_include_file("netdb.h" HAVE_NETDB_H) check_include_file("intrin.h" HAVE_INTRIN_H) - check_include_file("emmintrin.h" HAVE_EMMINTRIN_H) - check_include_file("wchar.h" HAVE_WCHAR_H) - check_include_file("stdint.h" HAVE_STDINT_H) - check_include_file("stdio.h" HAVE_STDIO_H) + set(HAVE_EMMINTRIN_H true) + set(HAVE_WCHAR_H true) + set(HAVE_STDINT_H true) + set(HAVE_STDIO_H true) check_include_file("langinfo.h" HAVE_LANGINFO_H) check_include_file("iconv.h" HAVE_ICONV_H) check_include_file("nl_types.h" HAVE_NL_TYPES_H) - check_include_file("ctype.h" HAVE_CTYPE_H) - check_include_file("wctype.h" HAVE_WCTYPE_H) + set(HAVE_CTYPE_H true) + set(HAVE_WCTYPE_H true) check_include_file("cpuid.h" HAVE_CPUID_H) check_include_file("endian.h" HAVE_ENDIAN_H) check_include_file("machine/endian.h" HAVE_MACHINE_ENDIAN_H) check_include_file("arpa/nameser_compat.h" HAVE_ARPA_NAMESER_COMPAT_H) - check_include_file("errno.h" HAVE_ERRNO_H) - check_include_file("float.h" HAVE_FLOAT_H) - check_include_file("locale.h" HAVE_LOCALE_H) + set(HAVE_ERRNO_H true) + set(HAVE_FLOAT_H true) + set(HAVE_LOCALE_H true) check_include_file("sys/param.h" HAVE_SYS_PARAM_H) check_include_file("sys/socket.h" HAVE_SYS_SOCKET_H) - check_include_file("sys/stat.h" HAVE_SYS_STAT_H) - check_include_file("sys/timeb.h" HAVE_SYS_TIMEB_H) - check_include_file("sys/types.h" HAVE_SYS_TYPES_H) + set(HAVE_SYS_STAT_H true) + set(HAVE_SYS_TIMEB_H true) + set(HAVE_SYS_TYPES_H true) - check_symbol_exists("mblen" "stdlib.h" HAVE_MBLEN) + set(HAVE_MBLEN true) check_symbol_exists("mbrlen" "stdlib.h" HAVE_MBRLEN) check_symbol_exists("mbsrtowcs" "stdlib.h" HAVE_MBSRTOWCS) - check_symbol_exists("mbstowcs" "stdlib.h" HAVE_MBSTOWCS) - check_symbol_exists("wsctombs" "stdlib.h" HAVE_WCSTOMBS) + set(HAVE_MBSTOWCS true) + set(HAVE_WCSTOMBS true) check_symbol_exists("wcsrtombs" "stdlib.h" HAVE_WCSRTOMBS) check_symbol_exists("realpath" "stdlib.h" HAVE_REALPATH) - check_symbol_exists("strchr" "string.h" HAVE_STRCHR) - check_symbol_exists("strdup" "string.h" HAVE_STRDUP) + set(HAVE_STRCHR true) + set(HAVE_STRDUP true) check_symbol_exists("stricmp" "string.h" HAVE_STRICMP) check_symbol_exists("strnicmp" "string.h" HAVE_STRNICMP) check_symbol_exists("strrcmp" "string.h" HAVE_STRRCMP) - check_symbol_exists("strstr" "string.h" HAVE_STRSTR) - check_symbol_exists("strtol" "string.h" HAVE_STRTOL) - check_symbol_exists("strtoul" "string.h" HAVE_STRTOUL) + set(HAVE_STRSTR true) + set(HAVE_STRTOL true) + set(HAVE_STRTOUL true) check_symbol_exists("strcasecmp" "strings.h" HAVE_STRCASECMP) check_symbol_exists("strncasecmp" "strings.h" HAVE_STRNCASECMP) check_symbol_exists("pathconf" "unistd.h" HAVE_PATHCONF) @@ -112,15 +112,15 @@ else() check_symbol_exists("iconv" "iconv.h" HAVE_ICONV) check_symbol_exists("iconv_close" "iconv.h" HAVE_ICONV_CLOSE) check_symbol_exists("iconv_open" "iconv.h" HAVE_ICONV_OPEN) - check_symbol_exists("towupper" "wctype.h" HAVE_TOWUPPER) - check_symbol_exists("towlower" "wctype.h" HAVE_TOWLOWER) + set(HAVE_TOWUPPER true) + set(HAVE_TOWLOWER true) check_symbol_exists("catclose" "nl_types.h" HAVE_CATCLOSE) check_symbol_exists("catgets" "nl_types.h" HAVE_CATGETS) check_symbol_exists("catopen" "nl_types.h" HAVE_CATOPEN) - check_symbol_exists("localeconv" "locale.h" HAVE_LOCALECONV) - check_symbol_exists("setlocale" "locale.h" HAVE_SETLOCALE) + set(HAVE_LOCALECONV true) + set(HAVE_SETLOCALE true) check_symbol_exists("socket" "sys/socket.h" HAVE_SOCKET) - check_symbol_exists("ftime" "sys/timeb.h" HAVE_FTIME) + set(HAVE_FTIME true) check_symbol_exists("getaddrinfo" "netdb.h" HAVE_GETADDRINFO) find_library(NSL_LIB nsl) @@ -130,7 +130,7 @@ else() check_include_file("unistd.h" HAVE_UNISTD_H) check_include_file("sys/time.h" HAVE_SYS_TIME_H) - check_include_file("limits.h" HAVE_LIMITS_H) + set(HAVE_LIMITS_H true) check_include_file("strings.h" HAVE_STRINGS_H) # extra defines for config.h