Add more checks on the GIL

Issue #10915, #15751, #26558:

* PyGILState_Check() now returns 1 (success) before the creation of the GIL and
  after the destruction of the GIL. It allows to use the function early in
  Python initialization and late in Python finalization.
* Add a flag to disable PyGILState_Check(). Disable PyGILState_Check() when
  Py_NewInterpreter() is called
* Add assert(PyGILState_Check()) to: _Py_dup(), _Py_fstat(), _Py_read()
  and _Py_write()
This commit is contained in:
Victor Stinner 2016-03-14 22:07:55 +01:00
parent 08572f68a9
commit 8a1be61849
5 changed files with 52 additions and 5 deletions

View file

@ -247,6 +247,10 @@ PyAPI_FUNC(PyThreadState *) PyGILState_GetThisThreadState(void);
* currently holds the GIL, 0 otherwise
*/
#ifndef Py_LIMITED_API
/* Issue #26558: Flag to disable PyGILState_Check().
If set, PyGILState_Check() always return 1. */
PyAPI_DATA(int) _PyGILState_check_enabled;
PyAPI_FUNC(int) PyGILState_Check(void);
#endif