Mercurial > cpython-lru_cache-weakref
comparison Python/pythonrun.c @ 43147:06dc4321a56a
Explicitly convert err->text to Unicode. Fixes #1069.
| author | Martin v. Löwis <martin@v.loewis.de> |
|---|---|
| date | Fri, 31 Aug 2007 11:17:42 +0000 |
| parents | 2c02ba72714b |
| children | 38f3f9ef193d |
comparison
equal
deleted
inserted
replaced
| 43146:082cef3be29b | 43147:06dc4321a56a |
|---|---|
| 1457 /* Set the error appropriate to the given input error code (see errcode.h) */ | 1457 /* Set the error appropriate to the given input error code (see errcode.h) */ |
| 1458 | 1458 |
| 1459 static void | 1459 static void |
| 1460 err_input(perrdetail *err) | 1460 err_input(perrdetail *err) |
| 1461 { | 1461 { |
| 1462 PyObject *v, *w, *errtype; | 1462 PyObject *v, *w, *errtype, *errtext; |
| 1463 PyObject* u = NULL; | 1463 PyObject* u = NULL; |
| 1464 char *msg = NULL; | 1464 char *msg = NULL; |
| 1465 errtype = PyExc_SyntaxError; | 1465 errtype = PyExc_SyntaxError; |
| 1466 switch (err->error) { | 1466 switch (err->error) { |
| 1467 case E_SYNTAX: | 1467 case E_SYNTAX: |
| 1537 default: | 1537 default: |
| 1538 fprintf(stderr, "error=%d\n", err->error); | 1538 fprintf(stderr, "error=%d\n", err->error); |
| 1539 msg = "unknown parsing error"; | 1539 msg = "unknown parsing error"; |
| 1540 break; | 1540 break; |
| 1541 } | 1541 } |
| 1542 v = Py_BuildValue("(ziiz)", err->filename, | 1542 /* err->text may not be UTF-8 in case of decoding errors. |
| 1543 err->lineno, err->offset, err->text); | 1543 Explicitly convert to an object. */ |
| 1544 if (!err->text) { | |
| 1545 errtext = Py_None; | |
| 1546 Py_INCREF(Py_None); | |
| 1547 } else { | |
| 1548 errtext = PyUnicode_DecodeUTF8(err->text, strlen(err->text), | |
| 1549 "replace"); | |
| 1550 } | |
| 1551 v = Py_BuildValue("(ziiN)", err->filename, | |
| 1552 err->lineno, err->offset, errtext); | |
| 1544 if (err->text != NULL) { | 1553 if (err->text != NULL) { |
| 1545 PyObject_FREE(err->text); | 1554 PyObject_FREE(err->text); |
| 1546 err->text = NULL; | 1555 err->text = NULL; |
| 1547 } | 1556 } |
| 1548 w = NULL; | 1557 w = NULL; |
