New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[C API] Remove _PyErr_OCCURRED() macro #87436
Comments
The private _PyErr_OCCURRED() function was introduced to optimize Objects/setobject.c: commit 5ba0cbe
But the usage of the macro was removed one month later: commit 9bda1d6
The macro is currently defined as: #if defined(Py_DEBUG) || defined(Py_LIMITED_API)
#define _PyErr_OCCURRED() PyErr_Occurred()
#else
#define _PyErr_OCCURRED() (PyThreadState_GET()->curexc_type)
#endif IMO the new _PyErr_Occurred(tstate) internal function is a more reliable way (don't depend on Py_DEBUG and Py_LIMITED_API) to ensure that the code uses the most efficient way to check if an exception was raised. I cannot find "_PyErr_OCCURRED" in the PyPI top 4000 projects, I checked with INADA-san's tool: So removing _PyErr_OCCURRED() is unlikely to break PyPI top 4000 projects. If it breaks a third party project: well, we don't provide any backward compatibility warranty on the *private* C API. |
But this way, this macro access directly the PyThreadState.curexc_type member which goes against the bpo-39947 "[C API] Make the PyThreadState structure opaque (move it to the internal C API)" issue. |
_PyErr_Occurred() is defined as: static inline PyObject* _PyErr_Occurred(PyThreadState *tstate)
{
assert(tstate != NULL);
return tstate->curexc_type;
} |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: