Skip to content

Commit 9087243

Browse files
authored
bpo-46850: Remove _PyEval_GetCoroutineOriginTrackingDepth() (GH-32018)
Remove the private undocumented function _PyEval_GetCoroutineOriginTrackingDepth() from the C API. Call the public sys.get_coroutine_origin_tracking_depth() function instead. Change the internal function _PyEval_SetCoroutineOriginTrackingDepth(): * Remove the 'tstate' parameter; * Add return value and raises an exception if depth is negative; * No longer export the function: call the public sys.set_coroutine_origin_tracking_depth() function instead. Uniformize also function declarations in pycore_ceval.h.
1 parent 332b04b commit 9087243

File tree

5 files changed

+25
-17
lines changed

5 files changed

+25
-17
lines changed

Include/cpython/ceval.h

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ PyAPI_FUNC(void) PyEval_SetProfile(Py_tracefunc, PyObject *);
88
PyAPI_DATA(int) _PyEval_SetProfile(PyThreadState *tstate, Py_tracefunc func, PyObject *arg);
99
PyAPI_FUNC(void) PyEval_SetTrace(Py_tracefunc, PyObject *);
1010
PyAPI_FUNC(int) _PyEval_SetTrace(PyThreadState *tstate, Py_tracefunc func, PyObject *arg);
11-
PyAPI_FUNC(int) _PyEval_GetCoroutineOriginTrackingDepth(void);
1211

1312
/* Helper to look up a builtin object */
1413
PyAPI_FUNC(PyObject *) _PyEval_GetBuiltin(PyObject *);

Include/internal/pycore_ceval.h

+10-8
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ PyAPI_FUNC(void) _PyEval_SignalAsyncExc(PyInterpreterState *interp);
3333
#ifdef HAVE_FORK
3434
extern PyStatus _PyEval_ReInitThreads(PyThreadState *tstate);
3535
#endif
36-
PyAPI_FUNC(void) _PyEval_SetCoroutineOriginTrackingDepth(
37-
PyThreadState *tstate,
38-
int new_depth);
3936

4037
// Used by sys.get_asyncgen_hooks()
4138
extern PyObject* _PyEval_GetAsyncGenFirstiter(void);
@@ -45,11 +42,16 @@ extern PyObject* _PyEval_GetAsyncGenFinalizer(void);
4542
extern int _PyEval_SetAsyncGenFirstiter(PyObject *);
4643
extern int _PyEval_SetAsyncGenFinalizer(PyObject *);
4744

48-
void _PyEval_Fini(void);
45+
// Used by sys.get_coroutine_origin_tracking_depth()
46+
// and sys.set_coroutine_origin_tracking_depth()
47+
extern int _PyEval_GetCoroutineOriginTrackingDepth(void);
48+
extern int _PyEval_SetCoroutineOriginTrackingDepth(int depth);
49+
50+
extern void _PyEval_Fini(void);
4951

5052

5153
extern PyObject* _PyEval_GetBuiltins(PyThreadState *tstate);
52-
extern PyObject *_PyEval_BuiltinsFromGlobals(
54+
extern PyObject* _PyEval_BuiltinsFromGlobals(
5355
PyThreadState *tstate,
5456
PyObject *globals);
5557

@@ -63,7 +65,7 @@ _PyEval_EvalFrame(PyThreadState *tstate, struct _PyInterpreterFrame *frame, int
6365
return tstate->interp->eval_frame(tstate, frame, throwflag);
6466
}
6567

66-
extern PyObject *
68+
extern PyObject*
6769
_PyEval_Vector(PyThreadState *tstate,
6870
PyFunctionObject *func, PyObject *locals,
6971
PyObject* const* args, size_t argcount,
@@ -124,9 +126,9 @@ static inline void _Py_LeaveRecursiveCall_inline(void) {
124126

125127
#define Py_LeaveRecursiveCall() _Py_LeaveRecursiveCall_inline()
126128

127-
struct _PyInterpreterFrame *_PyEval_GetFrame(void);
129+
extern struct _PyInterpreterFrame* _PyEval_GetFrame(void);
128130

129-
PyObject *_Py_MakeCoro(PyFunctionObject *func);
131+
extern PyObject* _Py_MakeCoro(PyFunctionObject *func);
130132

131133
#ifdef __cplusplus
132134
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Remove the private undocumented function
2+
``_PyEval_GetCoroutineOriginTrackingDepth()`` from the C API. Call the
3+
public :func:`sys.get_coroutine_origin_tracking_depth` function instead.
4+
Patch by Victor Stinner.

Python/ceval.c

+10-4
Original file line numberDiff line numberDiff line change
@@ -6852,13 +6852,19 @@ PyEval_SetTrace(Py_tracefunc func, PyObject *arg)
68526852
}
68536853

68546854

6855-
void
6856-
_PyEval_SetCoroutineOriginTrackingDepth(PyThreadState *tstate, int new_depth)
6855+
int
6856+
_PyEval_SetCoroutineOriginTrackingDepth(int depth)
68576857
{
6858-
assert(new_depth >= 0);
6859-
tstate->coroutine_origin_tracking_depth = new_depth;
6858+
PyThreadState *tstate = _PyThreadState_GET();
6859+
if (depth < 0) {
6860+
_PyErr_SetString(tstate, PyExc_ValueError, "depth must be >= 0");
6861+
return -1;
6862+
}
6863+
tstate->coroutine_origin_tracking_depth = depth;
6864+
return 0;
68606865
}
68616866

6867+
68626868
int
68636869
_PyEval_GetCoroutineOriginTrackingDepth(void)
68646870
{

Python/sysmodule.c

+1-4
Original file line numberDiff line numberDiff line change
@@ -1186,12 +1186,9 @@ static PyObject *
11861186
sys_set_coroutine_origin_tracking_depth_impl(PyObject *module, int depth)
11871187
/*[clinic end generated code: output=0a2123c1cc6759c5 input=a1d0a05f89d2c426]*/
11881188
{
1189-
PyThreadState *tstate = _PyThreadState_GET();
1190-
if (depth < 0) {
1191-
_PyErr_SetString(tstate, PyExc_ValueError, "depth must be >= 0");
1189+
if (_PyEval_SetCoroutineOriginTrackingDepth(depth) < 0) {
11921190
return NULL;
11931191
}
1194-
_PyEval_SetCoroutineOriginTrackingDepth(tstate, depth);
11951192
Py_RETURN_NONE;
11961193
}
11971194

0 commit comments

Comments
 (0)