mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
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.
This commit is contained in:
parent
df4ce10276
commit
ebe8f8a8ff
1 changed files with 10 additions and 7 deletions
|
@ -800,13 +800,11 @@ PyErr_SyntaxLocation(const char *filename, int lineno)
|
||||||
PyErr_Restore(exc, v, tb);
|
PyErr_Restore(exc, v, tb);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* com_fetch_program_text will attempt to load the line of text that
|
/* Attempt to load the line of text that the exception refers to. If it
|
||||||
the exception refers to. If it fails, it will return NULL but will
|
fails, it will return NULL but will not set an exception.
|
||||||
not set an exception.
|
|
||||||
|
|
||||||
XXX The functionality of this function is quite similar to the
|
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 *
|
PyObject *
|
||||||
PyErr_ProgramText(const char *filename, int lineno)
|
PyErr_ProgramText(const char *filename, int lineno)
|
||||||
|
@ -824,7 +822,8 @@ PyErr_ProgramText(const char *filename, int lineno)
|
||||||
char *pLastChar = &linebuf[sizeof(linebuf) - 2];
|
char *pLastChar = &linebuf[sizeof(linebuf) - 2];
|
||||||
do {
|
do {
|
||||||
*pLastChar = '\0';
|
*pLastChar = '\0';
|
||||||
if (Py_UniversalNewlineFgets(linebuf, sizeof linebuf, fp, NULL) == NULL)
|
if (Py_UniversalNewlineFgets(linebuf, sizeof linebuf,
|
||||||
|
fp, NULL) == NULL)
|
||||||
break;
|
break;
|
||||||
/* fgets read *something*; if it didn't get as
|
/* fgets read *something*; if it didn't get as
|
||||||
far as pLastChar, it must have found a newline
|
far as pLastChar, it must have found a newline
|
||||||
|
@ -836,9 +835,13 @@ PyErr_ProgramText(const char *filename, int lineno)
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
if (i == lineno) {
|
if (i == lineno) {
|
||||||
char *p = linebuf;
|
char *p = linebuf;
|
||||||
|
PyObject *res;
|
||||||
while (*p == ' ' || *p == '\t' || *p == '\014')
|
while (*p == ' ' || *p == '\t' || *p == '\014')
|
||||||
p++;
|
p++;
|
||||||
return PyUnicode_FromString(p);
|
res = PyUnicode_FromString(p);
|
||||||
|
if (res == NULL)
|
||||||
|
PyErr_Clear();
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue