Skip to content

Commit

Permalink
bpo-46850: Remove _PyEval_CallTracing() function (GH-32019)
Browse files Browse the repository at this point in the history
Remove the private undocumented function _PyEval_CallTracing() from
the C API. Call the public sys.call_tracing() function instead.
  • Loading branch information
vstinner authored Mar 21, 2022
1 parent 9087243 commit e63894b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
2 changes: 0 additions & 2 deletions Include/cpython/ceval.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
# error "this header file must not be included directly"
#endif

PyAPI_FUNC(PyObject *) _PyEval_CallTracing(PyObject *func, PyObject *args);

PyAPI_FUNC(void) PyEval_SetProfile(Py_tracefunc, PyObject *);
PyAPI_DATA(int) _PyEval_SetProfile(PyThreadState *tstate, Py_tracefunc func, PyObject *arg);
PyAPI_FUNC(void) PyEval_SetTrace(Py_tracefunc, PyObject *);
Expand Down
3 changes: 3 additions & 0 deletions Include/internal/pycore_ceval.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ PyAPI_FUNC(void) _PyEval_SignalAsyncExc(PyInterpreterState *interp);
extern PyStatus _PyEval_ReInitThreads(PyThreadState *tstate);
#endif

// Used by sys.call_tracing()
extern PyObject* _PyEval_CallTracing(PyObject *func, PyObject *args);

// Used by sys.get_asyncgen_hooks()
extern PyObject* _PyEval_GetAsyncGenFirstiter(void);
extern PyObject* _PyEval_GetAsyncGenFinalizer(void);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Remove the private undocumented function ``_PyEval_CallTracing()`` from the
C API. Call the public :func:`sys.call_tracing` function instead. Patch by
Victor Stinner.
11 changes: 7 additions & 4 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -6708,16 +6708,19 @@ call_trace(Py_tracefunc func, PyObject *obj,
return result;
}

PyObject *
PyObject*
_PyEval_CallTracing(PyObject *func, PyObject *args)
{
// Save and disable tracing
PyThreadState *tstate = _PyThreadState_GET();
int save_tracing = tstate->tracing;
int save_use_tracing = tstate->cframe->use_tracing;
PyObject *result;

tstate->tracing = 0;
result = PyObject_Call(func, args, NULL);

// Call the tracing function
PyObject *result = PyObject_Call(func, args, NULL);

// Restore tracing
tstate->tracing = save_tracing;
tstate->cframe->use_tracing = save_use_tracing;
return result;
Expand Down

0 comments on commit e63894b

Please sign in to comment.