diff --git a/Framework/PythonInterface/mantid/api/src/Exports/AlgorithmManager.cpp b/Framework/PythonInterface/mantid/api/src/Exports/AlgorithmManager.cpp index ca5c4f916097..ad6c7bea3007 100644 --- a/Framework/PythonInterface/mantid/api/src/Exports/AlgorithmManager.cpp +++ b/Framework/PythonInterface/mantid/api/src/Exports/AlgorithmManager.cpp @@ -124,8 +124,10 @@ GNU_DIAG_OFF("unused-local-typedef") // Seen with GCC 7.1.1 and Boost 1.63.0 GNU_DIAG_OFF("conversion") /// Define overload generators +// cppcheck-suppress unknownMacro BOOST_PYTHON_FUNCTION_OVERLOADS(create_overloads, create, 2, 3) BOOST_PYTHON_FUNCTION_OVERLOADS(createUnmanaged_overloads, createUnmanaged, 2, 3) + GNU_DIAG_ON("conversion") GNU_DIAG_ON("unused-local-typedef") ///@endcond diff --git a/Framework/PythonInterface/mantid/api/src/Exports/AlgorithmProperty.cpp b/Framework/PythonInterface/mantid/api/src/Exports/AlgorithmProperty.cpp index b386d8151b84..5eba265958d7 100644 --- a/Framework/PythonInterface/mantid/api/src/Exports/AlgorithmProperty.cpp +++ b/Framework/PythonInterface/mantid/api/src/Exports/AlgorithmProperty.cpp @@ -27,7 +27,7 @@ namespace { * @param direction An output/input/inout property * @return A pointer to a new AlgorithmProperty object */ -AlgorithmProperty *createPropertyWithValidatorAndDirection(const std::string &name, IValidator *validator, +AlgorithmProperty *createPropertyWithValidatorAndDirection(const std::string &name, const IValidator *validator, unsigned int direction) { return new AlgorithmProperty(name, validator->clone(), direction); } @@ -39,9 +39,10 @@ AlgorithmProperty *createPropertyWithValidatorAndDirection(const std::string &na * when passed to the framework * @return A pointer to a new AlgorithmProperty object */ -AlgorithmProperty *createPropertyWithValidator(const std::string &name, IValidator *validator) { +static const AlgorithmProperty *(*const createPropertyWithValidator)(const std::string &, const IValidator *) = + +[](const std::string &name, const IValidator *validator) -> const AlgorithmProperty * { return createPropertyWithValidatorAndDirection(name, validator, Mantid::Kernel::Direction::Input); -} +}; } // namespace void export_AlgorithmProperty() { @@ -54,7 +55,7 @@ void export_AlgorithmProperty() { .def(init(args("name"))) // These variants require the validator object to be cloned .def("__init__", - make_constructor(&createPropertyWithValidator, default_call_policies(), args("name", "validator"))) + make_constructor(createPropertyWithValidator, default_call_policies(), args("name", "validator"))) .def("__init__", make_constructor(&createPropertyWithValidatorAndDirection, default_call_policies(), args("name", "validator", "direction"))); } diff --git a/Framework/PythonInterface/mantid/api/src/Exports/Axis.cpp b/Framework/PythonInterface/mantid/api/src/Exports/Axis.cpp index c14f3028de25..b79d55155993 100644 --- a/Framework/PythonInterface/mantid/api/src/Exports/Axis.cpp +++ b/Framework/PythonInterface/mantid/api/src/Exports/Axis.cpp @@ -41,6 +41,7 @@ GNU_DIAG_OFF("unused-local-typedef") GNU_DIAG_OFF("conversion") // Overloads for operator() function which has 1 optional argument +// cppcheck-suppress unknownMacro BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(Axis_getValue, Axis::getValue, 1, 2) GNU_DIAG_ON("conversion") diff --git a/Framework/PythonInterface/mantid/api/src/Exports/ExperimentInfo.cpp b/Framework/PythonInterface/mantid/api/src/Exports/ExperimentInfo.cpp index ea5b7fc79e78..0a7750bdf82e 100644 --- a/Framework/PythonInterface/mantid/api/src/Exports/ExperimentInfo.cpp +++ b/Framework/PythonInterface/mantid/api/src/Exports/ExperimentInfo.cpp @@ -54,6 +54,7 @@ GNU_DIAG_OFF("unused-local-typedef") // Seen with GCC 7.1.1 and Boost 1.63.0 GNU_DIAG_OFF("conversion") /// Overload generator for getInstrumentFilename +// cppcheck-suppress unknownMacro BOOST_PYTHON_FUNCTION_OVERLOADS(getInstrumentFilename_Overload, getInstrumentFilenameWarn, 1, 2) GNU_DIAG_ON("conversion") GNU_DIAG_ON("unused-local-typedef") diff --git a/Framework/PythonInterface/mantid/api/src/Exports/IAlgorithm.cpp b/Framework/PythonInterface/mantid/api/src/Exports/IAlgorithm.cpp index d4d52209d692..de382e450ec9 100644 --- a/Framework/PythonInterface/mantid/api/src/Exports/IAlgorithm.cpp +++ b/Framework/PythonInterface/mantid/api/src/Exports/IAlgorithm.cpp @@ -221,7 +221,7 @@ std::string createDocString(const IAlgorithm &self) { buffer << "Property descriptions: " << EOL << EOL; // write the actual property descriptions for (size_t i = 0; i < numProps; ++i) { - Mantid::Kernel::Property *prop = properties[i]; + const Mantid::Kernel::Property *prop = properties[i]; buffer << prop->name() << "(" << Mantid::Kernel::Direction::asText(prop->direction()); if (!prop->isValid().empty()) buffer << ":req"; @@ -251,7 +251,7 @@ std::string createDocString(const IAlgorithm &self) { struct AllowCThreads { explicit AllowCThreads(const object &algm) : m_tracefunc(nullptr), m_tracearg(nullptr), m_saved(nullptr), m_tracking(false) { - PyThreadState *curThreadState = PyThreadState_GET(); + const PyThreadState *curThreadState = PyThreadState_GET(); m_tracefunc = curThreadState->c_tracefunc; m_tracearg = curThreadState->c_traceobj; Py_XINCREF(m_tracearg); @@ -315,8 +315,7 @@ PyObject *getAlgorithmID(const IAlgorithm &self) { AlgorithmID id = self.getAlgorithmID(); if (id) return to_python_value()(AlgorithmIDProxy(id)); - else - Py_RETURN_NONE; + return Py_NewRef(Py_None); } //-------------------------------------------------------------------------------------- diff --git a/Framework/PythonInterface/mantid/api/src/Exports/IEventList.cpp b/Framework/PythonInterface/mantid/api/src/Exports/IEventList.cpp index c572110c4252..31e4aa2ba1cd 100644 --- a/Framework/PythonInterface/mantid/api/src/Exports/IEventList.cpp +++ b/Framework/PythonInterface/mantid/api/src/Exports/IEventList.cpp @@ -72,12 +72,12 @@ void export_IEventList() { "Mask out events that have a tof between tofMin and tofMax " "(inclusively)") .def("maskCondition", &maskCondition, args("self", "mask"), "Mask out events by the condition vector") - .def("getTofs", (std::vector(IEventList::*)(void) const) & IEventList::getTofs, args("self"), + .def("getTofs", (std::vector(IEventList::*)() const) & IEventList::getTofs, args("self"), return_clone_numpy(), "Get a vector of the TOFs of the events") - .def("getWeights", (std::vector(IEventList::*)(void) const) & IEventList::getWeights, args("self"), + .def("getWeights", (std::vector(IEventList::*)() const) & IEventList::getWeights, args("self"), + return_clone_numpy(), "Get a vector of the weights of the events") + .def("getWeightErrors", (std::vector(IEventList::*)() const) & IEventList::getWeightErrors, args("self"), return_clone_numpy(), "Get a vector of the weights of the events") - .def("getWeightErrors", (std::vector(IEventList::*)(void) const) & IEventList::getWeightErrors, - args("self"), return_clone_numpy(), "Get a vector of the weights of the events") .def("getPulseTimes", &IEventList::getPulseTimes, args("self"), "Get a vector of the pulse times of the events") .def("getPulseTimesAsNumpy", make_function(&IEventList::getPulseTimes, return_value_policy()), diff --git a/Framework/PythonInterface/mantid/api/src/Exports/IFunction.cpp b/Framework/PythonInterface/mantid/api/src/Exports/IFunction.cpp index 6dfe52c6be17..a1ac0cae973d 100644 --- a/Framework/PythonInterface/mantid/api/src/Exports/IFunction.cpp +++ b/Framework/PythonInterface/mantid/api/src/Exports/IFunction.cpp @@ -147,6 +147,7 @@ BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(declareAttributeType1_Overloads, declareA using declareAttributeType2 = void (IFunctionAdapter::*)(const std::string &name, const boost::python::object &defaultValue, const boost::python::object &validator); +// cppcheck-suppress unknownMacro BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(declareAttributeType2_Overloads, declareAttribute, 3, 3) BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(tie_Overloads, tie, 2, 3) diff --git a/Framework/PythonInterface/mantid/api/src/Exports/IFunction1D.cpp b/Framework/PythonInterface/mantid/api/src/Exports/IFunction1D.cpp index 244612b417a2..75fb3fc0926c 100644 --- a/Framework/PythonInterface/mantid/api/src/Exports/IFunction1D.cpp +++ b/Framework/PythonInterface/mantid/api/src/Exports/IFunction1D.cpp @@ -20,6 +20,8 @@ void export_IFunction1D() { */ class_, std::shared_ptr, boost::noncopyable>( "IFunction1D", "Base class for 1D Fit functions") + // suppress c-style cast of Function1D object - think this is desired behaviour + // cppcheck-suppress cstyleCast .def("function1D", (object(IFunction1DAdapter::*)(const object &) const)&IFunction1DAdapter::function1D, (arg("self"), arg("xvals")), "Calculate the values of the function for the given x values and " diff --git a/Framework/PythonInterface/mantid/api/src/Exports/IMaskWorkspace.cpp b/Framework/PythonInterface/mantid/api/src/Exports/IMaskWorkspace.cpp index 2381f526603c..f631decdc603 100644 --- a/Framework/PythonInterface/mantid/api/src/Exports/IMaskWorkspace.cpp +++ b/Framework/PythonInterface/mantid/api/src/Exports/IMaskWorkspace.cpp @@ -41,6 +41,7 @@ void export_IMaskWorkspace() { .def("isMasked", isMaskedFromList, (arg("self"), arg("detector_id_list")), "Returns whether all of the given detector ID list are masked"); - // register pointers + // register pointers - required to map between C++ type T and python type + // cppcheck-suppress unusedScopedObject RegisterWorkspacePtrToPython(); } diff --git a/Framework/PythonInterface/mantid/api/src/Exports/IPeakFunction.cpp b/Framework/PythonInterface/mantid/api/src/Exports/IPeakFunction.cpp index 81dc15df0da8..164f0bdff9c4 100644 --- a/Framework/PythonInterface/mantid/api/src/Exports/IPeakFunction.cpp +++ b/Framework/PythonInterface/mantid/api/src/Exports/IPeakFunction.cpp @@ -17,9 +17,10 @@ using namespace boost::python; void export_IPeakFunction() { register_ptr_to_python>(); - class_, std::shared_ptr, boost::noncopyable>( "IPeakFunction", "Base class for peak Fit functions") + // suppress c-style cast of IPeakFunction object - think this is desired behaviour + // cppcheck-suppress cstyleCast .def("functionLocal", (object(IPeakFunctionAdapter::*)(const object &) const)&IPeakFunctionAdapter::functionLocal, (arg("self"), arg("vec_x")), "Calculate the values of the function for the given x values. The " diff --git a/buildconfig/CMake/CppCheck_Suppressions.txt.in b/buildconfig/CMake/CppCheck_Suppressions.txt.in index 611db6b788de..14c0215edbfa 100644 --- a/buildconfig/CMake/CppCheck_Suppressions.txt.in +++ b/buildconfig/CMake/CppCheck_Suppressions.txt.in @@ -837,20 +837,11 @@ constVariablePointer:${CMAKE_SOURCE_DIR}/Framework/PythonInterface/mantid/api/sr unknownMacro:${CMAKE_SOURCE_DIR}/Framework/PythonInterface/mantid/api/src/Exports/Algorithm.cpp:76 unknownMacro:${CMAKE_SOURCE_DIR}/Framework/PythonInterface/mantid/api/src/Exports/AlgorithmFactory.cpp:155 unknownMacro:${CMAKE_SOURCE_DIR}/Framework/PythonInterface/mantid/api/src/Exports/AlgorithmManager.cpp:127 -constParameterCallback:${CMAKE_SOURCE_DIR}/Framework/PythonInterface/mantid/api/src/Exports/AlgorithmProperty.cpp:30 unknownMacro:${CMAKE_SOURCE_DIR}/Framework/PythonInterface/mantid/api/src/Exports/Axis.cpp:44 unknownMacro:${CMAKE_SOURCE_DIR}/Framework/PythonInterface/mantid/api/src/Exports/ExperimentInfo.cpp:57 -constVariablePointer:${CMAKE_SOURCE_DIR}/Framework/PythonInterface/mantid/api/src/Exports/IAlgorithm.cpp:224 -constVariablePointer:${CMAKE_SOURCE_DIR}/Framework/PythonInterface/mantid/api/src/Exports/IAlgorithm.cpp:254 -missingReturn:${CMAKE_SOURCE_DIR}/Framework/PythonInterface/mantid/api/src/Exports/IAlgorithm.cpp:319 -cstyleCast:${CMAKE_SOURCE_DIR}/Framework/PythonInterface/mantid/api/src/Exports/IEventList.cpp:75 -cstyleCast:${CMAKE_SOURCE_DIR}/Framework/PythonInterface/mantid/api/src/Exports/IEventList.cpp:77 -cstyleCast:${CMAKE_SOURCE_DIR}/Framework/PythonInterface/mantid/api/src/Exports/IEventList.cpp:79 unknownMacro:${CMAKE_SOURCE_DIR}/Framework/PythonInterface/mantid/api/src/Exports/IFunction.cpp:150 -cstyleCast:${CMAKE_SOURCE_DIR}/Framework/PythonInterface/mantid/api/src/Exports/IFunction1D.cpp:23 cstyleCast:${CMAKE_SOURCE_DIR}/Framework/PythonInterface/mantid/api/src/Exports/IMDHistoWorkspace.cpp:50 unusedScopedObject:${CMAKE_SOURCE_DIR}/Framework/PythonInterface/mantid/api/src/Exports/IMaskWorkspace.cpp:45 -cstyleCast:${CMAKE_SOURCE_DIR}/Framework/PythonInterface/mantid/api/src/Exports/IPeakFunction.cpp:23 unusedScopedObject:${CMAKE_SOURCE_DIR}/Framework/PythonInterface/mantid/api/src/Exports/ISplittersWorkspace.cpp:25 unknownMacro:${CMAKE_SOURCE_DIR}/Framework/PythonInterface/mantid/api/src/Exports/ITableWorkspace.cpp:251 unknownMacro:${CMAKE_SOURCE_DIR}/Framework/PythonInterface/mantid/api/src/Exports/InstrumentFileFinder.cpp:36