mirror of
https://github.com/python/cpython.git
synced 2025-09-05 00:11:10 +00:00
_tracemalloc: store lineno as unsigned int
Issue #26564. Cleanup the code, lineno is never negative.
This commit is contained in:
parent
57003f81ea
commit
9528334e16
1 changed files with 7 additions and 17 deletions
|
@ -66,7 +66,7 @@ _declspec(align(4))
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
PyObject *filename;
|
PyObject *filename;
|
||||||
int lineno;
|
unsigned int lineno;
|
||||||
} frame_t;
|
} frame_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -266,12 +266,13 @@ tracemalloc_get_frame(PyFrameObject *pyframe, frame_t *frame)
|
||||||
PyCodeObject *code;
|
PyCodeObject *code;
|
||||||
PyObject *filename;
|
PyObject *filename;
|
||||||
_Py_hashtable_entry_t *entry;
|
_Py_hashtable_entry_t *entry;
|
||||||
|
int lineno;
|
||||||
|
|
||||||
frame->filename = unknown_filename;
|
frame->filename = unknown_filename;
|
||||||
frame->lineno = PyFrame_GetLineNumber(pyframe);
|
lineno = PyFrame_GetLineNumber(pyframe);
|
||||||
assert(frame->lineno >= 0);
|
if (lineno < 0)
|
||||||
if (frame->lineno < 0)
|
lineno = 0;
|
||||||
frame->lineno = 0;
|
frame->lineno = (unsigned int)lineno;
|
||||||
|
|
||||||
code = pyframe->f_code;
|
code = pyframe->f_code;
|
||||||
if (code == NULL) {
|
if (code == NULL) {
|
||||||
|
@ -375,7 +376,6 @@ traceback_get_frames(traceback_t *traceback)
|
||||||
for (pyframe = tstate->frame; pyframe != NULL; pyframe = pyframe->f_back) {
|
for (pyframe = tstate->frame; pyframe != NULL; pyframe = pyframe->f_back) {
|
||||||
tracemalloc_get_frame(pyframe, &traceback->frames[traceback->nframe]);
|
tracemalloc_get_frame(pyframe, &traceback->frames[traceback->nframe]);
|
||||||
assert(traceback->frames[traceback->nframe].filename != NULL);
|
assert(traceback->frames[traceback->nframe].filename != NULL);
|
||||||
assert(traceback->frames[traceback->nframe].lineno >= 0);
|
|
||||||
traceback->nframe++;
|
traceback->nframe++;
|
||||||
if (traceback->nframe == tracemalloc_config.max_nframe)
|
if (traceback->nframe == tracemalloc_config.max_nframe)
|
||||||
break;
|
break;
|
||||||
|
@ -943,15 +943,6 @@ tracemalloc_stop(void)
|
||||||
tracemalloc_traceback = NULL;
|
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,
|
PyDoc_STRVAR(tracemalloc_is_tracing_doc,
|
||||||
"is_tracing()->bool\n"
|
"is_tracing()->bool\n"
|
||||||
"\n"
|
"\n"
|
||||||
|
@ -996,8 +987,7 @@ frame_to_pyobject(frame_t *frame)
|
||||||
Py_INCREF(frame->filename);
|
Py_INCREF(frame->filename);
|
||||||
PyTuple_SET_ITEM(frame_obj, 0, frame->filename);
|
PyTuple_SET_ITEM(frame_obj, 0, frame->filename);
|
||||||
|
|
||||||
assert(frame->lineno >= 0);
|
lineno_obj = PyLong_FromUnsignedLong(frame->lineno);
|
||||||
lineno_obj = lineno_as_obj(frame->lineno);
|
|
||||||
if (lineno_obj == NULL) {
|
if (lineno_obj == NULL) {
|
||||||
Py_DECREF(frame_obj);
|
Py_DECREF(frame_obj);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue