]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-46850: Remove _PyEval_GetCoroutineOriginTrackingDepth() (GH-32018)
authorVictor Stinner <vstinner@python.org>
Mon, 21 Mar 2022 01:24:00 +0000 (02:24 +0100)
committerGitHub <noreply@github.com>
Mon, 21 Mar 2022 01:24:00 +0000 (02:24 +0100)
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.

Include/cpython/ceval.h
Include/internal/pycore_ceval.h
Misc/NEWS.d/next/C API/2022-03-21-01-30-14.bpo-46850.Tfxde5.rst [new file with mode: 0644]
Python/ceval.c
Python/sysmodule.c

index 47c86f9da202f1630d27e9d6b26d34c2c7e44938..e0a68876015d606f36b98360f58d84e8a06c0a49 100644 (file)
@@ -8,7 +8,6 @@ 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 *);
 PyAPI_FUNC(int) _PyEval_SetTrace(PyThreadState *tstate, Py_tracefunc func, PyObject *arg);
-PyAPI_FUNC(int) _PyEval_GetCoroutineOriginTrackingDepth(void);
 
 /* Helper to look up a builtin object */
 PyAPI_FUNC(PyObject *) _PyEval_GetBuiltin(PyObject *);
index 3efd13d01c7c52a5c232e8c78095103b8edc77b0..59a3453f9fd3bccba469b11252e584c607a2031c 100644 (file)
@@ -33,9 +33,6 @@ PyAPI_FUNC(void) _PyEval_SignalAsyncExc(PyInterpreterState *interp);
 #ifdef HAVE_FORK
 extern PyStatus _PyEval_ReInitThreads(PyThreadState *tstate);
 #endif
-PyAPI_FUNC(void) _PyEval_SetCoroutineOriginTrackingDepth(
-    PyThreadState *tstate,
-    int new_depth);
 
 // Used by sys.get_asyncgen_hooks()
 extern PyObject* _PyEval_GetAsyncGenFirstiter(void);
@@ -45,11 +42,16 @@ extern PyObject* _PyEval_GetAsyncGenFinalizer(void);
 extern int _PyEval_SetAsyncGenFirstiter(PyObject *);
 extern int _PyEval_SetAsyncGenFinalizer(PyObject *);
 
-void _PyEval_Fini(void);
+// Used by sys.get_coroutine_origin_tracking_depth()
+// and sys.set_coroutine_origin_tracking_depth()
+extern int _PyEval_GetCoroutineOriginTrackingDepth(void);
+extern int _PyEval_SetCoroutineOriginTrackingDepth(int depth);
+
+extern void _PyEval_Fini(void);
 
 
 extern PyObject* _PyEval_GetBuiltins(PyThreadState *tstate);
-extern PyObject *_PyEval_BuiltinsFromGlobals(
+extern PyObject_PyEval_BuiltinsFromGlobals(
     PyThreadState *tstate,
     PyObject *globals);
 
@@ -63,7 +65,7 @@ _PyEval_EvalFrame(PyThreadState *tstate, struct _PyInterpreterFrame *frame, int
     return tstate->interp->eval_frame(tstate, frame, throwflag);
 }
 
-extern PyObject *
+extern PyObject*
 _PyEval_Vector(PyThreadState *tstate,
             PyFunctionObject *func, PyObject *locals,
             PyObject* const* args, size_t argcount,
@@ -124,9 +126,9 @@ static inline void _Py_LeaveRecursiveCall_inline(void)  {
 
 #define Py_LeaveRecursiveCall() _Py_LeaveRecursiveCall_inline()
 
-struct _PyInterpreterFrame *_PyEval_GetFrame(void);
+extern struct _PyInterpreterFrame* _PyEval_GetFrame(void);
 
-PyObject *_Py_MakeCoro(PyFunctionObject *func);
+extern PyObject* _Py_MakeCoro(PyFunctionObject *func);
 
 #ifdef __cplusplus
 }
diff --git a/Misc/NEWS.d/next/C API/2022-03-21-01-30-14.bpo-46850.Tfxde5.rst b/Misc/NEWS.d/next/C API/2022-03-21-01-30-14.bpo-46850.Tfxde5.rst
new file mode 100644 (file)
index 0000000..0dc01fe
--- /dev/null
@@ -0,0 +1,4 @@
+Remove the private undocumented function
+``_PyEval_GetCoroutineOriginTrackingDepth()`` from the C API. Call the
+public :func:`sys.get_coroutine_origin_tracking_depth` function instead.
+Patch by Victor Stinner.
index 1a120bba83f8cdd6824e847887e0637c5f163230..04f2dde3cbdf91c80be227419e35e7eb03f7f7b0 100644 (file)
@@ -6852,13 +6852,19 @@ PyEval_SetTrace(Py_tracefunc func, PyObject *arg)
 }
 
 
-void
-_PyEval_SetCoroutineOriginTrackingDepth(PyThreadState *tstate, int new_depth)
+int
+_PyEval_SetCoroutineOriginTrackingDepth(int depth)
 {
-    assert(new_depth >= 0);
-    tstate->coroutine_origin_tracking_depth = new_depth;
+    PyThreadState *tstate = _PyThreadState_GET();
+    if (depth < 0) {
+        _PyErr_SetString(tstate, PyExc_ValueError, "depth must be >= 0");
+        return -1;
+    }
+    tstate->coroutine_origin_tracking_depth = depth;
+    return 0;
 }
 
+
 int
 _PyEval_GetCoroutineOriginTrackingDepth(void)
 {
index ae6d7c2955f818bb1fcfa86be7a6d04a8f2ee4ab..c89f81f689f7e3887cbbfdfe9a0845a222a6e121 100644 (file)
@@ -1186,12 +1186,9 @@ static PyObject *
 sys_set_coroutine_origin_tracking_depth_impl(PyObject *module, int depth)
 /*[clinic end generated code: output=0a2123c1cc6759c5 input=a1d0a05f89d2c426]*/
 {
-    PyThreadState *tstate = _PyThreadState_GET();
-    if (depth < 0) {
-        _PyErr_SetString(tstate, PyExc_ValueError, "depth must be >= 0");
+    if (_PyEval_SetCoroutineOriginTrackingDepth(depth) < 0) {
         return NULL;
     }
-    _PyEval_SetCoroutineOriginTrackingDepth(tstate, depth);
     Py_RETURN_NONE;
 }