Mercurial > cpython-lru_cache-weakref
comparison Python/errors.c @ 64859:00e4ce31d404
add PyErr_SyntaxLocationEx, to support adding a column offset
| author | Benjamin Peterson <benjamin@python.org> |
|---|---|
| date | Mon, 20 Sep 2010 22:42:10 +0000 |
| parents | 600c23127207 |
| children | 38ad57db88ac |
comparison
equal
deleted
inserted
replaced
| 64858:0d0f1db63431 | 64859:00e4ce31d404 |
|---|---|
| 778 } | 778 } |
| 779 | 779 |
| 780 extern PyObject *PyModule_GetWarningsModule(void); | 780 extern PyObject *PyModule_GetWarningsModule(void); |
| 781 | 781 |
| 782 | 782 |
| 783 void | |
| 784 PyErr_SyntaxLocation(const char *filename, int lineno) { | |
| 785 PyErr_SyntaxLocationEx(filename, lineno, -1); | |
| 786 } | |
| 787 | |
| 788 | |
| 783 /* Set file and line information for the current exception. | 789 /* Set file and line information for the current exception. |
| 784 If the exception is not a SyntaxError, also sets additional attributes | 790 If the exception is not a SyntaxError, also sets additional attributes |
| 785 to make printing of exceptions believe it is a syntax error. */ | 791 to make printing of exceptions believe it is a syntax error. */ |
| 786 | 792 |
| 787 void | 793 void |
| 788 PyErr_SyntaxLocation(const char *filename, int lineno) | 794 PyErr_SyntaxLocationEx(const char *filename, int lineno, int col_offset) |
| 789 { | 795 { |
| 790 PyObject *exc, *v, *tb, *tmp; | 796 PyObject *exc, *v, *tb, *tmp; |
| 791 | 797 |
| 792 /* add attributes for the line number and filename for the error */ | 798 /* add attributes for the line number and filename for the error */ |
| 793 PyErr_Fetch(&exc, &v, &tb); | 799 PyErr_Fetch(&exc, &v, &tb); |
| 799 PyErr_Clear(); | 805 PyErr_Clear(); |
| 800 else { | 806 else { |
| 801 if (PyObject_SetAttrString(v, "lineno", tmp)) | 807 if (PyObject_SetAttrString(v, "lineno", tmp)) |
| 802 PyErr_Clear(); | 808 PyErr_Clear(); |
| 803 Py_DECREF(tmp); | 809 Py_DECREF(tmp); |
| 810 } | |
| 811 if (col_offset >= 0) { | |
| 812 tmp = PyLong_FromLong(col_offset); | |
| 813 if (tmp == NULL) | |
| 814 PyErr_Clear(); | |
| 815 else { | |
| 816 if (PyObject_SetAttrString(v, "offset", tmp)) | |
| 817 PyErr_Clear(); | |
| 818 Py_DECREF(tmp); | |
| 819 } | |
| 804 } | 820 } |
| 805 if (filename != NULL) { | 821 if (filename != NULL) { |
| 806 tmp = PyUnicode_FromString(filename); | 822 tmp = PyUnicode_FromString(filename); |
| 807 if (tmp == NULL) | 823 if (tmp == NULL) |
| 808 PyErr_Clear(); | 824 PyErr_Clear(); |
