[Python-checkins] cpython: Issue #22156: simplify _tracemalloc.c, use an int for the MAX_NFRAME constant

victor.stinner python-checkins at python.org
Sat Aug 16 15:44:13 CEST 2014


http://hg.python.org/cpython/rev/a318a5ab91fe
changeset:   92119:a318a5ab91fe
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Sat Aug 16 15:44:02 2014 +0200
summary:
  Issue #22156: simplify _tracemalloc.c, use an int for the MAX_NFRAME constant

files:
  Modules/_tracemalloc.c |  12 ++++++------
  1 files changed, 6 insertions(+), 6 deletions(-)


diff --git a/Modules/_tracemalloc.c b/Modules/_tracemalloc.c
--- a/Modules/_tracemalloc.c
+++ b/Modules/_tracemalloc.c
@@ -79,7 +79,7 @@
         (sizeof(traceback_t) + sizeof(frame_t) * (NFRAME - 1))
 
 #define MAX_NFRAME \
-        (((size_t)INT_MAX - sizeof(traceback_t)) / sizeof(frame_t) + 1)
+        ((INT_MAX - (int)sizeof(traceback_t)) / (int)sizeof(frame_t) + 1)
 
 static PyObject *unknown_filename = NULL;
 static traceback_t tracemalloc_empty_traceback;
@@ -874,7 +874,7 @@
         return 0;
     }
 
-    assert(1 <= max_nframe && (size_t)max_nframe <= MAX_NFRAME);
+    assert(1 <= max_nframe && max_nframe <= MAX_NFRAME);
     tracemalloc_config.max_nframe = max_nframe;
 
     /* allocate a buffer to store a new traceback */
@@ -1226,10 +1226,10 @@
     if (!PyArg_ParseTuple(args, "|n:start", &nframe))
         return NULL;
 
-    if (nframe < 1 || (size_t)nframe > MAX_NFRAME) {
+    if (nframe < 1 || nframe > MAX_NFRAME) {
         PyErr_Format(PyExc_ValueError,
                      "the number of frames must be in range [1; %i]",
-                     (int)MAX_NFRAME);
+                     MAX_NFRAME);
         return NULL;
     }
     nframe_int = Py_SAFE_DOWNCAST(nframe, Py_ssize_t, int);
@@ -1388,7 +1388,7 @@
     if (nframe == -1 && PyErr_Occurred())
         return -1;
 
-    if (nframe < 1 || (size_t)nframe > MAX_NFRAME)
+    if (nframe < 1 || nframe > MAX_NFRAME)
         return -1;
 
     return Py_SAFE_DOWNCAST(nframe, long, int);
@@ -1412,7 +1412,7 @@
         value = strtol(p, &endptr, 10);
         if (*endptr != '\0'
             || value < 1
-            || (size_t)value > MAX_NFRAME
+            || value > MAX_NFRAME
             || errno == ERANGE)
         {
             Py_FatalError("PYTHONTRACEMALLOC: invalid number of frames");

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list