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.
This commit is contained in:
Victor Stinner 2021-02-19 15:08:54 +01:00 committed by GitHub
parent acde3f1530
commit a486054b24
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 3 additions and 7 deletions

View File

@ -30,12 +30,6 @@ PyAPI_FUNC(void) PyErr_SetExcInfo(PyObject *, PyObject *, PyObject *);
macro is defined. */ macro is defined. */
PyAPI_FUNC(void) _Py_NO_RETURN Py_FatalError(const char *message); 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 */ /* Error testing and normalization */
PyAPI_FUNC(int) PyErr_GivenExceptionMatches(PyObject *, PyObject *); PyAPI_FUNC(int) PyErr_GivenExceptionMatches(PyObject *, PyObject *);
PyAPI_FUNC(int) PyErr_ExceptionMatches(PyObject *); PyAPI_FUNC(int) PyErr_ExceptionMatches(PyObject *);

View File

@ -0,0 +1,2 @@
Remove the private ``_PyErr_OCCURRED()`` macro: use the public
:c:func:`PyErr_Occurred` function instead.

View File

@ -2750,7 +2750,7 @@ main_loop:
(PyDictObject *)f->f_builtins, (PyDictObject *)f->f_builtins,
name); name);
if (v == NULL) { if (v == NULL) {
if (!_PyErr_OCCURRED()) { if (!_PyErr_Occurred(tstate)) {
/* _PyDict_LoadGlobal() returns NULL without raising /* _PyDict_LoadGlobal() returns NULL without raising
* an exception if the key doesn't exist */ * an exception if the key doesn't exist */
format_exc_check_arg(tstate, PyExc_NameError, format_exc_check_arg(tstate, PyExc_NameError,