Skip to content

Commit e3cec4f

Browse files
committed
use internal _PyUnicodeError_GetParams helper
1 parent 442a938 commit e3cec4f

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

Python/codecs.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -760,22 +760,16 @@ PyObject *PyCodec_XMLCharRefReplaceErrors(PyObject *exc)
760760
return NULL;
761761
}
762762

763-
Py_ssize_t start, end;
764-
if (PyUnicodeEncodeError_GetStart(exc, &start) < 0) {
765-
return NULL;
766-
}
767-
if (PyUnicodeEncodeError_GetEnd(exc, &end) < 0) {
763+
PyObject *obj;
764+
Py_ssize_t objlen, start, end;
765+
if (_PyUnicodeError_GetParams(exc, &obj, &objlen, &start, &end, false) < 0) {
768766
return NULL;
769767
}
770768
if (end <= start) {
769+
Py_DECREF(obj);
771770
return Py_BuildValue("(Nn)", Py_GetConstant(Py_CONSTANT_EMPTY_STR), end);
772771
}
773772

774-
PyObject *obj = PyUnicodeEncodeError_GetObject(exc);
775-
if (obj == NULL) {
776-
return NULL;
777-
}
778-
779773
// The number of characters that each character 'ch' contributes
780774
// in the result is 2 + k + 1, where k = min{t >= 1 | 10^t > ch}
781775
// and will be formatted as "&#" + DIGITS + ";". Since the Unicode
@@ -785,7 +779,7 @@ PyObject *PyCodec_XMLCharRefReplaceErrors(PyObject *exc)
785779
end = start + PY_SSIZE_T_MAX / (2 + 7 + 1);
786780
}
787781

788-
end = Py_MIN(end, PyUnicode_GET_LENGTH(obj));
782+
end = Py_MIN(end, objlen);
789783

790784
Py_ssize_t ressize = 0;
791785
for (Py_ssize_t i = start; i < end; ++i) {

0 commit comments

Comments
 (0)