]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Add trace_frame. Fixes #534864.
authorMartin v. Löwis <martin@v.loewis.de>
Sun, 4 Aug 2002 08:26:49 +0000 (08:26 +0000)
committerMartin v. Löwis <martin@v.loewis.de>
Sun, 4 Aug 2002 08:26:49 +0000 (08:26 +0000)
Modules/pyexpat.c

index 3ea022a778d648c4f3ad3f51588e132ee4184ccb..4d09e3d41af0ab197c54d8dde7fe46f3d2b3a695 100644 (file)
@@ -352,6 +352,33 @@ getcode(enum HandlerTypes slot, char* func_name, int lineno)
     return NULL;
 }
 
+static int
+trace_frame(PyThreadState *tstate, PyFrameObject *f, int code, PyObject *val)
+{
+    int result = 0;
+    if (!tstate->use_tracing || tstate->tracing)
+       return 0;
+    if (tstate->c_profilefunc != NULL) {
+       tstate->tracing++;
+       result = tstate->c_profilefunc(tstate->c_profileobj,
+                                      f, code , val);
+       tstate->use_tracing = ((tstate->c_tracefunc != NULL)
+                              || (tstate->c_profilefunc != NULL));
+       tstate->tracing--;
+       if (result)
+           return result;
+    }
+    if (tstate->c_tracefunc != NULL) {
+       tstate->tracing++;
+       result = tstate->c_tracefunc(tstate->c_traceobj,
+                                    f, code , val);
+       tstate->use_tracing = ((tstate->c_tracefunc != NULL)
+                              || (tstate->c_profilefunc != NULL));
+       tstate->tracing--;
+    }  
+    return result;
+}
+
 static PyObject*
 call_with_frame(PyCodeObject *c, PyObject* func, PyObject* args)
 {
@@ -361,6 +388,7 @@ call_with_frame(PyCodeObject *c, PyObject* func, PyObject* args)
 
     if (c == NULL)
         return NULL;
+    
     f = PyFrame_New(
                     tstate,                    /*back*/
                     c,                         /*code*/
@@ -370,9 +398,19 @@ call_with_frame(PyCodeObject *c, PyObject* func, PyObject* args)
     if (f == NULL)
         return NULL;
     tstate->frame = f;
+    if (trace_frame(tstate, f, PyTrace_CALL, Py_None)) {
+       Py_DECREF(f);
+       return NULL;
+    }
     res = PyEval_CallObject(func, args);
     if (res == NULL && tstate->curexc_traceback == NULL)
         PyTraceBack_Here(f);
+    else {
+       if (trace_frame(tstate, f, PyTrace_RETURN, res)) {
+           Py_XDECREF(res);
+           res = NULL;
+       }
+    }
     tstate->frame = f->f_back;
     Py_DECREF(f);
     return res;