comparison Python/pythonrun.c @ 61383:85ac27fa913f

err_input(): don't encode/decode the unicode message
author Victor Stinner <victor.stinner@haypocalc.com>
date Sat, 08 May 2010 00:07:07 +0000
parents 7b69e630d237
children b966d5835d3b
comparison
equal deleted inserted replaced
61382:e2bccd372cd6 61383:85ac27fa913f
1894 1894
1895 static void 1895 static void
1896 err_input(perrdetail *err) 1896 err_input(perrdetail *err)
1897 { 1897 {
1898 PyObject *v, *w, *errtype, *errtext; 1898 PyObject *v, *w, *errtype, *errtext;
1899 PyObject* u = NULL; 1899 PyObject *msg_obj = NULL;
1900 char *msg = NULL; 1900 char *msg = NULL;
1901 errtype = PyExc_SyntaxError; 1901 errtype = PyExc_SyntaxError;
1902 switch (err->error) { 1902 switch (err->error) {
1903 case E_ERROR: 1903 case E_ERROR:
1904 return; 1904 return;
1950 msg = "too many levels of indentation"; 1950 msg = "too many levels of indentation";
1951 break; 1951 break;
1952 case E_DECODE: { 1952 case E_DECODE: {
1953 PyObject *type, *value, *tb; 1953 PyObject *type, *value, *tb;
1954 PyErr_Fetch(&type, &value, &tb); 1954 PyErr_Fetch(&type, &value, &tb);
1955 if (value != NULL) { 1955 msg = "unknown decode error";
1956 u = PyObject_Str(value); 1956 if (value != NULL)
1957 if (u != NULL) { 1957 msg_obj = PyObject_Str(value);
1958 msg = _PyUnicode_AsString(u);
1959 }
1960 }
1961 if (msg == NULL)
1962 msg = "unknown decode error";
1963 Py_XDECREF(type); 1958 Py_XDECREF(type);
1964 Py_XDECREF(value); 1959 Py_XDECREF(value);
1965 Py_XDECREF(tb); 1960 Py_XDECREF(tb);
1966 break; 1961 break;
1967 } 1962 }
1986 errtext = PyUnicode_DecodeUTF8(err->text, strlen(err->text), 1981 errtext = PyUnicode_DecodeUTF8(err->text, strlen(err->text),
1987 "replace"); 1982 "replace");
1988 } 1983 }
1989 v = Py_BuildValue("(ziiN)", err->filename, 1984 v = Py_BuildValue("(ziiN)", err->filename,
1990 err->lineno, err->offset, errtext); 1985 err->lineno, err->offset, errtext);
1991 w = NULL; 1986 if (v != NULL) {
1992 if (v != NULL) 1987 if (msg_obj)
1993 w = Py_BuildValue("(sO)", msg, v); 1988 w = Py_BuildValue("(OO)", msg_obj, v);
1994 Py_XDECREF(u); 1989 else
1990 w = Py_BuildValue("(sO)", msg, v);
1991 } else
1992 w = NULL;
1995 Py_XDECREF(v); 1993 Py_XDECREF(v);
1996 PyErr_SetObject(errtype, w); 1994 PyErr_SetObject(errtype, w);
1997 Py_XDECREF(w); 1995 Py_XDECREF(w);
1998 cleanup: 1996 cleanup:
1997 Py_XDECREF(msg_obj);
1999 if (err->text != NULL) { 1998 if (err->text != NULL) {
2000 PyObject_FREE(err->text); 1999 PyObject_FREE(err->text);
2001 err->text = NULL; 2000 err->text = NULL;
2002 } 2001 }
2003 } 2002 }