From 6bd1c6be496d625ae8874b457acbc0c2c841997d Mon Sep 17 00:00:00 2001 From: Chris Hennes Date: Fri, 25 Aug 2023 13:15:59 -0500 Subject: [PATCH] Base: Wrap PyArg_ParseTupleAndKeywords --- src/Base/CMakeLists.txt | 1 + src/Base/PersistencePyImp.cpp | 5 +++-- src/Base/PlacementPyImp.cpp | 10 ++++++---- src/Base/RotationPyImp.cpp | 9 +++++---- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/Base/CMakeLists.txt b/src/Base/CMakeLists.txt index 122b6e7fc9..d73271bed1 100644 --- a/src/Base/CMakeLists.txt +++ b/src/Base/CMakeLists.txt @@ -320,6 +320,7 @@ SET(FreeCADBase_HPP_SRCS ProgressIndicatorPy.h PyExport.h PyObjectBase.h + PyWrapParseTupleAndKeywords.h PythonTypeExt.h QtTools.h Reader.h diff --git a/src/Base/PersistencePyImp.cpp b/src/Base/PersistencePyImp.cpp index 72cdaf9959..25972775e5 100644 --- a/src/Base/PersistencePyImp.cpp +++ b/src/Base/PersistencePyImp.cpp @@ -27,6 +27,7 @@ #include "Persistence.h" #include "Writer.h" +#include // inclusion of the generated files (generated By PersitancePy.xml) #include "PersistencePy.h" @@ -59,9 +60,9 @@ Py::Int PersistencePy::getMemSize() const PyObject* PersistencePy::dumpContent(PyObject *args, PyObject *kwds) { int compression = 3; - static char* kwds_def[] = {"Compression",nullptr}; + static const std::array kwds_def {"Compression", nullptr}; PyErr_Clear(); - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|i", kwds_def, &compression)) { + if (!Wrapped_ParseTupleAndKeywords(args, kwds, "|i", kwds_def, &compression)) { return nullptr; } diff --git a/src/Base/PlacementPyImp.cpp b/src/Base/PlacementPyImp.cpp index 9bbb3163a6..5daeacee5c 100644 --- a/src/Base/PlacementPyImp.cpp +++ b/src/Base/PlacementPyImp.cpp @@ -24,6 +24,7 @@ #include "PreCompiled.h" #include "GeometryPyCXX.h" +#include // inclusion of the generated files (generated out of PlacementPy.xml) #include "PlacementPy.h" @@ -172,14 +173,15 @@ PyObject* PlacementPy::translate(PyObject * args) PyObject* PlacementPy::rotate(PyObject *args, PyObject *kwds) { double angle{}; - char *keywords[] = { "center", "axis", "angle", "comp", nullptr }; + static const std::array kwlist { "center", "axis", "angle", "comp", nullptr }; Vector3d center; Vector3d axis; - PyObject* pyComp = Py_False; + PyObject* pyComp = Py_False; // NOLINT - if (!PyArg_ParseTupleAndKeywords(args, kwds, "(ddd)(ddd)d|O!", keywords, ¢er.x, ¢er.y, ¢er.z, - &axis.x, &axis.y, &axis.z, &angle, &PyBool_Type, &pyComp)) + if (!Base::Wrapped_ParseTupleAndKeywords(args, kwds, "(ddd)(ddd)d|O!", kwlist, ¢er.x, ¢er.y, ¢er.z, + &axis.x, &axis.y, &axis.z, &angle, &PyBool_Type, &pyComp)) { return nullptr; + } try { /* diff --git a/src/Base/RotationPyImp.cpp b/src/Base/RotationPyImp.cpp index 00396e8f14..1af310e4c9 100644 --- a/src/Base/RotationPyImp.cpp +++ b/src/Base/RotationPyImp.cpp @@ -25,6 +25,7 @@ #include #include +#include // inclusion of the generated files (generated out of RotationPy.xml) #include "RotationPy.h" @@ -76,16 +77,16 @@ int RotationPy::PyInit(PyObject* args, PyObject* kwds) PyErr_Clear(); double angle{}; - static char *kw_deg[] = {"Axis", "Degree", nullptr}; - if (PyArg_ParseTupleAndKeywords(args, kwds, "O!d", kw_deg, &(Base::VectorPy::Type), &o, &angle)) { + static const std::array kw_deg {"Axis", "Degree", nullptr}; + if (Base::Wrapped_ParseTupleAndKeywords(args, kwds, "O!d", kw_deg, &(Base::VectorPy::Type), &o, &angle)) { // NOTE: The last parameter defines the rotation angle in degree. getRotationPtr()->setValue(static_cast(o)->value(), Base::toRadians(angle)); return 0; } PyErr_Clear(); - static char *kw_rad[] = {"Axis", "Radian", nullptr}; - if (PyArg_ParseTupleAndKeywords(args, kwds, "O!d", kw_rad, &(Base::VectorPy::Type), &o, &angle)) { + static const std::array kw_rad {"Axis", "Radian", nullptr}; + if (Base::Wrapped_ParseTupleAndKeywords(args, kwds, "O!d", kw_rad, &(Base::VectorPy::Type), &o, &angle)) { getRotationPtr()->setValue(static_cast(o)->value(), angle); return 0; }