|
1 | 1 | #include "Python.h" |
2 | 2 | #include "pycore_fileutils.h" // fileutils definitions |
3 | 3 | #include "pycore_runtime.h" // _PyRuntime |
| 4 | +#include "pycore_pystate.h" // _Py_AssertHoldsTstate() |
4 | 5 | #include "osdefs.h" // SEP |
5 | 6 |
|
6 | 7 | #include <stdlib.h> // mbstowcs() |
@@ -1311,7 +1312,7 @@ _Py_fstat(int fd, struct _Py_stat_struct *status) |
1311 | 1312 | { |
1312 | 1313 | int res; |
1313 | 1314 |
|
1314 | | - assert(PyGILState_Check()); |
| 1315 | + _Py_AssertHoldsTstate(); |
1315 | 1316 |
|
1316 | 1317 | Py_BEGIN_ALLOW_THREADS |
1317 | 1318 | res = _Py_fstat_noraise(fd, status); |
@@ -1691,7 +1692,7 @@ int |
1691 | 1692 | _Py_open(const char *pathname, int flags) |
1692 | 1693 | { |
1693 | 1694 | /* _Py_open() must be called with the GIL held. */ |
1694 | | - assert(PyGILState_Check()); |
| 1695 | + _Py_AssertHoldsTstate(); |
1695 | 1696 | return _Py_open_impl(pathname, flags, 1); |
1696 | 1697 | } |
1697 | 1698 |
|
@@ -1766,7 +1767,7 @@ _Py_wfopen(const wchar_t *path, const wchar_t *mode) |
1766 | 1767 | FILE* |
1767 | 1768 | Py_fopen(PyObject *path, const char *mode) |
1768 | 1769 | { |
1769 | | - assert(PyGILState_Check()); |
| 1770 | + _Py_AssertHoldsTstate(); |
1770 | 1771 |
|
1771 | 1772 | if (PySys_Audit("open", "Osi", path, mode, 0) < 0) { |
1772 | 1773 | return NULL; |
@@ -1881,7 +1882,7 @@ _Py_read(int fd, void *buf, size_t count) |
1881 | 1882 | int err; |
1882 | 1883 | int async_err = 0; |
1883 | 1884 |
|
1884 | | - assert(PyGILState_Check()); |
| 1885 | + _Py_AssertHoldsTstate(); |
1885 | 1886 |
|
1886 | 1887 | /* _Py_read() must not be called with an exception set, otherwise the |
1887 | 1888 | * caller may think that read() was interrupted by a signal and the signal |
@@ -2047,7 +2048,7 @@ _Py_write_impl(int fd, const void *buf, size_t count, int gil_held) |
2047 | 2048 | Py_ssize_t |
2048 | 2049 | _Py_write(int fd, const void *buf, size_t count) |
2049 | 2050 | { |
2050 | | - assert(PyGILState_Check()); |
| 2051 | + _Py_AssertHoldsTstate(); |
2051 | 2052 |
|
2052 | 2053 | /* _Py_write() must not be called with an exception set, otherwise the |
2053 | 2054 | * caller may think that write() was interrupted by a signal and the signal |
@@ -2675,7 +2676,7 @@ _Py_dup(int fd) |
2675 | 2676 | HANDLE handle; |
2676 | 2677 | #endif |
2677 | 2678 |
|
2678 | | - assert(PyGILState_Check()); |
| 2679 | + _Py_AssertHoldsTstate(); |
2679 | 2680 |
|
2680 | 2681 | #ifdef MS_WINDOWS |
2681 | 2682 | handle = _Py_get_osfhandle(fd); |
|
0 commit comments