From c4e2eebf39b43aa7521e22dffb5dadb8a602de8d Mon Sep 17 00:00:00 2001 From: "Joachim Wuttke (l)" <j.wuttke@fz-juelich.de> Date: Wed, 16 Sep 2020 12:15:49 +0200 Subject: [PATCH] Core: fct that computes something should not be named "get..." --- Core/Detector/IDetector2D.h | 2 +- Core/Detector/IsGISAXSDetector.cpp | 2 +- Core/Detector/IsGISAXSDetector.h | 2 +- Core/Detector/RectangularDetector.cpp | 2 +- Core/Detector/RectangularDetector.h | 2 +- Core/Detector/SphericalDetector.cpp | 2 +- Core/Detector/SphericalDetector.h | 2 +- Core/Simulation/Simulation2D.cpp | 2 +- auto/Wrap/libBornAgainCore.py | 8 +- auto/Wrap/libBornAgainCore_wrap.cpp | 18 ++-- auto/Wrap/libBornAgainFit.py | 2 +- auto/Wrap/libBornAgainFit_wrap.cpp | 126 ++++++++++++++++++-------- auto/Wrap/libBornAgainFit_wrap.h | 2 +- 13 files changed, 110 insertions(+), 62 deletions(-) diff --git a/Core/Detector/IDetector2D.h b/Core/Detector/IDetector2D.h index fb975a923ef..02a5bc529d8 100644 --- a/Core/Detector/IDetector2D.h +++ b/Core/Detector/IDetector2D.h @@ -76,7 +76,7 @@ public: //! Returns index of pixel that contains the specular wavevector. //! If no pixel contains this specular wavevector, the number of pixels is //! returned. This corresponds to an overflow index. - virtual size_t getIndexOfSpecular(const Beam& beam) const = 0; + virtual size_t indexOfSpecular(const Beam& beam) const = 0; #ifndef SWIG std::unique_ptr<DetectorContext> createContext() const; diff --git a/Core/Detector/IsGISAXSDetector.cpp b/Core/Detector/IsGISAXSDetector.cpp index 635e86e6b6f..b0c7641b99c 100644 --- a/Core/Detector/IsGISAXSDetector.cpp +++ b/Core/Detector/IsGISAXSDetector.cpp @@ -51,7 +51,7 @@ std::unique_ptr<IAxis> IsGISAXSDetector::createAxis(size_t index, size_t n_bins, return std::make_unique<CustomBinAxis>(axisName(index), n_bins, min, max); } -size_t IsGISAXSDetector::getIndexOfSpecular(const Beam& /*beam*/) const +size_t IsGISAXSDetector::indexOfSpecular(const Beam& /*beam*/) const { return totalSize(); } diff --git a/Core/Detector/IsGISAXSDetector.h b/Core/Detector/IsGISAXSDetector.h index 995aaa3c8a5..9dbe5d724d8 100644 --- a/Core/Detector/IsGISAXSDetector.h +++ b/Core/Detector/IsGISAXSDetector.h @@ -40,7 +40,7 @@ protected: //! Returns index of pixel that contains the specular wavevector. //! If no pixel contains this specular wavevector, the number of pixels is //! returned. This corresponds to an overflow index. - size_t getIndexOfSpecular(const Beam& beam) const override; + size_t indexOfSpecular(const Beam& beam) const override; }; #endif // BORNAGAIN_CORE_DETECTOR_ISGISAXSDETECTOR_H diff --git a/Core/Detector/RectangularDetector.cpp b/Core/Detector/RectangularDetector.cpp index e26d4e8292e..de0bc0e11ea 100644 --- a/Core/Detector/RectangularDetector.cpp +++ b/Core/Detector/RectangularDetector.cpp @@ -209,7 +209,7 @@ std::string RectangularDetector::axisName(size_t index) const } } -size_t RectangularDetector::getIndexOfSpecular(const Beam& beam) const +size_t RectangularDetector::indexOfSpecular(const Beam& beam) const { if (dimension() != 2) return totalSize(); diff --git a/Core/Detector/RectangularDetector.h b/Core/Detector/RectangularDetector.h index 63982126b28..f0908bba7de 100644 --- a/Core/Detector/RectangularDetector.h +++ b/Core/Detector/RectangularDetector.h @@ -88,7 +88,7 @@ protected: //! Returns index of pixel that contains the specular wavevector. //! If no pixel contains this specular wavevector, the number of pixels is //! returned. This corresponds to an overflow index. - size_t getIndexOfSpecular(const Beam& beam) const override; + size_t indexOfSpecular(const Beam& beam) const override; //! swap function void swapContent(RectangularDetector& other); diff --git a/Core/Detector/SphericalDetector.cpp b/Core/Detector/SphericalDetector.cpp index 20dcff097a8..feeae3ddb3e 100644 --- a/Core/Detector/SphericalDetector.cpp +++ b/Core/Detector/SphericalDetector.cpp @@ -73,7 +73,7 @@ std::string SphericalDetector::axisName(size_t index) const } } -size_t SphericalDetector::getIndexOfSpecular(const Beam& beam) const +size_t SphericalDetector::indexOfSpecular(const Beam& beam) const { if (dimension() != 2) return totalSize(); diff --git a/Core/Detector/SphericalDetector.h b/Core/Detector/SphericalDetector.h index 039ccb0866f..5266a69a66f 100644 --- a/Core/Detector/SphericalDetector.h +++ b/Core/Detector/SphericalDetector.h @@ -59,7 +59,7 @@ protected: //! Returns index of pixel that contains the specular wavevector. //! If no pixel contains this specular wavevector, the number of pixels is //! returned. This corresponds to an overflow index. - size_t getIndexOfSpecular(const Beam& beam) const override; + size_t indexOfSpecular(const Beam& beam) const override; }; #endif // BORNAGAIN_CORE_DETECTOR_SPHERICALDETECTOR_H diff --git a/Core/Simulation/Simulation2D.cpp b/Core/Simulation/Simulation2D.cpp index 4441df9ea0c..04486e38a59 100644 --- a/Core/Simulation/Simulation2D.cpp +++ b/Core/Simulation/Simulation2D.cpp @@ -100,7 +100,7 @@ std::vector<SimulationElement> Simulation2D::generateSimulationElements(const Be const IDetector2D& detector = m_instrument.detector2D(); const Eigen::Matrix2cd analyzer_operator = detector.detectionProperties().analyzerOperator(); - const size_t spec_index = detector.getIndexOfSpecular(beam); + const size_t spec_index = detector.indexOfSpecular(beam); const size_t N = m_detector_context->numberOfSimulationElements(); diff --git a/auto/Wrap/libBornAgainCore.py b/auto/Wrap/libBornAgainCore.py index 232d34aa7b3..111aa9b7c76 100644 --- a/auto/Wrap/libBornAgainCore.py +++ b/auto/Wrap/libBornAgainCore.py @@ -18927,15 +18927,15 @@ class IDetector2D(IDetector): """ return _libBornAgainCore.IDetector2D_createPixel(self, index) - def getIndexOfSpecular(self, beam): + def indexOfSpecular(self, beam): r""" - getIndexOfSpecular(IDetector2D self, Beam beam) -> size_t - virtual size_t IDetector2D::getIndexOfSpecular(const Beam &beam) const =0 + indexOfSpecular(IDetector2D self, Beam beam) -> size_t + virtual size_t IDetector2D::indexOfSpecular(const Beam &beam) const =0 Returns index of pixel that contains the specular wavevector. If no pixel contains this specular wavevector, the number of pixels is returned. This corresponds to an overflow index. """ - return _libBornAgainCore.IDetector2D_getIndexOfSpecular(self, beam) + return _libBornAgainCore.IDetector2D_indexOfSpecular(self, beam) # Register IDetector2D in _libBornAgainCore: _libBornAgainCore.IDetector2D_swigregister(IDetector2D) diff --git a/auto/Wrap/libBornAgainCore_wrap.cpp b/auto/Wrap/libBornAgainCore_wrap.cpp index 435472f2352..da416eb43f7 100644 --- a/auto/Wrap/libBornAgainCore_wrap.cpp +++ b/auto/Wrap/libBornAgainCore_wrap.cpp @@ -106635,7 +106635,7 @@ fail: } -SWIGINTERN PyObject *_wrap_IDetector2D_getIndexOfSpecular(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { +SWIGINTERN PyObject *_wrap_IDetector2D_indexOfSpecular(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *resultobj = 0; IDetector2D *arg1 = (IDetector2D *) 0 ; Beam *arg2 = 0 ; @@ -106646,21 +106646,21 @@ SWIGINTERN PyObject *_wrap_IDetector2D_getIndexOfSpecular(PyObject *SWIGUNUSEDPA PyObject *swig_obj[2] ; size_t result; - if (!SWIG_Python_UnpackTuple(args, "IDetector2D_getIndexOfSpecular", 2, 2, swig_obj)) SWIG_fail; + if (!SWIG_Python_UnpackTuple(args, "IDetector2D_indexOfSpecular", 2, 2, swig_obj)) SWIG_fail; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_IDetector2D, 0 | 0 ); if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "IDetector2D_getIndexOfSpecular" "', argument " "1"" of type '" "IDetector2D const *""'"); + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "IDetector2D_indexOfSpecular" "', argument " "1"" of type '" "IDetector2D const *""'"); } arg1 = reinterpret_cast< IDetector2D * >(argp1); res2 = SWIG_ConvertPtr(swig_obj[1], &argp2, SWIGTYPE_p_Beam, 0 | 0); if (!SWIG_IsOK(res2)) { - SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "IDetector2D_getIndexOfSpecular" "', argument " "2"" of type '" "Beam const &""'"); + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "IDetector2D_indexOfSpecular" "', argument " "2"" of type '" "Beam const &""'"); } if (!argp2) { - SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "IDetector2D_getIndexOfSpecular" "', argument " "2"" of type '" "Beam const &""'"); + SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "IDetector2D_indexOfSpecular" "', argument " "2"" of type '" "Beam const &""'"); } arg2 = reinterpret_cast< Beam * >(argp2); - result = ((IDetector2D const *)arg1)->getIndexOfSpecular((Beam const &)*arg2); + result = ((IDetector2D const *)arg1)->indexOfSpecular((Beam const &)*arg2); resultobj = SWIG_From_size_t(static_cast< size_t >(result)); return resultobj; fail: @@ -132473,9 +132473,9 @@ static PyMethodDef SwigMethods[] = { "Create an IPixel for the given OutputData object and index. \n" "\n" ""}, - { "IDetector2D_getIndexOfSpecular", _wrap_IDetector2D_getIndexOfSpecular, METH_VARARGS, "\n" - "IDetector2D_getIndexOfSpecular(IDetector2D self, Beam beam) -> size_t\n" - "virtual size_t IDetector2D::getIndexOfSpecular(const Beam &beam) const =0\n" + { "IDetector2D_indexOfSpecular", _wrap_IDetector2D_indexOfSpecular, METH_VARARGS, "\n" + "IDetector2D_indexOfSpecular(IDetector2D self, Beam beam) -> size_t\n" + "virtual size_t IDetector2D::indexOfSpecular(const Beam &beam) const =0\n" "\n" "Returns index of pixel that contains the specular wavevector. If no pixel contains this specular wavevector, the number of pixels is returned. This corresponds to an overflow index. \n" "\n" diff --git a/auto/Wrap/libBornAgainFit.py b/auto/Wrap/libBornAgainFit.py index 33f3addf37f..1805a1a1428 100644 --- a/auto/Wrap/libBornAgainFit.py +++ b/auto/Wrap/libBornAgainFit.py @@ -1,5 +1,5 @@ # This file was automatically generated by SWIG (http://www.swig.org). -# Version 4.0.1 +# Version 4.0.2 # # Do not make changes to this file unless you know what you are doing--modify # the SWIG interface file instead. diff --git a/auto/Wrap/libBornAgainFit_wrap.cpp b/auto/Wrap/libBornAgainFit_wrap.cpp index 0c5a892161c..fb6eae00179 100644 --- a/auto/Wrap/libBornAgainFit_wrap.cpp +++ b/auto/Wrap/libBornAgainFit_wrap.cpp @@ -1,6 +1,6 @@ /* ---------------------------------------------------------------------------- * This file was automatically generated by SWIG (http://www.swig.org). - * Version 4.0.1 + * Version 4.0.2 * * This file is not intended to be easily readable and contains a number of * coding conventions designed to improve portability and efficiency. Do not make @@ -809,15 +809,19 @@ SWIG_UnpackDataName(const char *c, void *ptr, size_t sz, const char *name) { SWIGINTERN char* SWIG_Python_str_AsChar(PyObject *str) { -#if PY_VERSION_HEX >= 0x03000000 +#if PY_VERSION_HEX >= 0x03030000 + return (char *)PyUnicode_AsUTF8(str); +#elif PY_VERSION_HEX >= 0x03000000 char *newstr = 0; str = PyUnicode_AsUTF8String(str); if (str) { char *cstr; Py_ssize_t len; - PyBytes_AsStringAndSize(str, &cstr, &len); - newstr = (char *) malloc(len+1); - memcpy(newstr, cstr, len+1); + if (PyBytes_AsStringAndSize(str, &cstr, &len) != -1) { + newstr = (char *) malloc(len+1); + if (newstr) + memcpy(newstr, cstr, len+1); + } Py_XDECREF(str); } return newstr; @@ -826,10 +830,10 @@ SWIG_Python_str_AsChar(PyObject *str) #endif } -#if PY_VERSION_HEX >= 0x03000000 -# define SWIG_Python_str_DelForPy3(x) free( (void*) (x) ) +#if PY_VERSION_HEX >= 0x03030000 || PY_VERSION_HEX < 0x03000000 +# define SWIG_Python_str_DelForPy3(x) #else -# define SWIG_Python_str_DelForPy3(x) +# define SWIG_Python_str_DelForPy3(x) free( (void*) (x) ) #endif @@ -1244,6 +1248,19 @@ SWIG_Python_UnpackTuple(PyObject *args, const char *name, Py_ssize_t min, Py_ssi } } +SWIGINTERN int +SWIG_Python_CheckNoKeywords(PyObject *kwargs, const char *name) { + int no_kwargs = 1; + if (kwargs) { + assert(PyDict_Check(kwargs)); + if (PyDict_Size(kwargs) > 0) { + PyErr_Format(PyExc_TypeError, "%s() does not take keyword arguments", name); + no_kwargs = 0; + } + } + return no_kwargs; +} + /* A functor is a function object with one single object argument */ #define SWIG_Python_CallFunctor(functor, obj) PyObject_CallFunctionObjArgs(functor, obj, NULL); @@ -1757,6 +1774,12 @@ SwigPyObject_TypeOnce(void) { #if PY_VERSION_HEX >= 0x03040000 0, /* tp_finalize */ #endif +#if PY_VERSION_HEX >= 0x03080000 + 0, /* tp_vectorcall */ +#endif +#if (PY_VERSION_HEX >= 0x03080000) && (PY_VERSION_HEX < 0x03090000) + 0, /* tp_print */ +#endif #ifdef COUNT_ALLOCS 0, /* tp_allocs */ 0, /* tp_frees */ @@ -1918,6 +1941,12 @@ SwigPyPacked_TypeOnce(void) { #if PY_VERSION_HEX >= 0x03040000 0, /* tp_finalize */ #endif +#if PY_VERSION_HEX >= 0x03080000 + 0, /* tp_vectorcall */ +#endif +#if (PY_VERSION_HEX >= 0x03080000) && (PY_VERSION_HEX < 0x03090000) + 0, /* tp_print */ +#endif #ifdef COUNT_ALLOCS 0, /* tp_allocs */ 0, /* tp_frees */ @@ -2244,8 +2273,10 @@ SWIG_Python_NewShadowInstance(SwigPyClientData *data, PyObject *swig_this) } } #else - PyObject *key = SWIG_This(); - PyObject_SetAttr(inst, key, swig_this); + if (PyObject_SetAttr(inst, SWIG_This(), swig_this) == -1) { + Py_DECREF(inst); + inst = 0; + } #endif } } else { @@ -2257,8 +2288,12 @@ SWIG_Python_NewShadowInstance(SwigPyClientData *data, PyObject *swig_this) inst = ((PyTypeObject *)data->newargs)->tp_new((PyTypeObject *)data->newargs, empty_args, empty_kwargs); Py_DECREF(empty_kwargs); if (inst) { - PyObject_SetAttr(inst, SWIG_This(), swig_this); - Py_TYPE(inst)->tp_flags &= ~Py_TPFLAGS_VALID_VERSION_TAG; + if (PyObject_SetAttr(inst, SWIG_This(), swig_this) == -1) { + Py_DECREF(inst); + inst = 0; + } else { + Py_TYPE(inst)->tp_flags &= ~Py_TPFLAGS_VALID_VERSION_TAG; + } } } Py_DECREF(empty_args); @@ -2275,25 +2310,21 @@ SWIG_Python_NewShadowInstance(SwigPyClientData *data, PyObject *swig_this) return inst; } -SWIGRUNTIME void +SWIGRUNTIME int SWIG_Python_SetSwigThis(PyObject *inst, PyObject *swig_this) { - PyObject *dict; #if !defined(SWIG_PYTHON_SLOW_GETSET_THIS) - PyObject **dictptr = _PyObject_GetDictPtr(inst); - if (dictptr != NULL) { - dict = *dictptr; - if (dict == NULL) { - dict = PyDict_New(); - *dictptr = dict; - } - PyDict_SetItem(dict, SWIG_This(), swig_this); - return; - } + PyObject **dictptr = _PyObject_GetDictPtr(inst); + if (dictptr != NULL) { + PyObject *dict = *dictptr; + if (dict == NULL) { + dict = PyDict_New(); + *dictptr = dict; + } + return PyDict_SetItem(dict, SWIG_This(), swig_this); + } #endif - dict = PyObject_GetAttrString(inst, "__dict__"); - PyDict_SetItem(dict, SWIG_This(), swig_this); - Py_DECREF(dict); + return PyObject_SetAttr(inst, SWIG_This(), swig_this); } @@ -2307,7 +2338,8 @@ SWIG_Python_InitShadowInstance(PyObject *args) { if (sthis) { SwigPyObject_append((PyObject*) sthis, obj[1]); } else { - SWIG_Python_SetSwigThis(obj[0], obj[1]); + if (SWIG_Python_SetSwigThis(obj[0], obj[1]) != 0) + return NULL; } return SWIG_Py_Void(); } @@ -3137,7 +3169,7 @@ static swig_module_info swig_module = {swig_types, 48, 0, 0, 0, 0}; #endif #define SWIG_name "_libBornAgainFit" -#define SWIGVERSION 0x040001 +#define SWIGVERSION 0x040002 #define SWIG_VERSION SWIGVERSION @@ -3866,11 +3898,20 @@ namespace swig { template <class Type> struct traits_asptr { static int asptr(PyObject *obj, Type **val) { - Type *p = 0; + int res = SWIG_ERROR; swig_type_info *descriptor = type_info<Type>(); - int res = descriptor ? SWIG_ConvertPtr(obj, (void **)&p, descriptor, 0) : SWIG_ERROR; - if (SWIG_IsOK(res)) { - if (val) *val = p; + if (val) { + Type *p = 0; + int newmem = 0; + res = descriptor ? SWIG_ConvertPtrAndOwn(obj, (void **)&p, descriptor, 0, &newmem) : SWIG_ERROR; + if (SWIG_IsOK(res)) { + if (newmem & SWIG_CAST_NEW_MEMORY) { + res |= SWIG_NEWOBJMASK; + } + *val = p; + } + } else { + res = descriptor ? SWIG_ConvertPtr(obj, 0, descriptor, 0) : SWIG_ERROR; } return res; } @@ -5070,7 +5111,7 @@ namespace swig { struct container_owner { // By default, do not add the back-reference (for value types) // Specialization below will check the reference for pointer types. - static bool back_reference(PyObject* child, PyObject* owner) { + static bool back_reference(PyObject* /*child*/, PyObject* /*owner*/) { return false; } }; @@ -5087,8 +5128,7 @@ namespace swig { static bool back_reference(PyObject* child, PyObject* owner) { SwigPyObject* swigThis = SWIG_Python_GetSwigThis(child); if (swigThis && (swigThis->own & SWIG_POINTER_OWN) != SWIG_POINTER_OWN) { - PyObject_SetAttr(child, container_owner_attribute(), owner); - return true; + return PyObject_SetAttr(child, container_owner_attribute(), owner) != -1; } return false; } @@ -5491,7 +5531,7 @@ SWIG_AsVal_std_complex_Sl_double_Sg_ (PyObject *o, std::complex<double>* val) SWIGINTERNINLINE PyObject* -SWIG_From_std_complex_Sl_double_Sg_ (/*@SWIG:/usr/share/swig4.0/typemaps/swigmacros.swg,104,%ifcplusplus@*/ +SWIG_From_std_complex_Sl_double_Sg_ (/*@SWIG:/usr/local/share/swig/4.0.2/typemaps/swigmacros.swg,104,%ifcplusplus@*/ const std::complex<double>& @@ -5667,9 +5707,11 @@ SWIG_AsCharPtrAndSize(PyObject *obj, char** cptr, size_t* psize, int *alloc) if (alloc) *alloc = SWIG_NEWOBJ; #endif - PyBytes_AsStringAndSize(obj, &cstr, &len); + if (PyBytes_AsStringAndSize(obj, &cstr, &len) == -1) + return SWIG_TypeError; #else - PyString_AsStringAndSize(obj, &cstr, &len); + if (PyString_AsStringAndSize(obj, &cstr, &len) == -1) + return SWIG_TypeError; #endif if (cptr) { if (alloc) { @@ -23328,6 +23370,12 @@ extern "C" { #if PY_VERSION_HEX >= 0x03040000 0, /* tp_finalize */ #endif +#if PY_VERSION_HEX >= 0x03080000 + 0, /* tp_vectorcall */ +#endif +#if (PY_VERSION_HEX >= 0x03080000) && (PY_VERSION_HEX < 0x03090000) + 0, /* tp_print */ +#endif #ifdef COUNT_ALLOCS 0, /* tp_allocs */ 0, /* tp_frees */ diff --git a/auto/Wrap/libBornAgainFit_wrap.h b/auto/Wrap/libBornAgainFit_wrap.h index ec6610edd3d..d7bb0e208ce 100644 --- a/auto/Wrap/libBornAgainFit_wrap.h +++ b/auto/Wrap/libBornAgainFit_wrap.h @@ -1,6 +1,6 @@ /* ---------------------------------------------------------------------------- * This file was automatically generated by SWIG (http://www.swig.org). - * Version 4.0.1 + * Version 4.0.2 * * This file is not intended to be easily readable and contains a number of * coding conventions designed to improve portability and efficiency. Do not make -- GitLab