mirror of
https://github.com/python/cpython.git
synced 2025-11-14 15:56:48 +00:00
gh-128360: Add _Py_AssertHoldsTstate as assertion for holding a thread state (#128361)
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
This commit is contained in:
parent
c6b570e5e3
commit
4d0a6595a0
11 changed files with 48 additions and 32 deletions
|
|
@ -300,6 +300,19 @@ PyAPI_FUNC(const PyConfig*) _Py_GetConfig(void);
|
|||
// See also PyInterpreterState_Get() and _PyInterpreterState_GET().
|
||||
extern PyInterpreterState* _PyGILState_GetInterpreterStateUnsafe(void);
|
||||
|
||||
#ifndef NDEBUG
|
||||
/* Modern equivalent of assert(PyGILState_Check()) */
|
||||
static inline void
|
||||
_Py_AssertHoldsTstateFunc(const char *func)
|
||||
{
|
||||
PyThreadState *tstate = _PyThreadState_GET();
|
||||
_Py_EnsureFuncTstateNotNULL(func, tstate);
|
||||
}
|
||||
#define _Py_AssertHoldsTstate() _Py_AssertHoldsTstateFunc(__func__)
|
||||
#else
|
||||
#define _Py_AssertHoldsTstate()
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue