Kaydet (Commit) a98b28c1 authored tarafından Victor Stinner's avatar Victor Stinner

Avoid PyUnicode_AS_UNICODE in the UTF-8 encoder

üst 3326cb6a
...@@ -4820,11 +4820,18 @@ _PyUnicode_AsUTF8String(PyObject *unicode, const char *errors) ...@@ -4820,11 +4820,18 @@ _PyUnicode_AsUTF8String(PyObject *unicode, const char *errors)
for(k = repsize; k > 0; k--) for(k = repsize; k > 0; k--)
*p++ = *prep++; *p++ = *prep++;
} else /* rep is unicode */ { } else /* rep is unicode */ {
const Py_UNICODE *prep = PyUnicode_AS_UNICODE(rep); enum PyUnicode_Kind repkind;
Py_UNICODE c; void *repdata;
if (PyUnicode_READY(rep) < 0) {
Py_DECREF(rep);
goto error;
}
repkind = PyUnicode_KIND(rep);
repdata = PyUnicode_DATA(rep);
for(k=0; k<repsize; k++) { for(k=0; k<repsize; k++) {
c = prep[k]; Py_UCS4 c = PyUnicode_READ(repkind, repdata, k);
if (0x80 <= c) { if (0x80 <= c) {
raise_encode_exception(&exc, "utf-8", raise_encode_exception(&exc, "utf-8",
unicode, unicode,
...@@ -4832,7 +4839,7 @@ _PyUnicode_AsUTF8String(PyObject *unicode, const char *errors) ...@@ -4832,7 +4839,7 @@ _PyUnicode_AsUTF8String(PyObject *unicode, const char *errors)
"surrogates not allowed"); "surrogates not allowed");
goto error; goto error;
} }
*p++ = (char)prep[k]; *p++ = (char)c;
} }
} }
Py_DECREF(rep); Py_DECREF(rep);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment