@@ -15,8 +15,6 @@ module pyexpat
1515
1616#define XML_COMBINED_VERSION (10000*XML_MAJOR_VERSION+100*XML_MINOR_VERSION+XML_MICRO_VERSION)
1717
18- #define FIX_TRACE
19-
2018static XML_Memory_Handling_Suite ExpatMemoryHandler = {
2119 PyObject_Malloc , PyObject_Realloc , PyObject_Free };
2220
@@ -217,121 +215,17 @@ flag_error(xmlparseobject *self)
217215 error_external_entity_ref_handler );
218216}
219217
220- static PyCodeObject *
221- getcode (enum HandlerTypes slot , char * func_name , int lineno )
222- {
223- if (handler_info [slot ].tb_code == NULL ) {
224- handler_info [slot ].tb_code =
225- PyCode_NewEmpty (__FILE__ , func_name , lineno );
226- }
227- return handler_info [slot ].tb_code ;
228- }
229-
230- #ifdef FIX_TRACE
231- static int
232- trace_frame (PyThreadState * tstate , PyFrameObject * f , int code , PyObject * val )
233- {
234- int result = 0 ;
235- if (!tstate -> use_tracing || tstate -> tracing )
236- return 0 ;
237- if (tstate -> c_profilefunc != NULL ) {
238- tstate -> tracing ++ ;
239- result = tstate -> c_profilefunc (tstate -> c_profileobj ,
240- f , code , val );
241- tstate -> use_tracing = ((tstate -> c_tracefunc != NULL )
242- || (tstate -> c_profilefunc != NULL ));
243- tstate -> tracing -- ;
244- if (result )
245- return result ;
246- }
247- if (tstate -> c_tracefunc != NULL ) {
248- tstate -> tracing ++ ;
249- result = tstate -> c_tracefunc (tstate -> c_traceobj ,
250- f , code , val );
251- tstate -> use_tracing = ((tstate -> c_tracefunc != NULL )
252- || (tstate -> c_profilefunc != NULL ));
253- tstate -> tracing -- ;
254- }
255- return result ;
256- }
257-
258- static int
259- trace_frame_exc (PyThreadState * tstate , PyFrameObject * f )
260- {
261- PyObject * type , * value , * traceback , * arg ;
262- int err ;
263-
264- if (tstate -> c_tracefunc == NULL )
265- return 0 ;
266-
267- PyErr_Fetch (& type , & value , & traceback );
268- if (value == NULL ) {
269- value = Py_None ;
270- Py_INCREF (value );
271- }
272- arg = PyTuple_Pack (3 , type , value , traceback );
273- if (arg == NULL ) {
274- PyErr_Restore (type , value , traceback );
275- return 0 ;
276- }
277- err = trace_frame (tstate , f , PyTrace_EXCEPTION , arg );
278- Py_DECREF (arg );
279- if (err == 0 )
280- PyErr_Restore (type , value , traceback );
281- else {
282- Py_XDECREF (type );
283- Py_XDECREF (value );
284- Py_XDECREF (traceback );
285- }
286- return err ;
287- }
288- #endif
289-
290218static PyObject *
291- call_with_frame (PyCodeObject * c , PyObject * func , PyObject * args ,
219+ call_with_frame (char * funcname , int lineno , PyObject * func , PyObject * args ,
292220 xmlparseobject * self )
293221{
294- PyThreadState * tstate = PyThreadState_GET ();
295- PyFrameObject * f ;
296- PyObject * res , * globals ;
222+ PyObject * res ;
297223
298- if (c == NULL )
299- return NULL ;
300-
301- globals = PyEval_GetGlobals ();
302- if (globals == NULL ) {
303- return NULL ;
304- }
305-
306- f = PyFrame_New (tstate , c , globals , NULL );
307- if (f == NULL )
308- return NULL ;
309- tstate -> frame = f ;
310- #ifdef FIX_TRACE
311- if (trace_frame (tstate , f , PyTrace_CALL , Py_None ) < 0 ) {
312- return NULL ;
313- }
314- #endif
315224 res = PyEval_CallObject (func , args );
316225 if (res == NULL ) {
317- if (tstate -> curexc_traceback == NULL )
318- PyTraceBack_Here (f );
226+ _PyTraceback_Add (funcname , __FILE__ , lineno );
319227 XML_StopParser (self -> itself , XML_FALSE );
320- #ifdef FIX_TRACE
321- if (trace_frame_exc (tstate , f ) < 0 ) {
322- return NULL ;
323- }
324228 }
325- else {
326- if (trace_frame (tstate , f , PyTrace_RETURN , res ) < 0 ) {
327- Py_CLEAR (res );
328- }
329- }
330- #else
331- }
332- #endif
333- tstate -> frame = f -> f_back ;
334- Py_DECREF (f );
335229 return res ;
336230}
337231
@@ -383,7 +277,7 @@ call_character_handler(xmlparseobject *self, const XML_Char *buffer, int len)
383277 PyTuple_SET_ITEM (args , 0 , temp );
384278 /* temp is now a borrowed reference; consider it unused. */
385279 self -> in_callback = 1 ;
386- temp = call_with_frame (getcode ( CharacterData , "CharacterData" , __LINE__ ) ,
280+ temp = call_with_frame ("CharacterData" , __LINE__ ,
387281 self -> handlers [CharacterData ], args , self );
388282 /* temp is an owned reference again, or NULL */
389283 self -> in_callback = 0 ;
@@ -515,7 +409,7 @@ my_StartElementHandler(void *userData,
515409 }
516410 /* Container is now a borrowed reference; ignore it. */
517411 self -> in_callback = 1 ;
518- rv = call_with_frame (getcode ( StartElement , "StartElement" , __LINE__ ) ,
412+ rv = call_with_frame ("StartElement" , __LINE__ ,
519413 self -> handlers [StartElement ], args , self );
520414 self -> in_callback = 0 ;
521415 Py_DECREF (args );
@@ -544,7 +438,7 @@ my_##NAME##Handler PARAMS {\
544438 args = Py_BuildValue PARAM_FORMAT ;\
545439 if (!args) { flag_error(self); return RETURN;} \
546440 self->in_callback = 1; \
547- rv = call_with_frame(getcode(NAME, #NAME,__LINE__) , \
441+ rv = call_with_frame(#NAME,__LINE__, \
548442 self->handlers[NAME], args, self); \
549443 self->in_callback = 0; \
550444 Py_DECREF(args); \
@@ -676,7 +570,7 @@ my_ElementDeclHandler(void *userData,
676570 goto finally ;
677571 }
678572 self -> in_callback = 1 ;
679- rv = call_with_frame (getcode ( ElementDecl , "ElementDecl" , __LINE__ ) ,
573+ rv = call_with_frame ("ElementDecl" , __LINE__ ,
680574 self -> handlers [ElementDecl ], args , self );
681575 self -> in_callback = 0 ;
682576 if (rv == NULL ) {
0 commit comments