From 159660719af86b015078b7fc998549ba45761fec Mon Sep 17 00:00:00 2001 From: "Mark A. Tsuchida" Date: Thu, 14 Dec 2023 14:14:52 -0600 Subject: [PATCH 1/5] MMDevice: Remove superfluous 'const' Doesn't change anything but produces warnings from GCC and Clang. This change should not affect the device binary interface. --- MMDevice/ImageMetadata.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MMDevice/ImageMetadata.h b/MMDevice/ImageMetadata.h index 156385eb1..eebebfbd0 100644 --- a/MMDevice/ImageMetadata.h +++ b/MMDevice/ImageMetadata.h @@ -101,7 +101,7 @@ class MetadataTag str.append(name_); return str; } - const bool IsReadOnly() const {return readOnly_;} + bool IsReadOnly() const {return readOnly_;} void SetDevice(const char* device) {deviceLabel_ = device;} void SetName(const char* name) {name_ = name;} @@ -496,4 +496,4 @@ class Metadata #ifdef _MSC_VER #pragma warning(pop) -#endif \ No newline at end of file +#endif From 03df42e64b5566a9a0a2267b0e583c2776fe649f Mon Sep 17 00:00:00 2001 From: "Mark A. Tsuchida" Date: Thu, 14 Dec 2023 14:17:25 -0600 Subject: [PATCH 2/5] MMDevice: Avoid sprintf() (deprecation warning) --- MMDevice/Property.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MMDevice/Property.cpp b/MMDevice/Property.cpp index b7f807ccd..7088a8f81 100644 --- a/MMDevice/Property.cpp +++ b/MMDevice/Property.cpp @@ -191,7 +191,7 @@ bool MM::FloatProperty::Get(std::string& strVal) const { char fmtStr[20]; char buf[BUFSIZE]; - std::sprintf(fmtStr, "%%.%df", decimalPlaces_); + std::snprintf(fmtStr, sizeof(fmtStr), "%%.%df", decimalPlaces_); std::snprintf(buf, BUFSIZE, fmtStr, value_); strVal = buf; return true; From 5a665ce1daee9d67719d70cbdc306594403b6f4b Mon Sep 17 00:00:00 2001 From: "Mark A. Tsuchida" Date: Thu, 14 Dec 2023 14:37:18 -0600 Subject: [PATCH 3/5] MMDevice/MMCore: Suppress GCC warnings for throw() There is no way to suppress just for exception specifications, but limit the suppression to within the headers. Also make suppression of MSVC C4290 consistent with GCC. --- MMCore/CircularBuffer.cpp | 8 ++++++++ MMCore/CircularBuffer.h | 9 +++++++++ MMCore/ConfigGroup.h | 19 +++++++++++++++++++ MMCore/Configuration.cpp | 9 +++++++++ MMCore/Configuration.h | 10 ++++++++++ MMCore/MMCore.cpp | 10 +++++++++- MMCore/MMCore.h | 10 ++++++++++ MMDevice/ImageMetadata.h | 12 +++++++++++- 8 files changed, 85 insertions(+), 2 deletions(-) diff --git a/MMCore/CircularBuffer.cpp b/MMCore/CircularBuffer.cpp index 1b796a4e9..933142e9b 100644 --- a/MMCore/CircularBuffer.cpp +++ b/MMCore/CircularBuffer.cpp @@ -36,6 +36,14 @@ #include #include +#ifdef _MSC_VER +#pragma warning(disable: 4290) // 'C++ exception specification ignored' +#endif + +#if defined(__GNUC__) && !defined(__clang__) +// 'dynamic exception specifications are deprecated in C++11 [-Wdeprecated]' +#pragma GCC diagnostic ignored "-Wdeprecated" +#endif const long long bytesInMB = 1 << 20; const long adjustThreshold = LONG_MAX / 2; diff --git a/MMCore/CircularBuffer.h b/MMCore/CircularBuffer.h index d42ea4a47..636c02ceb 100644 --- a/MMCore/CircularBuffer.h +++ b/MMCore/CircularBuffer.h @@ -40,6 +40,11 @@ #pragma warning(disable: 4290) // 'C++ exception specification ignored' #endif +#if defined(__GNUC__) && !defined(__clang__) +#pragma GCC diagnostic push +// 'dynamic exception specifications are deprecated in C++11 [-Wdeprecated]' +#pragma GCC diagnostic ignored "-Wdeprecated" +#endif class ThreadPool; class TaskSet_CopyMemory; @@ -101,6 +106,10 @@ class CircularBuffer std::shared_ptr tasksMemCopy_; }; +#if defined(__GNUC__) && !defined(__clang__) +#pragma GCC diagnostic pop +#endif + #ifdef _MSC_VER #pragma warning(pop) #endif diff --git a/MMCore/ConfigGroup.h b/MMCore/ConfigGroup.h index 050020815..a5b7d41bd 100644 --- a/MMCore/ConfigGroup.h +++ b/MMCore/ConfigGroup.h @@ -22,6 +22,17 @@ #pragma once +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable: 4290) // 'C++ exception specification ignored' +#endif + +#if defined(__GNUC__) && !defined(__clang__) +#pragma GCC diagnostic push +// 'dynamic exception specifications are deprecated in C++11 [-Wdeprecated]' +#pragma GCC diagnostic ignored "-Wdeprecated" +#endif + #include "Configuration.h" #include "Error.h" #include @@ -436,3 +447,11 @@ class PixelSizeConfigGroup : public ConfigGroupBase } } }; + +#if defined(__GNUC__) && !defined(__clang__) +#pragma GCC diagnostic pop +#endif + +#ifdef _MSC_VER +#pragma warning(pop) +#endif \ No newline at end of file diff --git a/MMCore/Configuration.cpp b/MMCore/Configuration.cpp index 32c8fa8ae..acd2df824 100644 --- a/MMCore/Configuration.cpp +++ b/MMCore/Configuration.cpp @@ -27,6 +27,15 @@ #include #include +#ifdef _MSC_VER +#pragma warning(disable: 4290) // 'C++ exception specification ignored' +#endif + +#if defined(__GNUC__) && !defined(__clang__) +// 'dynamic exception specifications are deprecated in C++11 [-Wdeprecated]' +#pragma GCC diagnostic ignored "-Wdeprecated" +#endif + std::string PropertySetting::generateKey(const char* device, const char* prop) { std::string key(device); diff --git a/MMCore/Configuration.h b/MMCore/Configuration.h index 4cd4a6ce7..16a2b775b 100644 --- a/MMCore/Configuration.h +++ b/MMCore/Configuration.h @@ -25,6 +25,12 @@ #pragma warning(disable: 4290) // 'C++ exception specification ignored' #endif +#if defined(__GNUC__) && !defined(__clang__) +#pragma GCC diagnostic push +// 'dynamic exception specifications are deprecated in C++11 [-Wdeprecated]' +#pragma GCC diagnostic ignored "-Wdeprecated" +#endif + #include #include #include @@ -119,6 +125,10 @@ class Configuration std::map index_; }; +#if defined(__GNUC__) && !defined(__clang__) +#pragma GCC diagnostic pop +#endif + #ifdef _MSC_VER #pragma warning(pop) #endif diff --git a/MMCore/MMCore.cpp b/MMCore/MMCore.cpp index e3eb01bc9..1db4309a9 100644 --- a/MMCore/MMCore.cpp +++ b/MMCore/MMCore.cpp @@ -37,7 +37,6 @@ // because all public methods will most likely appear in other // programming environments (Java or Python). - #include "../MMDevice/DeviceThreads.h" #include "../MMDevice/DeviceUtils.h" #include "../MMDevice/ImageMetadata.h" @@ -65,6 +64,15 @@ #include #include +#ifdef _MSC_VER +#pragma warning(disable: 4290) // 'C++ exception specification ignored' +#endif + +#if defined(__GNUC__) && !defined(__clang__) +// 'dynamic exception specifications are deprecated in C++11 [-Wdeprecated]' +#pragma GCC diagnostic ignored "-Wdeprecated" +#endif + /* * Important! Read this before changing this file: * diff --git a/MMCore/MMCore.h b/MMCore/MMCore.h index e320b6c1f..542b954ca 100644 --- a/MMCore/MMCore.h +++ b/MMCore/MMCore.h @@ -52,6 +52,12 @@ #pragma warning(disable: 4290) // 'C++ exception specification ignored' #endif +#if defined(__GNUC__) && !defined(__clang__) +#pragma GCC diagnostic push +// 'dynamic exception specifications are deprecated in C++11 [-Wdeprecated]' +#pragma GCC diagnostic ignored "-Wdeprecated" +#endif + #include "../MMDevice/DeviceThreads.h" #include "../MMDevice/MMDevice.h" #include "../MMDevice/MMDeviceConstants.h" @@ -693,6 +699,10 @@ class CMMCore void loadSystemConfigurationImpl(const char* fileName) throw (CMMError); }; +#if defined(__GNUC__) && !defined(__clang__) +#pragma GCC diagnostic pop +#endif + #ifdef _MSC_VER #pragma warning(pop) #endif diff --git a/MMDevice/ImageMetadata.h b/MMDevice/ImageMetadata.h index eebebfbd0..98f5c8a64 100644 --- a/MMDevice/ImageMetadata.h +++ b/MMDevice/ImageMetadata.h @@ -27,6 +27,12 @@ #pragma warning(disable: 4290) // 'C++ exception specification ignored' #endif +#if defined(__GNUC__) && !defined(__clang__) +#pragma GCC diagnostic push +// 'dynamic exception specifications are deprecated in C++11 [-Wdeprecated]' +#pragma GCC diagnostic ignored "-Wdeprecated" +#endif + #include "MMDeviceConstants.h" #include @@ -319,7 +325,7 @@ class Metadata else return false; } - + MetadataSingleTag GetSingleTag(const char* key) const throw (MetadataKeyError) { MetadataTag* tag = FindTag(key); @@ -494,6 +500,10 @@ class Metadata typedef std::map::const_iterator TagConstIter; }; +#if defined(__GNUC__) && !defined(__clang__) +#pragma GCC diagnostic pop +#endif + #ifdef _MSC_VER #pragma warning(pop) #endif From 97ecc51a3e7214dd312c6b2f00f0bf9e30bfb7d7 Mon Sep 17 00:00:00 2001 From: "Mark A. Tsuchida" Date: Thu, 14 Dec 2023 14:49:37 -0600 Subject: [PATCH 4/5] MMCore: Remove warning suppression from build The warnings for dynamic exception specifications are now suppressed in the code using pragmas for both GCC and MSVC. --- MMCore/MMCore.vcxproj | 4 +--- MMCore/meson.build | 1 - 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/MMCore/MMCore.vcxproj b/MMCore/MMCore.vcxproj index 26d732feb..413f2b563 100644 --- a/MMCore/MMCore.vcxproj +++ b/MMCore/MMCore.vcxproj @@ -55,7 +55,6 @@ true - 4290;%(DisableSpecificWarnings) $(OutDir)MMCore.lib @@ -70,7 +69,6 @@ true - 4290;%(DisableSpecificWarnings) $(OutDir)MMCore.lib @@ -183,4 +181,4 @@ - \ No newline at end of file + diff --git a/MMCore/meson.build b/MMCore/meson.build index b60ab51fc..d7399dc29 100644 --- a/MMCore/meson.build +++ b/MMCore/meson.build @@ -15,7 +15,6 @@ cxx = meson.get_compiler('cpp') if cxx.get_id() in ['msvc', 'clang-cl'] add_project_arguments('-DNOMINMAX', language: 'cpp') - add_project_arguments('/wd4290', language: 'cpp') endif # MMDevice must be copied into subprojects/ for this experimental build to work From d5a58b7f906753db4d9ae9575ef0c76b18b51982 Mon Sep 17 00:00:00 2001 From: "Mark A. Tsuchida" Date: Thu, 14 Dec 2023 15:14:34 -0600 Subject: [PATCH 5/5] MMCore: Don't free() arrays allocated by 'new' And don't manually manage memory to begin with; use std::vector. --- MMCore/MMCore.cpp | 56 +++++++++++++---------------------------------- 1 file changed, 15 insertions(+), 41 deletions(-) diff --git a/MMCore/MMCore.cpp b/MMCore/MMCore.cpp index 1db4309a9..22c2c2ecc 100644 --- a/MMCore/MMCore.cpp +++ b/MMCore/MMCore.cpp @@ -4458,23 +4458,10 @@ void CMMCore::setMultiROI(std::vector xs, std::vector ys, throw CMMError(getCoreErrorText(MMERR_CameraNotAvailable).c_str(), MMERR_CameraNotAvailable); } mm::DeviceModuleLockGuard guard(camera); - unsigned numROI = (unsigned) xs.size(); - unsigned* xsArr = new unsigned[numROI]; - unsigned* ysArr = new unsigned[numROI]; - unsigned* widthsArr = new unsigned[numROI]; - unsigned* heightsArr = new unsigned[numROI]; - for (unsigned i = 0; i < numROI; ++i) - { - xsArr[i] = xs[i]; - ysArr[i] = ys[i]; - widthsArr[i] = widths[i]; - heightsArr[i] = heights[i]; - } - int nRet = camera->SetMultiROI(xsArr, ysArr, widthsArr, heightsArr, numROI); - free(xsArr); - free(ysArr); - free(widthsArr); - free(heightsArr); + const unsigned numROI = (unsigned) xs.size(); + int nRet = camera->SetMultiROI(xs.data(), ys.data(), + widths.data(), heights.data(), + numROI); if (nRet != DEVICE_OK) { throw CMMError(getDeviceErrorText(nRet, camera).c_str(), MMERR_DEVICE_GENERIC); @@ -4507,18 +4494,16 @@ void CMMCore::getMultiROI(std::vector& xs, std::vector& ys, throw CMMError(getDeviceErrorText(nRet, camera).c_str(), MMERR_DEVICE_GENERIC); } - unsigned* xsArr = new unsigned[numROI]; - unsigned* ysArr = new unsigned[numROI]; - unsigned* widthsArr = new unsigned[numROI]; - unsigned* heightsArr = new unsigned[numROI]; + std::vector xsTmp(numROI); + std::vector ysTmp(numROI); + std::vector widthsTmp(numROI); + std::vector heightsTmp(numROI); unsigned newNum = numROI; - nRet = camera->GetMultiROI(xsArr, ysArr, widthsArr, heightsArr, &newNum); + nRet = camera->GetMultiROI(xsTmp.data(), ysTmp.data(), + widthsTmp.data(), heightsTmp.data(), + &newNum); if (nRet != DEVICE_OK) { - free(xsArr); - free(ysArr); - free(widthsArr); - free(heightsArr); throw CMMError(getDeviceErrorText(nRet, camera).c_str(), MMERR_DEVICE_GENERIC); } if (newNum > numROI) @@ -4527,21 +4512,10 @@ void CMMCore::getMultiROI(std::vector& xs, std::vector& ys, throw CMMError("Camera returned too many ROIs"); } - xs.clear(); - ys.clear(); - widths.clear(); - heights.clear(); - for (unsigned i = 0; i < newNum; ++i) - { - xs.push_back(xsArr[i]); - ys.push_back(ysArr[i]); - widths.push_back(widthsArr[i]); - heights.push_back(heightsArr[i]); - } - free(xsArr); - free(ysArr); - free(widthsArr); - free(heightsArr); + xs.swap(xsTmp); + ys.swap(ysTmp); + widths.swap(widthsTmp); + heights.swap(heightsTmp); } /**