]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-131296: fix clang-cl warning in tracemalloc.c (#131514)
authorVictor Stinner <vstinner@python.org>
Sat, 22 Mar 2025 09:38:47 +0000 (10:38 +0100)
committerGitHub <noreply@github.com>
Sat, 22 Mar 2025 09:38:47 +0000 (10:38 +0100)
Always set MAX_NFRAME to UINT16_MAX.

Avoid the complicated code which emitted a compiler warning.

Python/tracemalloc.c

index 2bdb6c36bdb18d70f49572138e123f578f8f453b..7066a214f1065bac435ab70fa94026acfa160b9c 100644 (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;
     }