@@ -132,16 +132,19 @@ PyTraceBack_Here(frame)
132132 return 0 ;
133133}
134134
135- static void
135+ static int
136136tb_displayline (f , filename , lineno , name )
137137 PyObject * f ;
138138 char * filename ;
139139 int lineno ;
140140 char * name ;
141141{
142+ int err = 0 ;
142143 FILE * xfp ;
143144 char linebuf [1000 ];
144145 int i ;
146+ if (filename == NULL || name == NULL )
147+ return -1 ;
145148#ifdef MPW
146149 /* This is needed by MPW's File and Line commands */
147150#define FMT " File \"%.900s\"; line %d # in %s\n"
@@ -165,6 +168,10 @@ tb_displayline(f, filename, lineno, name)
165168 char namebuf [MAXPATHLEN + 1 ];
166169 for (i = 0 ; i < npath ; i ++ ) {
167170 PyObject * v = PyList_GetItem (path , i );
171+ if (v == NULL ) {
172+ PyErr_Clear ();
173+ break ;
174+ }
168175 if (PyString_Check (v )) {
169176 int len ;
170177 len = PyString_Size (v );
@@ -186,9 +193,9 @@ tb_displayline(f, filename, lineno, name)
186193 }
187194 }
188195 sprintf (linebuf , FMT , filename , lineno , name );
189- PyFile_WriteString (linebuf , f );
190- if (xfp == NULL )
191- return ;
196+ err = PyFile_WriteString (linebuf , f );
197+ if (xfp == NULL || err != 0 )
198+ return err ;
192199 for (i = 0 ; i < lineno ; i ++ ) {
193200 if (fgets (linebuf , sizeof linebuf , xfp ) == NULL )
194201 break ;
@@ -197,47 +204,55 @@ tb_displayline(f, filename, lineno, name)
197204 char * p = linebuf ;
198205 while (* p == ' ' || * p == '\t' || * p == '\014' )
199206 p ++ ;
200- PyFile_WriteString (" " , f );
201- PyFile_WriteString (p , f );
202- if (strchr (p , '\n' ) == NULL )
203- PyFile_WriteString ("\n" , f );
207+ err = PyFile_WriteString (" " , f );
208+ if (err == 0 ) {
209+ err = PyFile_WriteString (p , f );
210+ if (err == 0 && strchr (p , '\n' ) == NULL )
211+ err = PyFile_WriteString ("\n" , f );
212+ }
204213 }
205214 fclose (xfp );
215+ return err ;
206216}
207217
208- static void
218+ static int
209219tb_printinternal (tb , f , limit )
210220 tracebackobject * tb ;
211221 PyObject * f ;
212222 int limit ;
213223{
224+ int err = 0 ;
214225 int depth = 0 ;
215226 tracebackobject * tb1 = tb ;
216227 while (tb1 != NULL ) {
217228 depth ++ ;
218229 tb1 = tb1 -> tb_next ;
219230 }
220- while (tb != NULL && ! PyOS_InterruptOccurred () ) {
231+ while (tb != NULL && err == 0 ) {
221232 if (depth <= limit ) {
222233 if (Py_OptimizeFlag )
223234 tb -> tb_lineno = PyCode_Addr2Line (
224235 tb -> tb_frame -> f_code , tb -> tb_lasti );
225- tb_displayline (f ,
236+ err = tb_displayline (f ,
226237 PyString_AsString (
227238 tb -> tb_frame -> f_code -> co_filename ),
228239 tb -> tb_lineno ,
229240 PyString_AsString (tb -> tb_frame -> f_code -> co_name ));
230241 }
231242 depth -- ;
232243 tb = tb -> tb_next ;
244+ if (err == 0 )
245+ err = PyErr_CheckSignals ();
233246 }
247+ return err ;
234248}
235249
236250int
237251PyTraceBack_Print (v , f )
238252 PyObject * v ;
239253 PyObject * f ;
240254{
255+ int err ;
241256 PyObject * limitv ;
242257 int limit = 1000 ;
243258 if (v == NULL )
@@ -252,7 +267,8 @@ PyTraceBack_Print(v, f)
252267 if (limit <= 0 )
253268 return 0 ;
254269 }
255- PyFile_WriteString ("Traceback (innermost last):\n" , f );
256- tb_printinternal ((tracebackobject * )v , f , limit );
257- return 0 ;
270+ err = PyFile_WriteString ("Traceback (innermost last):\n" , f );
271+ if (!err )
272+ err = tb_printinternal ((tracebackobject * )v , f , limit );
273+ return err ;
258274}
0 commit comments