[Python-checkins] cpython (merge 3.5 -> default): Merge 3.5 (_tracemalloc)

victor.stinner python-checkins at python.org
Tue Mar 15 16:58:06 EDT 2016


https://hg.python.org/cpython/rev/5eb223e1638c
changeset:   100550:5eb223e1638c
parent:      100548:18a19e62bac5
parent:      100549:fea3c6e9a38e
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Tue Mar 15 21:57:23 2016 +0100
summary:
  Merge 3.5 (_tracemalloc)

files:
  Modules/_tracemalloc.c |  24 +++++++-----------------
  1 files changed, 7 insertions(+), 17 deletions(-)


diff --git a/Modules/_tracemalloc.c b/Modules/_tracemalloc.c
--- a/Modules/_tracemalloc.c
+++ b/Modules/_tracemalloc.c
@@ -68,7 +68,7 @@
     /* filename cannot be NULL: "<unknown>" is used if the Python frame
        filename is NULL */
     PyObject *filename;
-    int lineno;
+    unsigned int lineno;
 } frame_t;
 
 typedef struct {
@@ -268,12 +268,13 @@
     PyCodeObject *code;
     PyObject *filename;
     _Py_hashtable_entry_t *entry;
+    int lineno;
 
     frame->filename = unknown_filename;
-    frame->lineno = PyFrame_GetLineNumber(pyframe);
-    assert(frame->lineno >= 0);
-    if (frame->lineno < 0)
-        frame->lineno = 0;
+    lineno = PyFrame_GetLineNumber(pyframe);
+    if (lineno < 0)
+        lineno = 0;
+    frame->lineno = (unsigned int)lineno;
 
     code = pyframe->f_code;
     if (code == NULL) {
@@ -377,7 +378,6 @@
     for (pyframe = tstate->frame; pyframe != NULL; pyframe = pyframe->f_back) {
         tracemalloc_get_frame(pyframe, &traceback->frames[traceback->nframe]);
         assert(traceback->frames[traceback->nframe].filename != NULL);
-        assert(traceback->frames[traceback->nframe].lineno >= 0);
         traceback->nframe++;
         if (traceback->nframe == tracemalloc_config.max_nframe)
             break;
@@ -941,15 +941,6 @@
     tracemalloc_traceback = NULL;
 }
 
-static PyObject*
-lineno_as_obj(int lineno)
-{
-    if (lineno >= 0)
-        return PyLong_FromLong(lineno);
-    else
-        Py_RETURN_NONE;
-}
-
 PyDoc_STRVAR(tracemalloc_is_tracing_doc,
     "is_tracing()->bool\n"
     "\n"
@@ -992,8 +983,7 @@
     Py_INCREF(frame->filename);
     PyTuple_SET_ITEM(frame_obj, 0, frame->filename);
 
-    assert(frame->lineno >= 0);
-    lineno_obj = lineno_as_obj(frame->lineno);
+    lineno_obj = PyLong_FromUnsignedLong(frame->lineno);
     if (lineno_obj == NULL) {
         Py_DECREF(frame_obj);
         return NULL;

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


More information about the Python-checkins mailing list