From cab9496a7023d8c536aee30bb539de4abdfafef8 Mon Sep 17 00:00:00 2001 From: Trygve Aaberge Date: Sun, 29 Dec 2024 17:08:30 +0100 Subject: [PATCH] python: define constants using PyModule_Add...Constant MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This follows the recommendation from Pythons documentation for PyModule_GetDict where it says: It is recommended extensions use other PyModule_* and PyObject_* functions rather than directly manipulate a module’s __dict__. --- src/plugins/python/weechat-python.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/plugins/python/weechat-python.c b/src/plugins/python/weechat-python.c index 903e5e559..558a047c6 100644 --- a/src/plugins/python/weechat-python.c +++ b/src/plugins/python/weechat-python.c @@ -604,7 +604,7 @@ end: static PyObject *weechat_python_init_module_weechat () { - PyObject *weechat_module, *weechat_dict; + PyObject *weechat_module; int i; weechat_module = PyModule_Create (&moduleDef); @@ -619,22 +619,21 @@ static PyObject *weechat_python_init_module_weechat () } /* define some constants */ - weechat_dict = PyModule_GetDict (weechat_module); for (i = 0; weechat_script_constants[i].name; i++) { if (weechat_script_constants[i].value_string) { - PyDict_SetItemString ( - weechat_dict, + PyModule_AddStringConstant ( + weechat_module, weechat_script_constants[i].name, - PyUnicode_FromString (weechat_script_constants[i].value_string)); + weechat_script_constants[i].value_string); } else { - PyDict_SetItemString ( - weechat_dict, + PyModule_AddIntConstant ( + weechat_module, weechat_script_constants[i].name, - PyLong_FromLong ((long)weechat_script_constants[i].value_integer)); + (long)weechat_script_constants[i].value_integer); } }