summaryrefslogtreecommitdiffstats
path: root/Python/errors.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2007-10-10 18:53:36 (GMT)
committerGuido van Rossum <guido@python.org>2007-10-10 18:53:36 (GMT)
commitebe8f8a8ff52f4b32a13458a92c96e18299d5286 (patch)
treef2bf25b63026dbaad091d12ceb0721cb80a515f7 /Python/errors.c
parentdf4ce10276819593089b7dc922401e24da8f8911 (diff)
downloadcpython-ebe8f8a8ff52f4b32a13458a92c96e18299d5286.zip
cpython-ebe8f8a8ff52f4b32a13458a92c96e18299d5286.tar.gz
cpython-ebe8f8a8ff52f4b32a13458a92c96e18299d5286.tar.bz2
Minor cleanup of the comment for PyErr_ProgramText() and a tweak to the code
to guarantee the claim that it doesn't set an exception.
Diffstat (limited to 'Python/errors.c')
-rw-r--r--Python/errors.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/Python/errors.c b/Python/errors.c
index b1a70ef..e543506 100644
--- a/Python/errors.c
+++ b/Python/errors.c
@@ -800,13 +800,11 @@ PyErr_SyntaxLocation(const char *filename, int lineno)
PyErr_Restore(exc, v, tb);
}
-/* com_fetch_program_text will 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.
+/* 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.
XXX The functionality of this function is quite similar to the
- functionality in tb_displayline() in traceback.c.
-*/
+ functionality in tb_displayline() in traceback.c. */
PyObject *
PyErr_ProgramText(const char *filename, int lineno)
@@ -824,7 +822,8 @@ PyErr_ProgramText(const char *filename, int lineno)
char *pLastChar = &linebuf[sizeof(linebuf) - 2];
do {
*pLastChar = '\0';
- if (Py_UniversalNewlineFgets(linebuf, sizeof linebuf, fp, NULL) == NULL)
+ if (Py_UniversalNewlineFgets(linebuf, sizeof linebuf,
+ fp, NULL) == NULL)
break;
/* fgets read *something*; if it didn't get as
far as pLastChar, it must have found a newline
@@ -836,9 +835,13 @@ PyErr_ProgramText(const char *filename, int lineno)
fclose(fp);
if (i == lineno) {
char *p = linebuf;
+ PyObject *res;
while (*p == ' ' || *p == '\t' || *p == '\014')
p++;
- return PyUnicode_FromString(p);
+ res = PyUnicode_FromString(p);
+ if (res == NULL)
+ PyErr_Clear();
+ return res;
}
return NULL;
}