Commit 2f05d8b5 authored by Samuel Debionne's avatar Samuel Debionne

Merge branch 'remove_compiler_warnings' into 'master'

Fix bugs and remove (gcc) compiler warnings

See merge request !158
parents 175a8114 06cb1234
Pipeline #26215 failed with stages
in 60 minutes and 6 seconds
......@@ -30,8 +30,12 @@
#else
#define LIMACORE_API __declspec(dllimport)
#endif
#define LIMA_MAYBE_UNUSED
#else /* Unix */
#define LIMACORE_API
#define LIMA_MAYBE_UNUSED [[maybe_unused]]
#endif
#endif //- LIMACOMPATIBILITY_H
......@@ -25,8 +25,7 @@
#include "lima/LimaCompatibility.h"
#include "lima/SizeUtils.h"
#include "lima/Debug.h"
#include <cassert>
#include "lima/Exceptions.h"
namespace lima
{
......@@ -50,14 +49,22 @@ struct LIMACORE_API Allocator
Allocator() : m_ref_count(0)
{}
Allocator(const Allocator& o) : m_ref_count(0)
Allocator(const Allocator& /*o*/) : m_ref_count(0)
{}
Allocator(Allocator&& o) : m_ref_count(0)
{ assert(o.m_ref_count == 0); }
{
if (o.m_ref_count != 0)
throw LIMA_COM_EXC(InvalidValue,
"Moved-from Allocator is not empty");
}
~Allocator()
{ assert(m_ref_count == 0); }
{
if (m_ref_count != 0)
std::cerr << "Error: destroying non-empty Allocator"
<< std::endl;
}
// Allocate a buffer of a given size and eventually return
// the associated allocator data and potentially modified size
......
......@@ -278,12 +278,15 @@ class LIMACORE_API CmdThread
int m_status;
//No need to have dll-interface for private variables
#if defined(_WIN32)
#pragma warning( push )
#pragma warning( disable : 4251 )
#pragma warning( disable : 4251 )
#endif
std::bitset<16> m_status_history;
std::queue<int> m_cmd;
#if defined(_WIN32)
#pragma warning( pop )
#endif
mutable Cond m_cond;
AuxThread m_thread;
};
......
......@@ -38,12 +38,13 @@ namespace lima
enum Stat {DOWN,DELAY,UP,RISING_EDGE,FALLING_EDGE};
class Callback
{
friend class Timer;
protected:
virtual void start() {}
virtual void risingEdge() {}
virtual void fallingEdge() {}
virtual void end() {}
private:
friend class Timer;
};
Timer(Callback* = NULL);
......
......@@ -66,7 +66,9 @@ typedef const char *ConstStr;
%UnitCode
#include <string>
#include "lima/LimaCompatibility.h"
LIMA_MAYBE_UNUSED
static const char *getConstStr(const std::string *s)
{
return (!s || s->empty()) ? NULL : s->c_str();
......
......@@ -412,7 +412,7 @@ _GenericDirectoryEvent::~_GenericDirectoryEvent()
m_cond.signal();
lock.unlock();
void *tReturn;
if(m_thread_id >= 0)
if(m_thread_id != pthread_t(-1))
pthread_join(m_thread_id,&tReturn);
}
void _GenericDirectoryEvent::_run()
......
......@@ -20,9 +20,7 @@
// along with this program; if not, see <http://www.gnu.org/licenses/>.
//###########################################################################
#include "lima/MemUtils.h"
#include "lima/Exceptions.h"
#include <cassert>
#include <cstdlib>
#include <sstream>
#ifdef __unix
......@@ -47,11 +45,11 @@ using namespace std;
void lima::GetSystemMem(int& mem_unit, int& system_mem)
{
if (mem_unit < 0)
throw LIMA_HW_EXC(InvalidValue, "Invalid mem_unit value");
throw LIMA_COM_EXC(InvalidValue, "Invalid mem_unit value");
#ifdef __unix
struct sysinfo s_info;
if (sysinfo(&s_info) < 0)
throw LIMA_HW_EXC(Error, "Error calling sysinfo");
throw LIMA_COM_EXC(Error, "Error calling sysinfo");
long long tot_mem = s_info.totalram;
tot_mem *= s_info.mem_unit;
......@@ -95,7 +93,7 @@ int lima::GetDefMaxNbBuffers(const FrameDim& frame_dim)
{
int frame_size = frame_dim.getMemSize();
if (frame_size <= 0)
throw LIMA_HW_EXC(InvalidValue, "Invalid FrameDim");
throw LIMA_COM_EXC(InvalidValue, "Invalid FrameDim");
int tot_buffers;
GetSystemMem(frame_size, tot_buffers);
......@@ -159,14 +157,14 @@ int MMapAllocator::getPageAlignedSize(int size)
// Allocate a buffer of a given size
Allocator::DataPtr MMapAllocator::alloc(void* &ptr, size_t& size,
size_t alignment/* = 16*/)
size_t /*alignment = 16*/)
{
ptr = allocMmap(size);
return DataPtr();
}
// Free a buffer
void MMapAllocator::release(void* ptr, size_t size, DataPtr alloc_data)
void MMapAllocator::release(void* ptr, size_t size, DataPtr /*alloc_data*/)
{
size = getPageAlignedSize(size);
munmap(ptr, size);
......@@ -185,24 +183,24 @@ void *MMapAllocator::allocMmap(size_t& size)
#endif //__unix
MemBuffer::MemBuffer(Allocator *allocator /*= Allocator::defaultAllocator()*/) :
m_ptr(nullptr),
m_size(0),
m_ptr(nullptr),
m_allocator(allocator)
{
}
MemBuffer::MemBuffer(int size, Allocator *allocator /*=
Allocator::defaultAllocator()*/):
m_ptr(nullptr),
m_size(0),
m_ptr(nullptr),
m_allocator(allocator)
{
alloc(size);
}
MemBuffer::MemBuffer(const MemBuffer& buffer) :
m_ptr(nullptr),
m_size(0),
m_ptr(nullptr),
m_allocator(buffer.m_allocator)
{
deepCopy(buffer);
......@@ -220,8 +218,8 @@ MemBuffer& MemBuffer::operator =(const MemBuffer& buffer)
// Steal buffer ressource
MemBuffer::MemBuffer(MemBuffer&& rhs) :
m_ptr(move(rhs.m_ptr)),
m_size(move(rhs.m_size)),
m_ptr(move(rhs.m_ptr)),
m_allocator(move(rhs.m_allocator))
{
// Finish resource transfer: remove it from rhs so
......@@ -272,7 +270,8 @@ void MemBuffer::clear()
void MemBuffer::uninitializedAlloc(size_t size)
{
assert(m_allocator);
if (!m_allocator)
throw LIMA_COM_EXC(InvalidValue, "No Allocator was defined");
if (m_size == size)
return;
......
......@@ -132,6 +132,7 @@ int SimpleRegEx::findNbGroups(const string& regex_str)
case '(':
if (!in_escape)
nb_groups++;
[[fallthrough]];
default:
in_escape = false;
}
......
......@@ -167,7 +167,7 @@ void Pipe::write(string s)
DEB_PARAM() << DEB_VAR1(s);
int fd = m_stream[WriteFd].getFd();
if (::write(fd, s.data(), s.size()) < s.size())
if (::write(fd, s.data(), s.size()) < ssize_t(s.size()))
THROW_COM_ERROR(Error) << "error writing to pipe";
}
......
......@@ -68,7 +68,7 @@ void test_alloc()
assert(d.getConstPtr() != b.getConstPtr());
//Move construction (from lvalue)
const void *ptr = b.getConstPtr();
LIMA_MAYBE_UNUSED const void *ptr = b.getConstPtr();
MemBuffer e(std::move(b));
assert(e.getSize() == 1);
assert(e.getConstPtr() == ptr);
......@@ -94,7 +94,8 @@ void test_alloc()
struct MockAllocator : lima::Allocator
{
virtual DataPtr alloc(void* &ptr, size_t& size, size_t alignment = 16) override
virtual DataPtr alloc(void* &ptr, size_t& size,
size_t /*alignment = 16*/) override
{
ptr = malloc(size);
return DataPtr();
......@@ -142,7 +143,7 @@ void test_custom_allocator()
assert(d.getAllocator() == &allocator);
//Move construction
const void *ptr = b.getConstPtr();
LIMA_MAYBE_UNUSED const void *ptr = b.getConstPtr();
MemBuffer e(std::move(b));
assert(e.getSize() == 1);
assert(e.getConstPtr() == ptr);
......@@ -160,7 +161,7 @@ void test_custom_allocator()
}
int main(int argc, char *argv[])
int main(int /*argc*/, char */*argv*/[])
{
try {
test_empty();
......
......@@ -74,7 +74,7 @@ private:
initializer_list<Key> vals;
};
int main(int argc, char *argv[])
int main(int /*argc*/, char */*argv*/[])
{
test_ordered_map<int> tint {"int", {2, 1, 0, 4}};
test_ordered_map<string> tstr {"string", {"2", "1", "0", "4"}};
......
......@@ -110,7 +110,7 @@ void test_regex(const string& re_str, const string& s)
}
int main(int argc, char *argv[])
int main(int /*argc*/, char */*argv*/[])
{
try {
test_simple_regex("(b)?ab((ab)(\\3c))?", "abababc.bab");
......
......@@ -171,8 +171,8 @@ namespace lima
const char *name = "Unknown";
switch(accTimeMode)
{
case CtAcquisition::Live: name = "Live";
case CtAcquisition::Real: name = "Real";
case CtAcquisition::Live: name = "Live"; break;
case CtAcquisition::Real: name = "Real"; break;
}
return name;
}
......
......@@ -69,8 +69,9 @@ inline bool ZBuffer::_isValid() const
inline void ZBuffer::_setInvalid()
{
used_size = 0;
alloc_size = 0;
buffer = NULL;
alloc_size = used_size = 0;
}
inline ZBuffer::ZBuffer(int buffer_size)
......@@ -89,8 +90,8 @@ inline ZBuffer::ZBuffer(const ZBuffer& o)
}
inline ZBuffer::ZBuffer(ZBuffer&& o)
: alloc_size(std::move(o.alloc_size)),
used_size(std::move(o.used_size)), buffer(std::move(o.buffer))
: used_size(std::move(o.used_size)), alloc_size(std::move(o.alloc_size)),
buffer(std::move(o.buffer))
{
DEB_CONSTRUCTOR();
o._setInvalid();
......
......@@ -801,7 +801,7 @@ SoftOpPeakFinder::~SoftOpPeakFinder()
{
m_opt->unref();
}
void SoftOpPeakFinder::setMask(Data& aMask)
void SoftOpPeakFinder::setMask(Data& /*aMask*/)
{
}
......
......@@ -165,7 +165,7 @@ class CtAccumulation::_CalcEndCBK : public TaskEventCallback
DEB_CLASS_NAMESPC(DebModControl,"_CalcEndCBK","Control");
public:
_CalcEndCBK(CtAccumulation &cnt) : m_cnt(cnt) {}
virtual void finished(Data &aData)
virtual void finished(Data &/*aData*/)
{
AutoMutex Lock(m_cnt.m_cond.mutex());
if(m_cnt.m_calc_pending_data.empty())
......
......@@ -110,7 +110,7 @@ public:
_AbortAcqCallback(CtControl &ctrl) :
TaskEventCallback(),_ctrl(ctrl) {}
virtual void finished(Data &aData)
virtual void finished(Data &/*aData*/)
{
_ctrl.stopAcq();
}
......@@ -226,7 +226,7 @@ void CtControl::ImageStatusThread::imageStatusChanged(const ImageStatus& status,
return;
}
volatile bool finished = false;
bool finished = false;
ChangeEvent *event = new ChangeEvent;
event->status = status;
event->force = force;
......
......@@ -2054,8 +2054,8 @@ CtConfig::ModuleTypeCallback* CtSaving::_getConfigHandler()
CtSaving::SaveContainer::SaveContainer(Stream& stream)
: m_stream(stream), m_statistic_size(16),
m_max_writing_task(1), m_running_writing_task(0),
m_log_stat_enable(false), m_log_stat_file(NULL)
m_log_stat_enable(false), m_log_stat_file(NULL),
m_max_writing_task(1), m_running_writing_task(0)
{
DEB_CONSTRUCTOR();
}
......@@ -2200,7 +2200,7 @@ void CtSaving::SaveContainer::writeFileStat(Data& aData, Timestamp start, Timest
write_rate = i->second.write_size / write_time / 1024. / 1024.;
total_time = i->second.writing_end - i->second.received_time;
fprintf(m_log_stat_file, "%d %.2f %.2f %.2f %.2f %.2f %.2f %.2f\n", \
fprintf(m_log_stat_file, "%ld %.2f %.2f %.2f %.2f %.2f %.2f %.2f\n", \
frameId, (double)i->second.received_time, \
comp_time * 1000.0, comp_rate, comp_ratio, \
write_time * 1000.0, write_rate, total_time * 1000.0);
......
......@@ -32,7 +32,7 @@ const int FileZCompression::BUFFER_HELPER_SIZE = 64 * 1024;
FileZCompression::FileZCompression(CtSaving::SaveContainer &save_cnt,
int framesPerFile,const CtSaving::HeaderMap &header) :
m_container(save_cnt),m_frame_per_file(framesPerFile)
m_container(save_cnt),m_frame_per_file(framesPerFile),m_header(header)
{
DEB_CONSTRUCTOR();
......@@ -225,7 +225,7 @@ void ImageBsCompression::_compression(const char *src,int data_size,int data_dep
unsigned int bs_block_size= 0;
unsigned int bs_in_size= (unsigned int)(data_size/data_depth);
unsigned int bs_out_size;
int64_t bs_out_size;
return_buffers.emplace_back(data_size);
ZBuffer& newBuffer = return_buffers.back();
......
......@@ -121,7 +121,7 @@ DataType get_h5_type(unsigned long long) {return PredType(PredType::NATIVE_UINT6
DataType get_h5_type(long long) {return PredType(PredType::NATIVE_INT64);}
DataType get_h5_type(float) {return PredType(PredType::NATIVE_FLOAT);}
DataType get_h5_type(double) {return PredType(PredType::NATIVE_DOUBLE);}
DataType get_h5_type(std::string& s) {StrType type = StrType(H5T_C_S1, H5T_VARIABLE); type.setCset(H5T_CSET_UTF8); return type;}
DataType get_h5_type(std::string& /*s*/) {StrType type = StrType(H5T_C_S1, H5T_VARIABLE); type.setCset(H5T_CSET_UTF8); return type;}
DataType get_h5_type(bool) {return PredType(PredType::NATIVE_UINT8);}
template <class T>
......@@ -176,6 +176,7 @@ void write_h5_attribute(L location,const char* entry_name,std::string& val)
*
*
*/
LIMA_MAYBE_UNUSED
static void calculate_chunck(hsize_t* data_size, hsize_t* chunck, int depth)
{
const double request_chunck_size = 256.;
......@@ -606,13 +607,10 @@ long SaveContainerHdf5::_writeFile(void* f,Data &aData,
file->m_instrument_detector_header = NULL;
// create the image data structure in the file
hsize_t data_dims[3], max_dims[3];
hsize_t data_dims[3];
data_dims[1] = aData.dimensions[1];
data_dims[2] = aData.dimensions[0];
data_dims[0] = m_nbframes;
max_dims[1] = aData.dimensions[1];
max_dims[2] = aData.dimensions[0];
max_dims[0] = H5S_UNLIMITED;
// Create property list for the dataset and setup chunk size
DSetCreatPropList plist;
hsize_t chunk_dims[RANK_THREE];
......@@ -743,7 +741,7 @@ int SaveContainerHdf5::findLastEntry(const _File &file) {
return index;
}
SinkTaskBase* SaveContainerHdf5::getCompressionTask(const CtSaving::HeaderMap& header)
SinkTaskBase* SaveContainerHdf5::getCompressionTask(const CtSaving::HeaderMap& /*header*/)
{
#if defined(WITH_Z_COMPRESSION)
if(m_format == CtSaving::HDF5GZ)
......
......@@ -57,7 +57,7 @@ SaveContainerTiff::~SaveContainerTiff()
}
void* SaveContainerTiff::_open(const std::string &filename,
std::ios_base::openmode flags)
std::ios_base::openmode /*flags*/)
{
DEB_MEMBER_FUNCT();
return new std::string(filename);
......@@ -71,8 +71,8 @@ void SaveContainerTiff::_close(void* f)
}
long SaveContainerTiff::_writeFile(void* f,Data &aData,
CtSaving::HeaderMap &aHeader,
CtSaving::FileFormat aFormat)
CtSaving::HeaderMap &/*aHeader*/,
CtSaving::FileFormat /*aFormat*/)
{
DEB_MEMBER_FUNCT();
......@@ -92,8 +92,8 @@ long SaveContainerTiff::_writeFile(void* f,Data &aData,
TIFFSetField(image, TIFFTAG_IMAGEWIDTH, aData.dimensions[0]);
TIFFSetField(image, TIFFTAG_IMAGELENGTH, aData.dimensions[1]);
int sampleformat;
int bytespersample;
int sampleformat = SAMPLEFORMAT_UINT;
int bytespersample = 0;
switch(aData.type)
{
......
......@@ -26,7 +26,7 @@
using namespace std;
using namespace lima;
int main(int argc, char *argv[])
int main(int /*argc*/, char */*argv*/[])
{
cout << "Hello!" << endl;
......
......@@ -157,7 +157,7 @@ void HwBufferSave::writeEdfHeader( const HwFrameInfoType& finfo )
long rem = len % EDF_HEADER_LEN;
if (rem > 0)
len += EDF_HEADER_LEN - rem;
p += snprintf(p, sizeof(buffer) - (p - buffer), "%*s}\n", len - (l + 2), "");
p += snprintf(p, sizeof(buffer) - (p - buffer), "%*s}\n", int(len - (l + 2)), "");
len = long(p - buffer);
m_fout->write(buffer, len);
......
......@@ -25,70 +25,70 @@ namespace lima
{
HwCap::Type HwCap::getTypeFromCtrlObj(HwDetInfoCtrlObj *p)
HwCap::Type HwCap::getTypeFromCtrlObj(HwDetInfoCtrlObj */*p*/)
{
return DetInfo;
}
HwCap::Type HwCap::getTypeFromCtrlObj(HwBufferCtrlObj *p)
HwCap::Type HwCap::getTypeFromCtrlObj(HwBufferCtrlObj */*p*/)
{
return Buffer;
}
HwCap::Type HwCap::getTypeFromCtrlObj(HwSyncCtrlObj *p)
HwCap::Type HwCap::getTypeFromCtrlObj(HwSyncCtrlObj */*p*/)
{
return Sync;
}
HwCap::Type HwCap::getTypeFromCtrlObj(HwBinCtrlObj *p)
HwCap::Type HwCap::getTypeFromCtrlObj(HwBinCtrlObj */*p*/)
{
return Bin;
}
HwCap::Type HwCap::getTypeFromCtrlObj(HwRoiCtrlObj *p)
HwCap::Type HwCap::getTypeFromCtrlObj(HwRoiCtrlObj */*p*/)
{
return Roi;
}
HwCap::Type HwCap::getTypeFromCtrlObj(HwFlipCtrlObj *p)
HwCap::Type HwCap::getTypeFromCtrlObj(HwFlipCtrlObj */*p*/)
{
return Flip;
}
HwCap::Type HwCap::getTypeFromCtrlObj(HwShutterCtrlObj *p)
HwCap::Type HwCap::getTypeFromCtrlObj(HwShutterCtrlObj */*p*/)
{
return Shutter;
}
HwCap::Type HwCap::getTypeFromCtrlObj(HwVideoCtrlObj *p)
HwCap::Type HwCap::getTypeFromCtrlObj(HwVideoCtrlObj */*p*/)
{
return Video;
}
HwCap::Type HwCap::getTypeFromCtrlObj(HwEventCtrlObj *p)
HwCap::Type HwCap::getTypeFromCtrlObj(HwEventCtrlObj */*p*/)
{
return Event;
}
HwCap::Type HwCap::getTypeFromCtrlObj(HwSavingCtrlObj*)
HwCap::Type HwCap::getTypeFromCtrlObj(HwSavingCtrlObj */*p*/)
{
return Saving;
}
HwCap::Type HwCap::getTypeFromCtrlObj(HwConfigCtrlObj*)
HwCap::Type HwCap::getTypeFromCtrlObj(HwConfigCtrlObj */*p*/)
{
return Config;
}
HwCap::Type HwCap::getTypeFromCtrlObj(HwReconstructionCtrlObj*)
HwCap::Type HwCap::getTypeFromCtrlObj(HwReconstructionCtrlObj */*p*/)
{
return Reconstruction;
}
......
......@@ -104,70 +104,70 @@ HwSavingCtrlObj::~HwSavingCtrlObj()
#endif
}
void HwSavingCtrlObj::setActive(bool flag, int stream_idx)
void HwSavingCtrlObj::setActive(bool flag, int /*stream_idx*/)
{
_setActive(flag);
m_active = flag;
}
bool HwSavingCtrlObj::isActive(int stream_idx) const
bool HwSavingCtrlObj::isActive(int /*stream_idx*/) const
{
return m_active;
}
void HwSavingCtrlObj::setDirectory(const std::string& directory, int stream_idx)
void HwSavingCtrlObj::setDirectory(const std::string& directory, int /*stream_idx*/)
{
m_directory = directory;
}
void HwSavingCtrlObj::setPrefix(const std::string& prefix, int stream_idx)
void HwSavingCtrlObj::setPrefix(const std::string& prefix, int /*stream_idx*/)
{
m_prefix = prefix;
}
void HwSavingCtrlObj::setSuffix(const std::string& suffix, int stream_idx)
void HwSavingCtrlObj::setSuffix(const std::string& suffix, int /*stream_idx*/)
{
m_suffix = suffix;
}
void HwSavingCtrlObj::setOptions(const std::string& options, int stream_idx)
void HwSavingCtrlObj::setOptions(const std::string& options, int /*stream_idx*/)
{
m_options = options;
}
void HwSavingCtrlObj::setNextNumber(long number, int stream_idx)
void HwSavingCtrlObj::setNextNumber(long number, int /*stream_idx*/)
{
m_next_number = number;
}
void HwSavingCtrlObj::setIndexFormat(const std::string& indexFormat, int stream_idx)
void HwSavingCtrlObj::setIndexFormat(const std::string& indexFormat, int /*stream_idx*/)
{
m_index_format = indexFormat;
}
void HwSavingCtrlObj::setFramesPerFile(long frames_per_file, int stream_idx)
void HwSavingCtrlObj::setFramesPerFile(long frames_per_file, int /*stream_idx*/)
{
m_frames_per_file = frames_per_file;
}
void HwSavingCtrlObj::setSaveFormat(const std::string &format, int stream_idx)
void HwSavingCtrlObj::setSaveFormat(const std::string &format, int /*stream_idx*/)
{
m_file_format = format;
}
void HwSavingCtrlObj::setOverwritePolicy(const std::string &overwritePolicy, int stream_idx)
void HwSavingCtrlObj::setOverwritePolicy(const std::string &overwritePolicy, int /*stream_idx*/)
{
m_overwritePolicy = overwritePolicy;
}
/** @brief write manually a frame
*/
void HwSavingCtrlObj::writeFrame(HwFrameInfoType& info, int stream_idx)
void HwSavingCtrlObj::writeFrame(HwFrameInfoType& /*info*/, int /*stream_idx*/)
{
DEB_MEMBER_FUNCT();
THROW_HW_ERROR(NotSupported) << "No available for this Hardware";
}
void HwSavingCtrlObj::writeFrame(int,int, int stream_idx)
void HwSavingCtrlObj::writeFrame(int,int, int /*stream_idx*/)
{
DEB_MEMBER_FUNCT();