From c60e03741a82e56027c10fdb10f314bd266f3a7c Mon Sep 17 00:00:00 2001 From: Chris Hennes Date: Fri, 25 Aug 2023 13:19:09 -0500 Subject: [PATCH] TD: Wrap PyArg_ParseTupleAndKeywords --- src/Mod/TechDraw/App/AppTechDrawPy.cpp | 11 +++++++---- src/Mod/TechDraw/App/CenterLinePyImp.cpp | 5 +++-- src/Mod/TechDraw/App/CosmeticEdgePyImp.cpp | 8 +++++--- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/Mod/TechDraw/App/AppTechDrawPy.cpp b/src/Mod/TechDraw/App/AppTechDrawPy.cpp index 5746d84948..9fb36bb843 100644 --- a/src/Mod/TechDraw/App/AppTechDrawPy.cpp +++ b/src/Mod/TechDraw/App/AppTechDrawPy.cpp @@ -40,6 +40,7 @@ #include #include #include +#include #include #include #include @@ -1093,7 +1094,9 @@ private: Py::Object projectToSVG(const Py::Tuple& args, const Py::Dict& keys) { - static char* argNames[] = {"topoShape", "direction", "type", "tolerance", "vStyle", "v0Style", "v1Style", "hStyle", "h0Style", "h1Style", nullptr}; + static const std::array argNames{"topoShape", "direction", "type", "tolerance", "vStyle", + "v0Style", "v1Style", "hStyle", "h0Style", "h1Style", + nullptr}; PyObject *pcObjShape = nullptr; PyObject *pcObjDir = nullptr; const char *extractionTypePy = nullptr; @@ -1114,7 +1117,7 @@ private: // Get the arguments - if (!PyArg_ParseTupleAndKeywords( + if (!Base::Wrapped_ParseTupleAndKeywords( args.ptr(), keys.ptr(), "O!|O!sfOOOOOO", argNames, @@ -1122,9 +1125,9 @@ private: &(Base::VectorPy::Type), &pcObjDir, &extractionTypePy, &tol, &vStylePy, &v0StylePy, &v1StylePy, - &hStylePy, &h0StylePy, &h1StylePy)) - + &hStylePy, &h0StylePy, &h1StylePy)) { throw Py::Exception(); + } // Convert all arguments into the right format diff --git a/src/Mod/TechDraw/App/CenterLinePyImp.cpp b/src/Mod/TechDraw/App/CenterLinePyImp.cpp index e6283ec02e..d0a0a6a3a9 100644 --- a/src/Mod/TechDraw/App/CenterLinePyImp.cpp +++ b/src/Mod/TechDraw/App/CenterLinePyImp.cpp @@ -26,6 +26,7 @@ #endif #include +#include #include "CenterLinePy.h" #include "DrawUtil.h" @@ -130,8 +131,8 @@ void CenterLinePy::setFormat(Py::Dict arg) double weight = 0.5; PyObject* pColor = color.ptr(); PyObject* visible = Py_True; - static char* kw[] = {"style", "weight", "color", "visible", nullptr}; - if (!PyArg_ParseTupleAndKeywords(dummy.ptr(), arg.ptr(), "|idO!O!", kw, + static const std::array kw{"style", "weight", "color", "visible", nullptr}; + if (!Base::Wrapped_ParseTupleAndKeywords(dummy.ptr(), arg.ptr(), "|idO!O!", kw, &style, &weight, &PyTuple_Type, &pColor, &PyBool_Type, &visible)) { throw Py::ValueError("Expected {'style':int, 'weight':float, 'color':tuple, 'visible':bool} dict"); } diff --git a/src/Mod/TechDraw/App/CosmeticEdgePyImp.cpp b/src/Mod/TechDraw/App/CosmeticEdgePyImp.cpp index df24c92eb5..b7e2671854 100644 --- a/src/Mod/TechDraw/App/CosmeticEdgePyImp.cpp +++ b/src/Mod/TechDraw/App/CosmeticEdgePyImp.cpp @@ -27,6 +27,8 @@ # include #endif +#include + #include "CosmeticEdgePy.h" #include "CosmeticEdgePy.cpp" #include "Cosmetic.h" @@ -122,9 +124,9 @@ void CosmeticEdgePy::setFormat(Py::Dict arg) double weight = 0.5; PyObject* pColor = color.ptr(); PyObject* visible = Py_True; - static char* kw[] = {"style", "weight", "color", "visible", nullptr}; - if (!PyArg_ParseTupleAndKeywords(dummy.ptr(), arg.ptr(), "|idO!O!", kw, - &style, &weight, &PyTuple_Type, &pColor, &PyBool_Type, &visible)) { + static const std::array kw{"style", "weight", "color", "visible", nullptr}; + if (!Base::Wrapped_ParseTupleAndKeywords(dummy.ptr(), arg.ptr(), "|idO!O!", kw, + &style, &weight, &PyTuple_Type, &pColor, &PyBool_Type, &visible)) { throw Py::ValueError("Expected {'style':int, 'weight':float, 'color':tuple, 'visible':bool} dict"); }