mirror of
https://github.com/python/cpython.git
synced 2024-11-25 10:54:51 +08:00
Fix an issue in PyTokenizer_RestoreEncoding() which was treating a PyBytes
object with PyString calls and not checking errors. This caused the display of syntax errors to be deformed.
This commit is contained in:
parent
feea0786a2
commit
641591cffe
@ -1556,7 +1556,10 @@ dec_utf8(const char *enc, const char *text, size_t len) {
|
|||||||
Py_DECREF(unicode_text);
|
Py_DECREF(unicode_text);
|
||||||
}
|
}
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
PyErr_Print();
|
PyErr_Clear();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
assert(PyBytes_Check(ret));
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -1569,8 +1572,8 @@ PyTokenizer_RestoreEncoding(struct tok_state* tok, int len, int *offset)
|
|||||||
/* convert source to original encondig */
|
/* convert source to original encondig */
|
||||||
PyObject *lineobj = dec_utf8(tok->encoding, tok->buf, len);
|
PyObject *lineobj = dec_utf8(tok->encoding, tok->buf, len);
|
||||||
if (lineobj != NULL) {
|
if (lineobj != NULL) {
|
||||||
int linelen = PyString_Size(lineobj);
|
int linelen = PyBytes_GET_SIZE(lineobj);
|
||||||
const char *line = PyString_AsString(lineobj);
|
const char *line = PyBytes_AS_STRING(lineobj);
|
||||||
text = PyObject_MALLOC(linelen + 1);
|
text = PyObject_MALLOC(linelen + 1);
|
||||||
if (text != NULL && line != NULL) {
|
if (text != NULL && line != NULL) {
|
||||||
if (linelen)
|
if (linelen)
|
||||||
@ -1582,9 +1585,11 @@ PyTokenizer_RestoreEncoding(struct tok_state* tok, int len, int *offset)
|
|||||||
/* adjust error offset */
|
/* adjust error offset */
|
||||||
if (*offset > 1) {
|
if (*offset > 1) {
|
||||||
PyObject *offsetobj = dec_utf8(tok->encoding,
|
PyObject *offsetobj = dec_utf8(tok->encoding,
|
||||||
tok->buf, *offset-1);
|
tok->buf,
|
||||||
|
*offset-1);
|
||||||
if (offsetobj) {
|
if (offsetobj) {
|
||||||
*offset = PyString_Size(offsetobj) + 1;
|
*offset = 1 +
|
||||||
|
PyBytes_GET_SIZE(offsetobj);
|
||||||
Py_DECREF(offsetobj);
|
Py_DECREF(offsetobj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user