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

Skip to content

Commit b001df0

Browse files
author
Victor Stinner
committed
err_input(): don't encode/decode the unicode message
1 parent 3b2494f commit b001df0

1 file changed

Lines changed: 12 additions & 13 deletions

File tree

Python/pythonrun.c

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1896,7 +1896,7 @@ static void
18961896
err_input(perrdetail *err)
18971897
{
18981898
PyObject *v, *w, *errtype, *errtext;
1899-
PyObject* u = NULL;
1899+
PyObject *msg_obj = NULL;
19001900
char *msg = NULL;
19011901
errtype = PyExc_SyntaxError;
19021902
switch (err->error) {
@@ -1952,14 +1952,9 @@ err_input(perrdetail *err)
19521952
case E_DECODE: {
19531953
PyObject *type, *value, *tb;
19541954
PyErr_Fetch(&type, &value, &tb);
1955-
if (value != NULL) {
1956-
u = PyObject_Str(value);
1957-
if (u != NULL) {
1958-
msg = _PyUnicode_AsString(u);
1959-
}
1960-
}
1961-
if (msg == NULL)
1962-
msg = "unknown decode error";
1955+
msg = "unknown decode error";
1956+
if (value != NULL)
1957+
msg_obj = PyObject_Str(value);
19631958
Py_XDECREF(type);
19641959
Py_XDECREF(value);
19651960
Py_XDECREF(tb);
@@ -1988,14 +1983,18 @@ err_input(perrdetail *err)
19881983
}
19891984
v = Py_BuildValue("(ziiN)", err->filename,
19901985
err->lineno, err->offset, errtext);
1991-
w = NULL;
1992-
if (v != NULL)
1993-
w = Py_BuildValue("(sO)", msg, v);
1994-
Py_XDECREF(u);
1986+
if (v != NULL) {
1987+
if (msg_obj)
1988+
w = Py_BuildValue("(OO)", msg_obj, v);
1989+
else
1990+
w = Py_BuildValue("(sO)", msg, v);
1991+
} else
1992+
w = NULL;
19951993
Py_XDECREF(v);
19961994
PyErr_SetObject(errtype, w);
19971995
Py_XDECREF(w);
19981996
cleanup:
1997+
Py_XDECREF(msg_obj);
19991998
if (err->text != NULL) {
20001999
PyObject_FREE(err->text);
20012000
err->text = NULL;

0 commit comments

Comments
 (0)