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

Skip to content

Commit 245a94b

Browse files
committed
Merge heads
2 parents c9f3846 + c06bb7a commit 245a94b

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

Python/codecs.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ PyObject *PyCodec_XMLCharRefReplaceErrors(PyObject *exc)
573573
if (PyObject_IsInstance(exc, PyExc_UnicodeEncodeError)) {
574574
PyObject *restuple;
575575
PyObject *object;
576-
Py_ssize_t i, o;
576+
Py_ssize_t i;
577577
Py_ssize_t start;
578578
Py_ssize_t end;
579579
PyObject *res;
@@ -612,7 +612,7 @@ PyObject *PyCodec_XMLCharRefReplaceErrors(PyObject *exc)
612612
}
613613
outp = PyUnicode_1BYTE_DATA(res);
614614
/* generate replacement */
615-
for (i = start, o = 0; i < end; ++i) {
615+
for (i = start; i < end; ++i) {
616616
int digits;
617617
int base;
618618
ch = PyUnicode_READ_CHAR(object, i);
@@ -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)