gh-131296: fix clang-cl warning in tracemalloc.c (#131514)

Always set MAX_NFRAME to UINT16_MAX.

Avoid the complicated code which emitted a compiler warning.
This commit is contained in:
Victor Stinner 2025-03-22 10:38:47 +01:00 committed by GitHub
parent 8b7d20d3a9
commit 9962469943
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -48,10 +48,7 @@ typedef struct tracemalloc_traceback traceback_t;
#define TRACEBACK_SIZE(NFRAME) \
(sizeof(traceback_t) + sizeof(frame_t) * (NFRAME - 1))
/* The maximum number of frames is either:
- The maximum number of frames we can store in `traceback_t.nframe`
- The maximum memory size_t we can allocate */
static const unsigned long MAX_NFRAME = Py_MIN(UINT16_MAX, ((SIZE_MAX - sizeof(traceback_t)) / sizeof(frame_t) + 1));
static const int MAX_NFRAME = UINT16_MAX;
#define tracemalloc_empty_traceback _PyRuntime.tracemalloc.empty_traceback
@ -791,9 +788,9 @@ tracemalloc_deinit(void)
int
_PyTraceMalloc_Start(int max_nframe)
{
if (max_nframe < 1 || (unsigned long) max_nframe > MAX_NFRAME) {
if (max_nframe < 1 || max_nframe > MAX_NFRAME) {
PyErr_Format(PyExc_ValueError,
"the number of frames must be in range [1; %lu]",
"the number of frames must be in range [1; %i]",
MAX_NFRAME);
return -1;
}