Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(207047)

Unified Diff: Python/errors.c

Issue 11619: On Windows, don't encode filenames in the import machinery
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Python/compile.c ('k') | Python/future.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/Python/errors.c Mon Aug 26 14:05:19 2013 +0200
+++ b/Python/errors.c Mon Aug 26 16:10:52 2013 +0200
@@ -901,7 +901,8 @@ extern PyObject *PyModule_GetWarningsMod
void
-PyErr_SyntaxLocation(const char *filename, int lineno) {
+PyErr_SyntaxLocation(const char *filename, int lineno)
+{
PyErr_SyntaxLocationEx(filename, lineno, -1);
}
@@ -911,7 +912,7 @@ PyErr_SyntaxLocation(const char *filenam
to make printing of exceptions believe it is a syntax error. */
void
-PyErr_SyntaxLocationEx(const char *filename, int lineno, int col_offset)
+PyErr_SyntaxLocationObject(PyObject *filename, int lineno, int col_offset)
{
PyObject *exc, *v, *tb, *tmp;
_Py_IDENTIFIER(filename);
@@ -945,16 +946,10 @@ PyErr_SyntaxLocationEx(const char *filen
}
}
if (filename != NULL) {
- tmp = PyUnicode_DecodeFSDefault(filename);
- if (tmp == NULL)
+ if (_PyObject_SetAttrId(v, &PyId_filename, filename))
PyErr_Clear();
- else {
- if (_PyObject_SetAttrId(v, &PyId_filename, tmp))
- PyErr_Clear();
- Py_DECREF(tmp);
- }
- tmp = PyErr_ProgramText(filename, lineno);
+ tmp = PyErr_ProgramTextObject(filename, lineno);
if (tmp) {
if (_PyObject_SetAttrId(v, &PyId_text, tmp))
PyErr_Clear();
@@ -984,6 +979,21 @@ PyErr_SyntaxLocationEx(const char *filen
PyErr_Restore(exc, v, tb);
}
+void
+PyErr_SyntaxLocationEx(const char *filename, int lineno, int col_offset)
+{
+ PyObject *fileobj;
+ if (filename != NULL) {
+ fileobj = PyUnicode_DecodeFSDefault(filename);
+ if (fileobj == NULL)
+ PyErr_Clear();
+ }
+ else
+ fileobj = NULL;
+ PyErr_SyntaxLocationObject(fileobj, lineno, col_offset);
+ Py_XDECREF(fileobj);
+}
+
/* Attempt to load the line of text that the exception refers to. If it
fails, it will return NULL but will not set an exception.
@@ -991,15 +1001,11 @@ PyErr_SyntaxLocationEx(const char *filen
functionality in tb_displayline() in traceback.c. */
PyObject *
-PyErr_ProgramText(const char *filename, int lineno)
+err_programtext(FILE *fp, int lineno)
{
- FILE *fp;
int i;
char linebuf[1000];
- if (filename == NULL || *filename == '\0' || lineno <= 0)
- return NULL;
- fp = fopen(filename, "r" PY_STDIOTEXTMODE);
if (fp == NULL)
return NULL;
for (i = 0; i < lineno; i++) {
@@ -1030,6 +1036,26 @@ PyErr_ProgramText(const char *filename,
return NULL;
}
+PyObject *
+PyErr_ProgramText(const char *filename, int lineno)
+{
+ FILE *fp;
+ if (filename == NULL || *filename == '\0' || lineno <= 0)
+ return NULL;
+ fp = fopen(filename, "r" PY_STDIOTEXTMODE);
+ return err_programtext(fp, lineno);
+}
+
+PyObject *
+PyErr_ProgramTextObject(PyObject *filename, int lineno)
+{
+ FILE *fp;
+ if (filename == NULL || lineno <= 0)
+ return NULL;
+ fp = _Py_fopen(filename, "r" PY_STDIOTEXTMODE);
+ return err_programtext(fp, lineno);
+}
+
#ifdef __cplusplus
}
#endif
« no previous file with comments | « Python/compile.c ('k') | Python/future.c » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+