@@ -11,6 +11,7 @@ Copyright (c) Corporation for National Research Initiatives.
1111#include "Python.h"
1212#include "pycore_call.h" // _PyObject_CallNoArgs()
1313#include "pycore_interp.h" // PyInterpreterState.codec_search_path
14+ #include "pycore_pyerrors.h" // _PyErr_FormatNote()
1415#include "pycore_pystate.h" // _PyInterpreterState_GET()
1516#include "pycore_ucnhash.h" // _PyUnicode_Name_CAPI
1617#include <ctype.h>
@@ -382,29 +383,6 @@ PyObject *PyCodec_StreamWriter(const char *encoding,
382383 return codec_getstreamcodec (encoding , stream , errors , 3 );
383384}
384385
385- static void
386- add_note_to_codec_error (const char * operation ,
387- const char * encoding )
388- {
389- PyObject * exc = PyErr_GetRaisedException ();
390- if (exc == NULL ) {
391- return ;
392- }
393- PyObject * note = PyUnicode_FromFormat ("%s with '%s' codec failed" ,
394- operation , encoding );
395- if (note == NULL ) {
396- _PyErr_ChainExceptions1 (exc );
397- return ;
398- }
399- int res = _PyException_AddNote (exc , note );
400- Py_DECREF (note );
401- if (res < 0 ) {
402- _PyErr_ChainExceptions1 (exc );
403- return ;
404- }
405- PyErr_SetRaisedException (exc );
406- }
407-
408386/* Encode an object (e.g. a Unicode object) using the given encoding
409387 and return the resulting encoded object (usually a Python string).
410388
@@ -425,7 +403,7 @@ _PyCodec_EncodeInternal(PyObject *object,
425403
426404 result = PyObject_Call (encoder , args , NULL );
427405 if (result == NULL ) {
428- add_note_to_codec_error ( "encoding" , encoding );
406+ _PyErr_FormatNote ( "%s with '%s' codec failed" , "encoding" , encoding );
429407 goto onError ;
430408 }
431409
@@ -470,7 +448,7 @@ _PyCodec_DecodeInternal(PyObject *object,
470448
471449 result = PyObject_Call (decoder , args , NULL );
472450 if (result == NULL ) {
473- add_note_to_codec_error ( "decoding" , encoding );
451+ _PyErr_FormatNote ( "%s with '%s' codec failed" , "decoding" , encoding );
474452 goto onError ;
475453 }
476454 if (!PyTuple_Check (result ) ||
0 commit comments