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:
Peter Bierma 2025-01-20 06:34:35 -05:00 committed by GitHub
parent c6b570e5e3
commit 4d0a6595a0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 48 additions and 32 deletions

View file

@ -110,6 +110,7 @@ Local naming conventions:
#include "pycore_fileutils.h" // _Py_set_inheritable()
#include "pycore_moduleobject.h" // _PyModule_GetState
#include "pycore_time.h" // _PyTime_AsMilliseconds()
#include "pycore_pystate.h" // _Py_AssertHoldsTstate()
#include "pycore_pyatomic_ft_wrappers.h"
#ifdef _Py_MEMORY_SANITIZER
@ -822,8 +823,8 @@ internal_select(PySocketSockObject *s, int writing, PyTime_t interval,
struct timeval tv, *tvp;
#endif
/* must be called with the GIL held */
assert(PyGILState_Check());
/* must be called with a thread state */
_Py_AssertHoldsTstate();
/* Error condition is for output only */
assert(!(connect && !writing));
@ -936,8 +937,8 @@ sock_call_ex(PySocketSockObject *s,
int deadline_initialized = 0;
int res;
/* sock_call() must be called with the GIL held. */
assert(PyGILState_Check());
/* sock_call() must be called with a thread state. */
_Py_AssertHoldsTstate();
/* outer loop to retry select() when select() is interrupted by a signal
or to retry select()+sock_func() on false positive (see above) */