8000 gh-105140: remove unused arg of _PyErr_ChainStackItem by iritkatriel · Pull Request #105141 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-105140: remove unused arg of _PyErr_ChainStackItem #105141

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

Merged
merged 4 commits into from
Jun 1, 2023
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
3 changes: 1 addition & 2 deletions Include/internal/pycore_pyerrors.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ PyAPI_FUNC(void) _PyErr_SetObject(
PyObject *type,
PyObject *value);

PyAPI_FUNC(void) _PyErr_ChainStackItem(
_PyErr_StackItem *exc_info);
PyAPI_FUNC(void) _PyErr_ChainStackItem(void);

PyAPI_FUNC(void) _PyErr_Clear(PyThreadState *tstate);

Expand Down
2 changes: 1 addition & 1 deletion Objects/genobject.c
< 8000 thead class="sr-only">
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ gen_send_ex2(PyGenObject *gen, PyObject *arg, PyObject **presult,

if (exc) {
assert(_PyErr_Occurred(tstate));
_PyErr_ChainStackItem(NULL);
_PyErr_ChainStackItem();
}

gen->gi_frame_state = FRAME_EXECUTING;
Expand Down
38 changes: 7 additions & 31 deletions Python/errors.c
Original file line number Diff line number Diff line change
Expand Up @@ -703,52 +703,28 @@ _PyErr_ChainExceptions1(PyObject *exc)
}
}

/* Set the currently set exception's context to the given exception.

If the provided exc_info is NULL, then the current Python thread state's
exc_info will be used for the context instead.
/* If the current thread is handling an exception (exc_info is ), set this
exception as the context of the current raised exception.

This function can only be called when _PyErr_Occurred() is true.
Also, this function won't create any cycles in the exception context
chain to the extent that _PyErr_SetObject ensures this. */
void
_PyErr_ChainStackItem(_PyErr_StackItem *exc_info)
_PyErr_ChainStackItem(void)
{
PyThreadState *tstate = _PyThreadState_GET();
assert(_PyErr_Occurred(tstate));

int exc_info_given;
if (exc_info == NULL) {
exc_info_given = 0;
exc_info = tstate->exc_info;
} else {
exc_info_given = 1;
}

_PyErr_StackItem *exc_info = tstate->exc_info;
if (exc_info->exc_value == NULL || exc_info->exc_value == Py_None) {
return;
}

_PyErr_StackItem *saved_exc_info;
if (exc_info_given) {
/* Temporarily set the thread state's exc_info since this is what
_PyErr_SetObject uses for implicit exception chaining. */
saved_exc_info = tstate->exc_info;
tstate->exc_info = exc_info;
}

PyObject *typ, *val, *tb;
_PyErr_Fetch(tstate, &typ, &val, &tb);
PyObject *exc = _PyErr_GetRaisedException(tstate);

/* _PyErr_SetObject sets the context from PyThreadState. */
_PyErr_SetObject(tstate, typ, val);
Py_DECREF(typ); // since _PyErr_Occurred was true
Py_XDECREF(val);
Py_XDECREF(tb);

if (exc_info_given) {
tstate->exc_info = saved_exc_info;
}
_PyErr_SetObject(tstate, (PyObject *) Py_TYPE(exc), exc);
Py_DECREF(exc); // since _PyErr_Occurred was true
}

static PyObject *
Expand Down
0