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

Skip to content

Commit c06bb7a

Browse files
author
Victor Stinner
committed
Avoid the Py_UNICODE type in codecs.c
1 parent b31f1bc commit c06bb7a

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

Python/codecs.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,7 @@ PyCodec_SurrogatePassErrors(PyObject *exc)
778778
}
779779
else if (PyObject_IsInstance(exc, PyExc_UnicodeDecodeError)) {
780780
unsigned char *p;
781-
Py_UNICODE ch = 0;
781+
Py_UCS4 ch = 0;
782782
if (PyUnicodeDecodeError_GetStart(exc, &start))
783783
return NULL;
784784
if (!(object = PyUnicodeDecodeError_GetObject(exc)))
@@ -804,7 +804,10 @@ PyCodec_SurrogatePassErrors(PyObject *exc)
804804
PyErr_SetObject(PyExceptionInstance_Class(exc), exc);
805805
return NULL;
806806
}
807-
return Py_BuildValue("(u#n)", &ch, 1, start+3);
807+
res = PyUnicode_FromOrdinal(ch);
808+
if (res == NULL)
809+
return NULL;
810+
return Py_BuildValue("(Nn)", res, start+3);
808811
}
809812
else {
810813
wrong_exception_type(exc);
@@ -853,8 +856,9 @@ PyCodec_SurrogateEscapeErrors(PyObject *exc)
853856
return restuple;
854857
}
855858
else if (PyObject_IsInstance(exc, PyExc_UnicodeDecodeError)) {
859+
PyObject *str;
856860
unsigned char *p;
857-
Py_UNICODE ch[4]; /* decode up to 4 bad bytes. */
861+
Py_UCS2 ch[4]; /* decode up to 4 bad bytes. */
858862
int consumed = 0;
859863
if (PyUnicodeDecodeError_GetStart(exc, &start))
860864
return NULL;
@@ -879,7 +883,10 @@ PyCodec_SurrogateEscapeErrors(PyObject *exc)
879883
PyErr_SetObject(PyExceptionInstance_Class(exc), exc);
880884
return NULL;
881885
}
882-
return Py_BuildValue("(u#n)", ch, consumed, start+consumed);
886+
str = PyUnicode_FromKindAndData(PyUnicode_2BYTE_KIND, ch, consumed);
887+
if (str == NULL)
888+
return NULL;
889+
return Py_BuildValue("(Nn)", str, start+consumed);
883890
}
884891
else {
885892
wrong_exception_type(exc);

0 commit comments

Comments
 (0)