Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8bb6596

Browse files
committed
Suppress uninitialized variable warnings for small stack allocations
Add macros to disable and re-enable compiler-specific warnings aboutpossibly uninitialized variables (`-Wmaybe-uninitialized` for GCC,`-Wuninitialized` for Clang, and warning C4700 for MSVC). Use thesemacros in `_PyEvalFramePushAndInit_Ex()` to suppress false positiveson stack-allocated arrays like `stack_array`.This also addresses warnings such as the one in `pycore_call.h` whenusing `small_stack[_PY_FASTCALL_SMALL_STACK]` that may be flagged byGCC's `-Wmaybe-uninitialized`.
1 parentd47584a commit8bb6596

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

‎Include/pymacro.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,4 +199,21 @@ PyAPI_FUNC(uint32_t) Py_PACK_VERSION(int x, int y);
199199
#endif// Py_LIMITED_API < 3.14
200200

201201

202+
#if defined(__clang__)
203+
#defineDISABLE_UNINIT_WARNINGS_Pragma("clang diagnostic push") \
204+
_Pragma("clang diagnostic ignored\"-Wuninitialized\"")
205+
#define ENABLE_UNINIT_WARNINGS_Pragma("clang diagnostic pop")
206+
#elif defined(__GNUC__) || defined(__GNUG__)
207+
#defineDISABLE_UNINIT_WARNINGS_Pragma("GCC diagnostic push") \
208+
_Pragma("GCC diagnostic ignored\"-Wmaybe-uninitialized\"")
209+
#define ENABLE_UNINIT_WARNINGS_Pragma("GCC diagnostic pop")
210+
#elif defined(_MSC_VER)
211+
#defineDISABLE_UNINIT_WARNINGS__pragma(warning(push)) \
212+
__pragma(warning(disable:4700))
213+
#define ENABLE_UNINIT_WARNINGS__pragma(warning(pop))
214+
#else
215+
#defineDISABLE_UNINIT_WARNINGS
216+
#defineENABLE_UNINIT_WARNINGS
217+
#endif
218+
202219
#endif/* Py_PYMACRO_H*/

‎Python/ceval.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1814,6 +1814,7 @@ _PyEvalFramePushAndInit_Ex(PyThreadState *tstate, _PyStackRef func,
18141814
PyObject*kwnames=NULL;
18151815
_PyStackRef*newargs;
18161816
PyObject*const*object_array=NULL;
1817+
DISABLE_UNINIT_WARNINGS
18171818
_PyStackRefstack_array[8];
18181819
if (has_dict) {
18191820
object_array=_PyStack_UnpackDict(tstate,_PyTuple_ITEMS(callargs),nargs,kwargs,&kwnames);
@@ -1855,6 +1856,7 @@ _PyEvalFramePushAndInit_Ex(PyThreadState *tstate, _PyStackRef func,
18551856
elseif (nargs>8) {
18561857
PyMem_Free((void*)newargs);
18571858
}
1859+
ENABLE_UNINIT_WARNINGS
18581860
/* No need to decref func here because the reference has been stolen by
18591861
_PyEvalFramePushAndInit.
18601862
*/

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp