Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Include/internal/pycore_freelist_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ extern "C" {
# define Py_pycfunctionobject_MAXFREELIST 16
# define Py_pycmethodobject_MAXFREELIST 16
# define Py_pymethodobjects_MAXFREELIST 20
# define Py_tracebacks_MAXFREELIST 8

// A generic freelist of either PyObjects or other data structures.
struct _Py_freelist {
Expand Down Expand Up @@ -66,6 +67,7 @@ struct _Py_freelists {
struct _Py_freelist pycfunctionobject;
struct _Py_freelist pycmethodobject;
struct _Py_freelist pymethodobjects;
struct _Py_freelist tracebacks;
};

#ifdef __cplusplus
Expand Down
1 change: 1 addition & 0 deletions Objects/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,7 @@ _PyObject_ClearFreeLists(struct _Py_freelists *freelists, int is_finalization)
clear_freelist(&freelists->pycfunctionobject, is_finalization, PyObject_GC_Del);
clear_freelist(&freelists->pycmethodobject, is_finalization, PyObject_GC_Del);
clear_freelist(&freelists->pymethodobjects, is_finalization, free_object);
clear_freelist(&freelists->tracebacks, is_finalization, PyObject_GC_Del);
}

/*
Expand Down
16 changes: 9 additions & 7 deletions Python/traceback.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "Python.h"
#include "pycore_call.h" // _PyObject_CallMethod()
#include "pycore_fileutils.h" // _Py_BEGIN_SUPPRESS_IPH
#include "pycore_freelist.h" // _Py_FREELIST_POP()
#include "pycore_frame.h" // PyFrameObject
#include "pycore_interp.h" // PyInterpreterState.gc
#include "pycore_interpframe.h" // _PyFrame_GetCode()
Expand Down Expand Up @@ -79,15 +80,16 @@ tb_create_raw(PyTracebackObject *next, PyFrameObject *frame, int lasti,
int lineno)
{
PyTracebackObject *tb;
if ((next != NULL && !PyTraceBack_Check(next)) ||
frame == NULL || !PyFrame_Check(frame)) {
PyErr_BadInternalCall();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it safe to remove this call? tb_create_raw is used in several C-API calls that can in theory reach this point.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All callers have their own guards: tb_new_impl is checked via AC, _PyTraceBack_FromFrame checks with asserts as well (callers of _PyTraceBack_FromFrame do perform actual checks, _PyTraceBack_FromFrame is internal api). Maybe I missed a path?

return NULL;
assert(next == NULL || PyTraceBack_Check(next));
assert(frame != NULL);
assert(PyFrame_Check(frame));
tb = _Py_FREELIST_POP(PyTracebackObject, tracebacks);
if (tb == NULL) {
tb = PyObject_GC_New(PyTracebackObject, &PyTraceBack_Type);
}
tb = PyObject_GC_New(PyTracebackObject, &PyTraceBack_Type);
if (tb != NULL) {
tb->tb_next = (PyTracebackObject*)Py_XNewRef(next);
tb->tb_frame = (PyFrameObject*)Py_XNewRef(frame);
tb->tb_frame = (PyFrameObject*)Py_NewRef(frame);
tb->tb_lasti = lasti;
tb->tb_lineno = lineno;
PyObject_GC_Track(tb);
Expand Down Expand Up @@ -237,7 +239,7 @@ tb_dealloc(PyObject *op)
PyObject_GC_UnTrack(tb);
Py_XDECREF(tb->tb_next);
Py_XDECREF(tb->tb_frame);
PyObject_GC_Del(tb);
_Py_FREELIST_FREE(tracebacks, tb, PyObject_GC_Del);
}

static int
Expand Down
Loading