@@ -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
811809PyObject *
812810PyErr_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