Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-102192: deprecate _PyErr_ChainExceptions #102935

Merged
merged 7 commits into from
Apr 1, 2023
Merged
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion Include/cpython/pyerrors.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ PyAPI_FUNC(void) _PyErr_GetExcInfo(PyThreadState *, PyObject **, PyObject **, Py

/* Context manipulation (PEP 3134) */

PyAPI_FUNC(void) _PyErr_ChainExceptions(PyObject *, PyObject *, PyObject *);
Copy link
Member

Choose a reason for hiding this comment

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

This is marked as an API function, so it will need to be added to the "porting to 3.12" section and any other relevant sections in the "what's new".

PyAPI_FUNC(void) _PyErr_ChainExceptions1(PyObject *);

/* Like PyErr_Format(), but saves current exception as __context__ and
Expand Down
37 changes: 0 additions & 37 deletions Python/errors.c
Original file line number Diff line number Diff line change
Expand Up @@ -644,43 +644,6 @@ _PyErr_StackItemToExcInfoTuple(_PyErr_StackItem *err_info)
}


/* Like PyErr_Restore(), but if an exception is already set,
set the context associated with it.

The caller is responsible for ensuring that this call won't create
any cycles in the exception context chain. */
void
_PyErr_ChainExceptions(PyObject *typ, PyObject *val, PyObject *tb)
{
if (typ == NULL)
return;

PyThreadState *tstate = _PyThreadState_GET();

if (!PyExceptionClass_Check(typ)) {
_PyErr_Format(tstate, PyExc_SystemError,
"_PyErr_ChainExceptions: "
"exception %R is not a BaseException subclass",
typ);
return;
}

if (_PyErr_Occurred(tstate)) {
_PyErr_NormalizeException(tstate, &typ, &val, &tb);
if (tb != NULL) {
PyException_SetTraceback(val, tb);
Py_DECREF(tb);
}
Py_DECREF(typ);
PyObject *exc2 = _PyErr_GetRaisedException(tstate);
PyException_SetContext(exc2, val);
_PyErr_SetRaisedException(tstate, exc2);
}
else {
_PyErr_Restore(tstate, typ, val, tb);
}
}

/* Like PyErr_SetRaisedException(), but if an exception is already set,
set the context associated with it.

Expand Down