Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ebe8f8a

Browse files
committed
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.
1 parent df4ce10 commit ebe8f8a

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

Python/errors.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -800,13 +800,11 @@ PyErr_SyntaxLocation(const char *filename, int lineno)
800800
PyErr_Restore(exc, v, tb);
801801
}
802802

803-
/* com_fetch_program_text will attempt to load the line of text that
804-
the exception refers to. If it fails, it will return NULL but will
805-
not set an exception.
803+
/* Attempt to load the line of text that the exception refers to. If it
804+
fails, it will return NULL but will not set an exception.
806805
807806
XXX The functionality of this function is quite similar to the
808-
functionality in tb_displayline() in traceback.c.
809-
*/
807+
functionality in tb_displayline() in traceback.c. */
810808

811809
PyObject *
812810
PyErr_ProgramText(const char *filename, int lineno)
@@ -824,7 +822,8 @@ PyErr_ProgramText(const char *filename, int lineno)
824822
char *pLastChar = &linebuf[sizeof(linebuf) - 2];
825823
do {
826824
*pLastChar = '\0';
827-
if (Py_UniversalNewlineFgets(linebuf, sizeof linebuf, fp, NULL) == NULL)
825+
if (Py_UniversalNewlineFgets(linebuf, sizeof linebuf,
826+
fp, NULL) == NULL)
828827
break;
829828
/* fgets read *something*; if it didn't get as
830829
far as pLastChar, it must have found a newline
@@ -836,9 +835,13 @@ PyErr_ProgramText(const char *filename, int lineno)
836835
fclose(fp);
837836
if (i == lineno) {
838837
char *p = linebuf;
838+
PyObject *res;
839839
while (*p == ' ' || *p == '\t' || *p == '\014')
840840
p++;
841-
return PyUnicode_FromString(p);
841+
res = PyUnicode_FromString(p);
842+
if (res == NULL)
843+
PyErr_Clear();
844+
return res;
842845
}
843846
return NULL;
844847
}

0 commit comments

Comments
 (0)