summaryrefslogtreecommitdiffstats
path: root/Python/codecs.c
diff options
context:
space:
mode:
Diffstat (limited to 'Python/codecs.c')
-rw-r--r--Python/codecs.c28
1 files changed, 3 insertions, 25 deletions
diff --git a/Python/codecs.c b/Python/codecs.c
index 9d800f9..1983f56 100644
--- a/Python/codecs.c
+++ b/Python/codecs.c
@@ -11,6 +11,7 @@ Copyright (c) Corporation for National Research Initiatives.
#include "Python.h"
#include "pycore_call.h" // _PyObject_CallNoArgs()
#include "pycore_interp.h" // PyInterpreterState.codec_search_path
+#include "pycore_pyerrors.h" // _PyErr_FormatNote()
#include "pycore_pystate.h" // _PyInterpreterState_GET()
#include "pycore_ucnhash.h" // _PyUnicode_Name_CAPI
#include <ctype.h>
@@ -382,29 +383,6 @@ PyObject *PyCodec_StreamWriter(const char *encoding,
return codec_getstreamcodec(encoding, stream, errors, 3);
}
-static void
-add_note_to_codec_error(const char *operation,
- const char *encoding)
-{
- PyObject *exc = PyErr_GetRaisedException();
- if (exc == NULL) {
- return;
- }
- PyObject *note = PyUnicode_FromFormat("%s with '%s' codec failed",
- operation, encoding);
- if (note == NULL) {
- _PyErr_ChainExceptions1(exc);
- return;
- }
- int res = _PyException_AddNote(exc, note);
- Py_DECREF(note);
- if (res < 0) {
- _PyErr_ChainExceptions1(exc);
- return;
- }
- PyErr_SetRaisedException(exc);
-}
-
/* Encode an object (e.g. a Unicode object) using the given encoding
and return the resulting encoded object (usually a Python string).
@@ -425,7 +403,7 @@ _PyCodec_EncodeInternal(PyObject *object,
result = PyObject_Call(encoder, args, NULL);
if (result == NULL) {
- add_note_to_codec_error("encoding", encoding);
+ _PyErr_FormatNote("%s with '%s' codec failed", "encoding", encoding);
goto onError;
}
@@ -470,7 +448,7 @@ _PyCodec_DecodeInternal(PyObject *object,
result = PyObject_Call(decoder, args, NULL);
if (result == NULL) {
- add_note_to_codec_error("decoding", encoding);
+ _PyErr_FormatNote("%s with '%s' codec failed", "decoding", encoding);
goto onError;
}
if (!PyTuple_Check(result) ||