Skip to content
Closed
Changes from 1 commit
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
Next Next commit
Fix races in tracebacks
  • Loading branch information
Fidget-Spinner committed Jul 14, 2024
commit 6cb88977e006ec426daa823921739e12620ac64c
24 changes: 22 additions & 2 deletions Objects/exceptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,16 +308,26 @@ BaseException_set_args(PyBaseExceptionObject *self, PyObject *val, void *Py_UNUS
}

static PyObject *
BaseException_get_tb(PyBaseExceptionObject *self, void *Py_UNUSED(ignored))
BaseException_get_tb_lock_held(PyBaseExceptionObject *self, void *Py_UNUSED(ignored))
{
if (self->traceback == NULL) {
Py_RETURN_NONE;
}
return Py_NewRef(self->traceback);
}

static PyObject *
BaseException_get_tb(PyBaseExceptionObject *self, void *Py_UNUSED(ignored))
Comment thread
Fidget-Spinner marked this conversation as resolved.
Outdated
{
PyObject *res;
Py_BEGIN_CRITICAL_SECTION(self);
res = BaseException_get_tb_lock_held(self, NULL);
Py_END_CRITICAL_SECTION();
return res;
}

static int
BaseException_set_tb(PyBaseExceptionObject *self, PyObject *tb, void *Py_UNUSED(ignored))
BaseException_set_tb_lock_held(PyBaseExceptionObject *self, PyObject *tb, void *Py_UNUSED(ignored))
{
if (tb == NULL) {
PyErr_SetString(PyExc_TypeError, "__traceback__ may not be deleted");
Expand All @@ -337,6 +347,16 @@ BaseException_set_tb(PyBaseExceptionObject *self, PyObject *tb, void *Py_UNUSED(
return 0;
}

static int
BaseException_set_tb(PyBaseExceptionObject *self, PyObject *tb, void *Py_UNUSED(ignored))
{
int res;
Py_BEGIN_CRITICAL_SECTION(self);
res = BaseException_set_tb_lock_held(self, tb, NULL);
Py_END_CRITICAL_SECTION();
return res;
}

static PyObject *
BaseException_get_context(PyObject *self, void *Py_UNUSED(ignored))
{
Expand Down