|
8 | 8 |
|
9 | 9 | #define XML_COMBINED_VERSION (10000*XML_MAJOR_VERSION+100*XML_MINOR_VERSION+XML_MICRO_VERSION) |
10 | 10 |
|
11 | | -#define FIX_TRACE |
12 | | - |
13 | 11 | static XML_Memory_Handling_Suite ExpatMemoryHandler = { |
14 | 12 | PyObject_Malloc, PyObject_Realloc, PyObject_Free}; |
15 | 13 |
|
@@ -210,121 +208,17 @@ flag_error(xmlparseobject *self) |
210 | 208 | error_external_entity_ref_handler); |
211 | 209 | } |
212 | 210 |
|
213 | | -static PyCodeObject* |
214 | | -getcode(enum HandlerTypes slot, char* func_name, int lineno) |
215 | | -{ |
216 | | - if (handler_info[slot].tb_code == NULL) { |
217 | | - handler_info[slot].tb_code = |
218 | | - PyCode_NewEmpty(__FILE__, func_name, lineno); |
219 | | - } |
220 | | - return handler_info[slot].tb_code; |
221 | | -} |
222 | | - |
223 | | -#ifdef FIX_TRACE |
224 | | -static int |
225 | | -trace_frame(PyThreadState *tstate, PyFrameObject *f, int code, PyObject *val) |
226 | | -{ |
227 | | - int result = 0; |
228 | | - if (!tstate->use_tracing || tstate->tracing) |
229 | | - return 0; |
230 | | - if (tstate->c_profilefunc != NULL) { |
231 | | - tstate->tracing++; |
232 | | - result = tstate->c_profilefunc(tstate->c_profileobj, |
233 | | - f, code , val); |
234 | | - tstate->use_tracing = ((tstate->c_tracefunc != NULL) |
235 | | - || (tstate->c_profilefunc != NULL)); |
236 | | - tstate->tracing--; |
237 | | - if (result) |
238 | | - return result; |
239 | | - } |
240 | | - if (tstate->c_tracefunc != NULL) { |
241 | | - tstate->tracing++; |
242 | | - result = tstate->c_tracefunc(tstate->c_traceobj, |
243 | | - f, code , val); |
244 | | - tstate->use_tracing = ((tstate->c_tracefunc != NULL) |
245 | | - || (tstate->c_profilefunc != NULL)); |
246 | | - tstate->tracing--; |
247 | | - } |
248 | | - return result; |
249 | | -} |
250 | | - |
251 | | -static int |
252 | | -trace_frame_exc(PyThreadState *tstate, PyFrameObject *f) |
253 | | -{ |
254 | | - PyObject *type, *value, *traceback, *arg; |
255 | | - int err; |
256 | | - |
257 | | - if (tstate->c_tracefunc == NULL) |
258 | | - return 0; |
259 | | - |
260 | | - PyErr_Fetch(&type, &value, &traceback); |
261 | | - if (value == NULL) { |
262 | | - value = Py_None; |
263 | | - Py_INCREF(value); |
264 | | - } |
265 | | - arg = PyTuple_Pack(3, type, value, traceback); |
266 | | - if (arg == NULL) { |
267 | | - PyErr_Restore(type, value, traceback); |
268 | | - return 0; |
269 | | - } |
270 | | - err = trace_frame(tstate, f, PyTrace_EXCEPTION, arg); |
271 | | - Py_DECREF(arg); |
272 | | - if (err == 0) |
273 | | - PyErr_Restore(type, value, traceback); |
274 | | - else { |
275 | | - Py_XDECREF(type); |
276 | | - Py_XDECREF(value); |
277 | | - Py_XDECREF(traceback); |
278 | | - } |
279 | | - return err; |
280 | | -} |
281 | | -#endif |
282 | | - |
283 | 211 | static PyObject* |
284 | | -call_with_frame(PyCodeObject *c, PyObject* func, PyObject* args, |
| 212 | +call_with_frame(char *funcname, int lineno, PyObject* func, PyObject* args, |
285 | 213 | xmlparseobject *self) |
286 | 214 | { |
287 | | - PyThreadState *tstate = PyThreadState_GET(); |
288 | | - PyFrameObject *f; |
289 | | - PyObject *res, *globals; |
| 215 | + PyObject *res; |
290 | 216 |
|
291 | | - if (c == NULL) |
292 | | - return NULL; |
293 | | - |
294 | | - globals = PyEval_GetGlobals(); |
295 | | - if (globals == NULL) { |
296 | | - return NULL; |
297 | | - } |
298 | | - |
299 | | - f = PyFrame_New(tstate, c, globals, NULL); |
300 | | - if (f == NULL) |
301 | | - return NULL; |
302 | | - tstate->frame = f; |
303 | | -#ifdef FIX_TRACE |
304 | | - if (trace_frame(tstate, f, PyTrace_CALL, Py_None) < 0) { |
305 | | - return NULL; |
306 | | - } |
307 | | -#endif |
308 | 217 | res = PyEval_CallObject(func, args); |
309 | 218 | if (res == NULL) { |
310 | | - if (tstate->curexc_traceback == NULL) |
311 | | - PyTraceBack_Here(f); |
| 219 | + _PyTraceback_Add(funcname, __FILE__, lineno); |
312 | 220 | XML_StopParser(self->itself, XML_FALSE); |
313 | | -#ifdef FIX_TRACE |
314 | | - if (trace_frame_exc(tstate, f) < 0) { |
315 | | - return NULL; |
316 | | - } |
317 | 221 | } |
318 | | - else { |
319 | | - if (trace_frame(tstate, f, PyTrace_RETURN, res) < 0) { |
320 | | - Py_CLEAR(res); |
321 | | - } |
322 | | - } |
323 | | -#else |
324 | | - } |
325 | | -#endif |
326 | | - tstate->frame = f->f_back; |
327 | | - Py_DECREF(f); |
328 | 222 | return res; |
329 | 223 | } |
330 | 224 |
|
@@ -376,7 +270,7 @@ call_character_handler(xmlparseobject *self, const XML_Char *buffer, int len) |
376 | 270 | PyTuple_SET_ITEM(args, 0, temp); |
377 | 271 | /* temp is now a borrowed reference; consider it unused. */ |
378 | 272 | self->in_callback = 1; |
379 | | - temp = call_with_frame(getcode(CharacterData, "CharacterData", __LINE__), |
| 273 | + temp = call_with_frame("CharacterData", __LINE__, |
380 | 274 | self->handlers[CharacterData], args, self); |
381 | 275 | /* temp is an owned reference again, or NULL */ |
382 | 276 | self->in_callback = 0; |
@@ -508,7 +402,7 @@ my_StartElementHandler(void *userData, |
508 | 402 | } |
509 | 403 | /* Container is now a borrowed reference; ignore it. */ |
510 | 404 | self->in_callback = 1; |
511 | | - rv = call_with_frame(getcode(StartElement, "StartElement", __LINE__), |
| 405 | + rv = call_with_frame("StartElement", __LINE__, |
512 | 406 | self->handlers[StartElement], args, self); |
513 | 407 | self->in_callback = 0; |
514 | 408 | Py_DECREF(args); |
@@ -537,7 +431,7 @@ my_##NAME##Handler PARAMS {\ |
537 | 431 | args = Py_BuildValue PARAM_FORMAT ;\ |
538 | 432 | if (!args) { flag_error(self); return RETURN;} \ |
539 | 433 | self->in_callback = 1; \ |
540 | | - rv = call_with_frame(getcode(NAME,#NAME,__LINE__), \ |
| 434 | + rv = call_with_frame(#NAME,__LINE__, \ |
541 | 435 | self->handlers[NAME], args, self); \ |
542 | 436 | self->in_callback = 0; \ |
543 | 437 | Py_DECREF(args); \ |
@@ -669,7 +563,7 @@ my_ElementDeclHandler(void *userData, |
669 | 563 | goto finally; |
670 | 564 | } |
671 | 565 | self->in_callback = 1; |
672 | | - rv = call_with_frame(getcode(ElementDecl, "ElementDecl", __LINE__), |
| 566 | + rv = call_with_frame("ElementDecl", __LINE__, |
673 | 567 | self->handlers[ElementDecl], args, self); |
674 | 568 | self->in_callback = 0; |
675 | 569 | if (rv == NULL) { |
|
0 commit comments