diff options
author | Peter Bierma <zintensitydev@gmail.com> | 2025-01-20 06:34:35 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-01-20 17:04:35 +0530 |
commit | 4d0a6595a06c554c57ebd90ee64ff4c2bec239b8 (patch) | |
tree | a44951c47b86cbc327cdd5e1a588b467dc758a36 /Python/pytime.c | |
parent | c6b570e5e3b214d2038645c5fa7806e0fb3f7dcd (diff) | |
download | cpython-4d0a6595a06c554c57ebd90ee64ff4c2bec239b8.tar.gz cpython-4d0a6595a06c554c57ebd90ee64ff4c2bec239b8.zip |
gh-128360: Add `_Py_AssertHoldsTstate` as assertion for holding a thread state (#128361)
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
Diffstat (limited to 'Python/pytime.c')
-rw-r--r-- | Python/pytime.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/Python/pytime.c b/Python/pytime.c index 2b37cd991ef..c039fc98ce4 100644 --- a/Python/pytime.c +++ b/Python/pytime.c @@ -1,5 +1,6 @@ #include "Python.h" #include "pycore_time.h" // PyTime_t +#include "pycore_pystate.h" // _Py_AssertHoldsTstate() #include <time.h> // gmtime_r() #ifdef HAVE_SYS_TIME_H @@ -897,14 +898,14 @@ _PyTime_AsTimespec(PyTime_t t, struct timespec *ts) #endif -// N.B. If raise_exc=0, this may be called without the GIL. +// N.B. If raise_exc=0, this may be called without a thread state. static int py_get_system_clock(PyTime_t *tp, _Py_clock_info_t *info, int raise_exc) { assert(info == NULL || raise_exc); if (raise_exc) { - // raise_exc requires to hold the GIL - assert(PyGILState_Check()); + // raise_exc requires to hold a thread state + _Py_AssertHoldsTstate(); } #ifdef MS_WINDOWS @@ -1142,14 +1143,14 @@ py_mach_timebase_info(_PyTimeFraction *base, int raise_exc) #endif -// N.B. If raise_exc=0, this may be called without the GIL. +// N.B. If raise_exc=0, this may be called without a thread state. static int py_get_monotonic_clock(PyTime_t *tp, _Py_clock_info_t *info, int raise_exc) { assert(info == NULL || raise_exc); if (raise_exc) { - // raise_exc requires to hold the GIL - assert(PyGILState_Check()); + // raise_exc requires to hold a thread state + _Py_AssertHoldsTstate(); } #if defined(MS_WINDOWS) |