Skip to content

Commit

Permalink
Merge pull request #417 from micro-manager/mmdevice-mmcore-warnings
Browse files Browse the repository at this point in the history
Fix GCC and Clang warnings in MMDevice, MMCore
  • Loading branch information
marktsuchida authored Dec 14, 2023
2 parents 4db4ff1 + d5a58b7 commit e0dac2c
Show file tree
Hide file tree
Showing 11 changed files with 104 additions and 50 deletions.
8 changes: 8 additions & 0 deletions MMCore/CircularBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@
#include <memory>
#include <string>

#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;
Expand Down
9 changes: 9 additions & 0 deletions MMCore/CircularBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -101,6 +106,10 @@ class CircularBuffer
std::shared_ptr<TaskSet_CopyMemory> tasksMemCopy_;
};

#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic pop
#endif

#ifdef _MSC_VER
#pragma warning(pop)
#endif
19 changes: 19 additions & 0 deletions MMCore/ConfigGroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <string>
Expand Down Expand Up @@ -436,3 +447,11 @@ class PixelSizeConfigGroup : public ConfigGroupBase<PixelSizeConfiguration>
}
}
};

#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic pop
#endif

#ifdef _MSC_VER
#pragma warning(pop)
#endif
9 changes: 9 additions & 0 deletions MMCore/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@
#include <sstream>
#include <string>

#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);
Expand Down
10 changes: 10 additions & 0 deletions MMCore/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <string>
#include <vector>
#include <map>
Expand Down Expand Up @@ -119,6 +125,10 @@ class Configuration
std::map<std::string, int> index_;
};

#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic pop
#endif

#ifdef _MSC_VER
#pragma warning(pop)
#endif
66 changes: 24 additions & 42 deletions MMCore/MMCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -65,6 +64,15 @@
#include <sstream>
#include <vector>

#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:
*
Expand Down Expand Up @@ -4450,23 +4458,10 @@ void CMMCore::setMultiROI(std::vector<unsigned> xs, std::vector<unsigned> 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);
Expand Down Expand Up @@ -4499,18 +4494,16 @@ void CMMCore::getMultiROI(std::vector<unsigned>& xs, std::vector<unsigned>& 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<unsigned> xsTmp(numROI);
std::vector<unsigned> ysTmp(numROI);
std::vector<unsigned> widthsTmp(numROI);
std::vector<unsigned> 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)
Expand All @@ -4519,21 +4512,10 @@ void CMMCore::getMultiROI(std::vector<unsigned>& xs, std::vector<unsigned>& 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);
}

/**
Expand Down
10 changes: 10 additions & 0 deletions MMCore/MMCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
4 changes: 1 addition & 3 deletions MMCore/MMCore.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
<RuntimeTypeInfo>true</RuntimeTypeInfo>
<PrecompiledHeader>
</PrecompiledHeader>
<DisableSpecificWarnings>4290;%(DisableSpecificWarnings)</DisableSpecificWarnings>
</ClCompile>
<Lib>
<OutputFile>$(OutDir)MMCore.lib</OutputFile>
Expand All @@ -70,7 +69,6 @@
<RuntimeTypeInfo>true</RuntimeTypeInfo>
<PrecompiledHeader>
</PrecompiledHeader>
<DisableSpecificWarnings>4290;%(DisableSpecificWarnings)</DisableSpecificWarnings>
</ClCompile>
<Lib>
<OutputFile>$(OutDir)MMCore.lib</OutputFile>
Expand Down Expand Up @@ -183,4 +181,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>
1 change: 0 additions & 1 deletion MMCore/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 13 additions & 3 deletions MMDevice/ImageMetadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <string>
Expand Down Expand Up @@ -101,7 +107,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;}
Expand Down Expand Up @@ -319,7 +325,7 @@ class Metadata
else
return false;
}

MetadataSingleTag GetSingleTag(const char* key) const throw (MetadataKeyError)
{
MetadataTag* tag = FindTag(key);
Expand Down Expand Up @@ -494,6 +500,10 @@ class Metadata
typedef std::map<std::string, MetadataTag*>::const_iterator TagConstIter;
};

#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic pop
#endif

#ifdef _MSC_VER
#pragma warning(pop)
#endif
#endif
2 changes: 1 addition & 1 deletion MMDevice/Property.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit e0dac2c

Please sign in to comment.