From 86c99c242176736de836517384b3ba15febbf899 Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Sat, 10 Oct 2026 17:24:04 +0200 Subject: [PATCH] refactor(sonar): drop const_cast on string literals passed to the Python C API (cpp:S859) --- scripting/PyInt.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/scripting/PyInt.cpp b/scripting/PyInt.cpp index 7f86532b..f84d64bf 100644 --- a/scripting/PyInt.cpp +++ b/scripting/PyInt.cpp @@ -107,13 +107,13 @@ void render_task::run() m_input = nullptr; // call the renderer - auto *output{PyObject_CallMethod(m_renderer, const_cast("render"), const_cast("O"), input)}; + auto *output{PyObject_CallMethod(m_renderer, "render", "O", input)}; Py_DECREF(input); if (output != nullptr) { - auto *outputWidth = PyObject_CallMethod(m_renderer, const_cast("get_width"), nullptr); - auto *outputHeight = PyObject_CallMethod(m_renderer, const_cast("get_height"), nullptr); + auto *outputWidth = PyObject_CallMethod(m_renderer, "get_width", nullptr); + auto *outputHeight = PyObject_CallMethod(m_renderer, "get_height", nullptr); if (outputWidth != nullptr && outputHeight != nullptr && m_target != nullptr) { @@ -166,7 +166,7 @@ void render_task::run() } // get commands from renderer - auto *commandsPO = PyObject_CallMethod(m_renderer, const_cast("getCommands"), nullptr); + auto *commandsPO = PyObject_CallMethod(m_renderer, "getCommands", nullptr); if (commandsPO != nullptr) { std::vector commands = python_external_utils::PyObjectToStringArray(commandsPO); @@ -310,7 +310,7 @@ auto python_taskqueue::init() -> bool stringiomodule = PyImport_ImportModule("io"); stringioclassname = stringiomodule != nullptr ? PyObject_GetAttrString(stringiomodule, "StringIO") : nullptr; stringioobject = stringioclassname != nullptr ? PyObject_CallObject(stringioclassname, nullptr) : nullptr; - m_stderr = {(stringioobject == nullptr ? nullptr : PySys_SetObject(const_cast("stderr"), stringioobject) != 0 ? nullptr : stringioobject)}; + m_stderr = {(stringioobject == nullptr ? nullptr : PySys_SetObject("stderr", stringioobject) != 0 ? nullptr : stringioobject)}; if (false == run_file("abstractscreenrenderer")) { @@ -509,7 +509,7 @@ auto python_taskqueue::fetch_renderer(std::string const &Renderer) -> PyObject * } renderer = PyObject_CallObject(renderername, rendererarguments); - PyObject_CallMethod(renderer, const_cast("manul_set_format"), const_cast("(s)"), "RGBA"); + PyObject_CallMethod(renderer, "manul_set_format", "(s)", "RGBA"); if (PyErr_Occurred() != nullptr) { @@ -621,14 +621,14 @@ void python_taskqueue::error() { // std err pythona jest buforowane PyErr_Print(); - if (auto *errortext{PyObject_CallMethod(m_stderr, const_cast("getvalue"), nullptr)}; errortext != nullptr) + if (auto *errortext{PyObject_CallMethod(m_stderr, "getvalue", nullptr)}; errortext != nullptr) { if (const char *errstr = PyUnicode_AsUTF8(errortext); errstr != nullptr) ErrorLog(errstr); Py_DECREF(errortext); } - PyObject_CallMethod(m_stderr, const_cast("truncate"), const_cast("L"), (long long)0); - PyObject_CallMethod(m_stderr, const_cast("seek"), const_cast("L"), (long long)0); + PyObject_CallMethod(m_stderr, "truncate", "L", (long long)0); + PyObject_CallMethod(m_stderr, "seek", "L", (long long)0); } else {