[Python-checkins] bpo-43270: Remove private _PyErr_OCCURRED() macro (GH-24579)

vstinner webhook-mailer at python.org
Fri Feb 19 09:08:57 EST 2021


https://github.com/python/cpython/commit/a486054b24658fa623e030ddd4cc0cbfcac54ab0
commit: a486054b24658fa623e030ddd4cc0cbfcac54ab0
branch: master
author: Victor Stinner <vstinner at python.org>
committer: vstinner <vstinner at python.org>
date: 2021-02-19T15:08:54+01:00
summary:

bpo-43270: Remove private _PyErr_OCCURRED() macro (GH-24579)

Remove the private _PyErr_OCCURRED() macro: use the public
PyErr_Occurred() function instead.

CPython internals must use the internal _PyErr_Occurred(tstate)
function instead: it is the most efficient way to check if an
exception was raised.

files:
A Misc/NEWS.d/next/C API/2021-02-19-14-28-26.bpo-43270.UKx4XN.rst
M Include/pyerrors.h
M Python/ceval.c

diff --git a/Include/pyerrors.h b/Include/pyerrors.h
index 979a26ba68a03..692d67175741e 100644
--- a/Include/pyerrors.h
+++ b/Include/pyerrors.h
@@ -30,12 +30,6 @@ PyAPI_FUNC(void) PyErr_SetExcInfo(PyObject *, PyObject *, PyObject *);
    macro is defined. */
 PyAPI_FUNC(void) _Py_NO_RETURN Py_FatalError(const char *message);
 
-#if defined(Py_DEBUG) || defined(Py_LIMITED_API)
-#define _PyErr_OCCURRED() PyErr_Occurred()
-#else
-#define _PyErr_OCCURRED() (PyThreadState_GET()->curexc_type)
-#endif
-
 /* Error testing and normalization */
 PyAPI_FUNC(int) PyErr_GivenExceptionMatches(PyObject *, PyObject *);
 PyAPI_FUNC(int) PyErr_ExceptionMatches(PyObject *);
diff --git a/Misc/NEWS.d/next/C API/2021-02-19-14-28-26.bpo-43270.UKx4XN.rst b/Misc/NEWS.d/next/C API/2021-02-19-14-28-26.bpo-43270.UKx4XN.rst
new file mode 100644
index 0000000000000..ab8c9772cb0f9
--- /dev/null
+++ b/Misc/NEWS.d/next/C API/2021-02-19-14-28-26.bpo-43270.UKx4XN.rst	
@@ -0,0 +1,2 @@
+Remove the private ``_PyErr_OCCURRED()`` macro: use the public
+:c:func:`PyErr_Occurred` function instead.
diff --git a/Python/ceval.c b/Python/ceval.c
index 81a21c9a0f534..4771a516a96e8 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -2750,7 +2750,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, PyFrameObject *f, int throwflag)
                                        (PyDictObject *)f->f_builtins,
                                        name);
                 if (v == NULL) {
-                    if (!_PyErr_OCCURRED()) {
+                    if (!_PyErr_Occurred(tstate)) {
                         /* _PyDict_LoadGlobal() returns NULL without raising
                          * an exception if the key doesn't exist */
                         format_exc_check_arg(tstate, PyExc_NameError,



More information about the Python-checkins mailing list