From: Charlie Zhao Date: Fri, 6 Oct 2023 23:15:19 +0000 (+0800) Subject: gh-106078: Suppress the warning caused by multi-phase initialization of `decimal... X-Git-Tag: v3.13.0a1~103 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=de1052245f67d5c5a5dbb4f39449f7687f58fd78;p=thirdparty%2FPython%2Fcpython.git gh-106078: Suppress the warning caused by multi-phase initialization of `decimal` (#107524) --- diff --git a/Modules/_decimal/_decimal.c b/Modules/_decimal/_decimal.c index b49ea3cbb410..99ff9aa17b17 100644 --- a/Modules/_decimal/_decimal.c +++ b/Modules/_decimal/_decimal.c @@ -5877,6 +5877,7 @@ error: return NULL; } +static int minalloc_is_set = 0; static int _decimal_exec(PyObject *m) @@ -5899,7 +5900,12 @@ _decimal_exec(PyObject *m) mpd_reallocfunc = PyMem_Realloc; mpd_callocfunc = mpd_callocfunc_em; mpd_free = PyMem_Free; - mpd_setminalloc(_Py_DEC_MINALLOC); + + /* Suppress the warning caused by multi-phase initialization */ + if (!minalloc_is_set) { + mpd_setminalloc(_Py_DEC_MINALLOC); + minalloc_is_set = 1; + } decimal_state *state = get_module_state(m); diff --git a/Tools/c-analyzer/cpython/ignored.tsv b/Tools/c-analyzer/cpython/ignored.tsv index f9911643332b..ca656f0760ab 100644 --- a/Tools/c-analyzer/cpython/ignored.tsv +++ b/Tools/c-analyzer/cpython/ignored.tsv @@ -166,6 +166,9 @@ Python/pylifecycle.c fatal_error reentrant - # explicitly protected, internal-only Modules/_xxinterpchannelsmodule.c - _globals - +# set once during module init +Modules/_decimal/_decimal.c - minalloc_is_set - + ################################## ## not significant