Thanks to visit codestin.com
Credit goes to github.com

Skip to content

gh-102406: replace exception chaining by PEP-678 notes in codecs #102407

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 7 commits into from
Mar 21, 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
Prev Previous commit
Next Next commit
Merge remote-tracking branch 'upstream/main' into codecs-exc
  • Loading branch information
iritkatriel committed Mar 21, 2023
commit af91411cac970a6f49a485156363b515029f4b73
6 changes: 3 additions & 3 deletions Include/cpython/pyerrors.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ PyAPI_FUNC(PyObject *) _PyErr_FormatFromCause(

/* In exceptions.c */

PyAPI_FUNC(PyObject*) _PyException_AddNote(
PyObject *exc,
PyObject *note);
PyAPI_FUNC(int) _PyException_AddNote(
PyObject *exc,
PyObject *note);

/* In signalmodule.c */

Expand Down
10 changes: 6 additions & 4 deletions Objects/exceptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -3749,16 +3749,18 @@ _PyExc_Fini(PyInterpreterState *interp)
_PyExc_FiniTypes(interp);
}


PyObject*
int
_PyException_AddNote(PyObject *exc, PyObject *note)
{
if (!PyExceptionInstance_Check(exc)) {
PyErr_Format(PyExc_TypeError,
"exc must be an exception, not '%s'",
Py_TYPE(exc)->tp_name);
return NULL;
return -1;
}
return BaseException_add_note(exc, note);
PyObject *r = BaseException_add_note(exc, note);
int res = r == NULL ? -1 : 0;
Py_XDECREF(r);
return res;
}

6 changes: 2 additions & 4 deletions Python/codecs.c
Original file line number Diff line number Diff line change
Expand Up @@ -393,14 +393,12 @@ add_note_to_codec_error(const char *operation,
_PyErr_ChainExceptions1(exc);
return;
}
PyObject *res = _PyException_AddNote(exc, note);
int res = _PyException_AddNote(exc, note);
Py_DECREF(note);

if (res == NULL) {
if (res < 0) {
_PyErr_ChainExceptions1(exc);
return;
}
Py_DECREF(res);
PyErr_SetRaisedException(exc);
}

Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.