]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
(backport) tracing of C functions: don't call the trace func
authorArmin Rigo <arigo@tunes.org>
Tue, 20 Sep 2005 20:53:11 +0000 (20:53 +0000)
committerArmin Rigo <arigo@tunes.org>
Tue, 20 Sep 2005 20:53:11 +0000 (20:53 +0000)
with an exception currently set!

Python/ceval.c

index 8a8fdbe7f94284aa79a46ea7ee884726eb72ee00..a1cdb1dfdf88bebe4ec862c31879fc7976db4105 100644 (file)
@@ -99,7 +99,7 @@ static int prtrace(PyObject *, char *);
 static int call_trace(Py_tracefunc, PyObject *, PyFrameObject *,
                      int, PyObject *);
 static void call_trace_protected(Py_tracefunc, PyObject *,
-                                PyFrameObject *, int);
+                                PyFrameObject *, int, PyObject *);
 static void call_exc_trace(Py_tracefunc, PyObject *, PyFrameObject *);
 static int maybe_call_line_trace(Py_tracefunc, PyObject *,
                                  PyFrameObject *, int *, int *, int *);
@@ -2475,14 +2475,14 @@ fast_yield:
                        else if (why == WHY_EXCEPTION) {
                                call_trace_protected(tstate->c_tracefunc,
                                                     tstate->c_traceobj, f,
-                                                    PyTrace_RETURN);
+                                                    PyTrace_RETURN, NULL);
                        }
                }
                if (tstate->c_profilefunc) {
                        if (why == WHY_EXCEPTION)
                                call_trace_protected(tstate->c_profilefunc,
                                                     tstate->c_profileobj, f,
-                                                    PyTrace_RETURN);
+                                                    PyTrace_RETURN, NULL);
                        else if (call_trace(tstate->c_profilefunc,
                                            tstate->c_profileobj, f,
                                            PyTrace_RETURN, retval)) {
@@ -3090,12 +3090,12 @@ call_exc_trace(Py_tracefunc func, PyObject *self, PyFrameObject *f)
 
 static void
 call_trace_protected(Py_tracefunc func, PyObject *obj, PyFrameObject *frame,
-                    int what)
+                    int what, PyObject *arg)
 {
        PyObject *type, *value, *traceback;
        int err;
        PyErr_Fetch(&type, &value, &traceback);
-       err = call_trace(func, obj, frame, what, NULL);
+       err = call_trace(func, obj, frame, what, arg);
        if (err == 0)
                PyErr_Restore(type, value, traceback);
        else {
@@ -3481,31 +3481,36 @@ err_args(PyObject *func, int flags, int nargs)
                             nargs);
 }
 
-#define C_TRACE(call) \
+#define C_TRACE(x, call) \
 if (tstate->use_tracing && tstate->c_profilefunc) { \
        if (call_trace(tstate->c_profilefunc, \
                tstate->c_profileobj, \
                tstate->frame, PyTrace_C_CALL, \
-               func)) \
-               { return NULL; } \
-       call; \
-       if (tstate->c_profilefunc != NULL) { \
-               if (x == NULL) { \
-                       if (call_trace (tstate->c_profilefunc, \
-                               tstate->c_profileobj, \
-                               tstate->frame, PyTrace_C_EXCEPTION, \
-                               func)) \
-                               { return NULL; } \
-               } else { \
-                       if (call_trace(tstate->c_profilefunc, \
-                               tstate->c_profileobj, \
-                               tstate->frame, PyTrace_C_RETURN, \
-                               func)) \
-                               { return NULL; } \
+               func)) { \
+               x = NULL; \
+       } \
+       else { \
+               x = call; \
+               if (tstate->c_profilefunc != NULL) { \
+                       if (x == NULL) { \
+                               call_trace_protected(tstate->c_profilefunc, \
+                                       tstate->c_profileobj, \
+                                       tstate->frame, PyTrace_C_EXCEPTION, \
+                                       func); \
+                               /* XXX should pass (type, value, tb) */ \
+                       } else { \
+                               if (call_trace(tstate->c_profilefunc, \
+                                       tstate->c_profileobj, \
+                                       tstate->frame, PyTrace_C_RETURN, \
+                                       func)) { \
+                                       Py_DECREF(x); \
+                                       x = NULL; \
+                               } \
+                       } \
                } \
        } \
 } else { \
-       call; \
+       x = call; \
        }
 
 static PyObject *
@@ -3534,11 +3539,11 @@ call_function(PyObject ***pp_stack, int oparg
                        PyCFunction meth = PyCFunction_GET_FUNCTION(func);
                        PyObject *self = PyCFunction_GET_SELF(func);
                        if (flags & METH_NOARGS && na == 0) {
-                               C_TRACE(x=(*meth)(self,NULL));
+                               C_TRACE(x(*meth)(self,NULL));
                        }
                        else if (flags & METH_O && na == 1) {
                                PyObject *arg = EXT_POP(*pp_stack);
-                               C_TRACE(x=(*meth)(self,arg));
+                               C_TRACE(x(*meth)(self,arg));
                                Py_DECREF(arg);
                        }
                        else {
@@ -3550,7 +3555,7 @@ call_function(PyObject ***pp_stack, int oparg
                        PyObject *callargs;
                        callargs = load_args(pp_stack, na);
                        rdtscll(*pintr0);
-                       C_TRACE(x=PyCFunction_Call(func,callargs,NULL));
+                       C_TRACE(xPyCFunction_Call(func,callargs,NULL));
                        rdtscll(*pintr1);
                        Py_XDECREF(callargs);
                }