own a reference to the return value, so you do not need to :c:func:`Py_DECREF`
it.
+ The caller must hold the GIL.
+
.. note::
Do not compare the return value to a specific exception; use
static inline PyObject* _PyErr_Occurred(PyThreadState *tstate)
{
- return tstate == NULL ? NULL : tstate->curexc_type;
+ assert(tstate != NULL);
+ return tstate->curexc_type;
}
_Py_CheckFunctionResult(PyThreadState *tstate, PyObject *callable,
PyObject *result, const char *where)
{
- int err_occurred = (_PyErr_Occurred(tstate) != NULL);
-
assert((callable != NULL) ^ (where != NULL));
if (result == NULL) {
- if (!err_occurred) {
+ if (!_PyErr_Occurred(tstate)) {
if (callable)
_PyErr_Format(tstate, PyExc_SystemError,
"%R returned NULL without setting an error",
}
}
else {
- if (err_occurred) {
+ if (_PyErr_Occurred(tstate)) {
Py_DECREF(result);
if (callable) {
return data;
}
-static void
+static inline void
_PyMem_DebugCheckGIL(void)
{
- if (!PyGILState_Check())
+ if (!PyGILState_Check()) {
Py_FatalError("Python memory allocator called "
"without holding the GIL");
+ }
}
static void *
PyObject* _Py_HOT_FUNCTION
PyErr_Occurred(void)
{
+ /* The caller must hold the GIL. */
+ assert(PyGILState_Check());
+
PyThreadState *tstate = _PyThreadState_GET();
return _PyErr_Occurred(tstate);
}