| 
									
										
										
										
											1997-05-05 20:56:21 +00:00
										 |  |  | /* Thread and interpreter state structures and their interfaces */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-08 23:37:28 +00:00
										 |  |  | #ifndef Py_PYSTATE_H
 | 
					
						
							|  |  |  | #define Py_PYSTATE_H
 | 
					
						
							|  |  |  | #ifdef __cplusplus
 | 
					
						
							|  |  |  | extern "C" { | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-07 11:16:41 -07:00
										 |  |  | /* This limitation is for performance and simplicity. If needed it can be
 | 
					
						
							|  |  |  | removed (with effort). */ | 
					
						
							|  |  |  | #define MAX_CO_EXTRA_USERS 255
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-23 11:35:52 -07:00
										 |  |  | PyAPI_FUNC(PyInterpreterState *) PyInterpreterState_New(void); | 
					
						
							|  |  |  | PyAPI_FUNC(void) PyInterpreterState_Clear(PyInterpreterState *); | 
					
						
							|  |  |  | PyAPI_FUNC(void) PyInterpreterState_Delete(PyInterpreterState *); | 
					
						
							| 
									
										
										
										
											2018-11-01 01:51:40 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-13 18:15:33 +01:00
										 |  |  | #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03090000
 | 
					
						
							|  |  |  | /* New in 3.9 */ | 
					
						
							|  |  |  | /* Get the current interpreter state.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |    Issue a fatal error if there no current Python thread state or no current | 
					
						
							|  |  |  |    interpreter. It cannot return NULL. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |    The caller must hold the GIL. */ | 
					
						
							|  |  |  | PyAPI_FUNC(PyInterpreterState *) PyInterpreterState_Get(void); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-15 17:47:43 -06:00
										 |  |  | #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03080000
 | 
					
						
							|  |  |  | /* New in 3.8 */ | 
					
						
							|  |  |  | PyAPI_FUNC(PyObject *) PyInterpreterState_GetDict(PyInterpreterState *); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-22 19:46:40 -07:00
										 |  |  | #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03070000
 | 
					
						
							|  |  |  | /* New in 3.7 */ | 
					
						
							| 
									
										
										
										
											2019-02-23 11:35:52 -07:00
										 |  |  | PyAPI_FUNC(int64_t) PyInterpreterState_GetID(PyInterpreterState *); | 
					
						
							| 
									
										
										
										
											2017-05-22 19:46:40 -07:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2012-06-22 12:20:55 +02:00
										 |  |  | #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000
 | 
					
						
							| 
									
										
										
										
											2019-03-15 17:47:43 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* State unique per thread */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-22 12:20:55 +02:00
										 |  |  | /* New in 3.3 */ | 
					
						
							| 
									
										
										
										
											2022-02-24 17:51:59 +01:00
										 |  |  | PyAPI_FUNC(int) PyState_AddModule(PyObject*, PyModuleDef*); | 
					
						
							|  |  |  | PyAPI_FUNC(int) PyState_RemoveModule(PyModuleDef*); | 
					
						
							| 
									
										
										
										
											2012-06-22 12:20:55 +02:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2022-02-24 17:51:59 +01:00
										 |  |  | PyAPI_FUNC(PyObject*) PyState_FindModule(PyModuleDef*); | 
					
						
							| 
									
										
										
										
											1997-05-05 20:56:21 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-23 11:35:52 -07:00
										 |  |  | PyAPI_FUNC(PyThreadState *) PyThreadState_New(PyInterpreterState *); | 
					
						
							|  |  |  | PyAPI_FUNC(void) PyThreadState_Clear(PyThreadState *); | 
					
						
							|  |  |  | PyAPI_FUNC(void) PyThreadState_Delete(PyThreadState *); | 
					
						
							| 
									
										
										
										
											1997-05-05 20:56:21 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-01 01:51:40 +01:00
										 |  |  | /* Get the current thread state.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |    When the current thread state is NULL, this issues a fatal error (so that | 
					
						
							|  |  |  |    the caller needn't check for NULL). | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |    The caller must hold the GIL. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-03 18:53:51 +02:00
										 |  |  |    See also PyThreadState_GetUnchecked() and _PyThreadState_GET(). */ | 
					
						
							| 
									
										
										
										
											2019-02-23 11:35:52 -07:00
										 |  |  | PyAPI_FUNC(PyThreadState *) PyThreadState_Get(void); | 
					
						
							| 
									
										
										
										
											2016-01-20 11:12:38 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-13 14:09:13 +02:00
										 |  |  | // Alias to PyThreadState_Get()
 | 
					
						
							| 
									
										
										
										
											2018-11-01 01:51:40 +01:00
										 |  |  | #define PyThreadState_GET() PyThreadState_Get()
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-23 11:35:52 -07:00
										 |  |  | PyAPI_FUNC(PyThreadState *) PyThreadState_Swap(PyThreadState *); | 
					
						
							| 
									
										
										
										
											2002-08-12 07:21:58 +00:00
										 |  |  | PyAPI_FUNC(PyObject *) PyThreadState_GetDict(void); | 
					
						
							| 
									
										
										
										
											2017-03-23 15:48:39 +02:00
										 |  |  | PyAPI_FUNC(int) PyThreadState_SetAsyncExc(unsigned long, PyObject *); | 
					
						
							| 
									
										
										
										
											1997-05-05 20:56:21 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-13 23:38:08 +01:00
										 |  |  | #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03090000
 | 
					
						
							|  |  |  | /* New in 3.9 */ | 
					
						
							| 
									
										
										
										
											2020-03-20 15:51:45 +01:00
										 |  |  | PyAPI_FUNC(PyInterpreterState*) PyThreadState_GetInterpreter(PyThreadState *tstate); | 
					
						
							| 
									
										
										
										
											2020-04-28 16:32:48 +02:00
										 |  |  | PyAPI_FUNC(PyFrameObject*) PyThreadState_GetFrame(PyThreadState *tstate); | 
					
						
							| 
									
										
										
										
											2020-03-25 21:23:53 +01:00
										 |  |  | PyAPI_FUNC(uint64_t) PyThreadState_GetID(PyThreadState *tstate); | 
					
						
							| 
									
										
										
										
											2020-03-13 23:38:08 +01:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-03-29 02:24:26 +00:00
										 |  |  | typedef | 
					
						
							| 
									
										
										
										
											2003-04-19 15:41:53 +00:00
										 |  |  |     enum {PyGILState_LOCKED, PyGILState_UNLOCKED} | 
					
						
							|  |  |  |         PyGILState_STATE; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-26 23:34:58 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-19 15:41:53 +00:00
										 |  |  | /* Ensure that the current thread is ready to call the Python
 | 
					
						
							|  |  |  |    C API, regardless of the current state of Python, or of its | 
					
						
							|  |  |  |    thread lock.  This may be called as many times as desired | 
					
						
							| 
									
										
										
										
											2004-03-29 02:24:26 +00:00
										 |  |  |    by a thread so long as each call is matched with a call to | 
					
						
							|  |  |  |    PyGILState_Release().  In general, other thread-state APIs may | 
					
						
							|  |  |  |    be used between _Ensure() and _Release() calls, so long as the | 
					
						
							| 
									
										
										
										
											2003-04-19 15:41:53 +00:00
										 |  |  |    thread-state is restored to its previous state before the Release(). | 
					
						
							|  |  |  |    For example, normal use of the Py_BEGIN_ALLOW_THREADS/ | 
					
						
							|  |  |  |    Py_END_ALLOW_THREADS macros are acceptable. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |    The return value is an opaque "handle" to the thread state when | 
					
						
							| 
									
										
										
										
											2004-03-13 20:45:47 +00:00
										 |  |  |    PyGILState_Ensure() was called, and must be passed to | 
					
						
							| 
									
										
										
										
											2003-04-19 15:41:53 +00:00
										 |  |  |    PyGILState_Release() to ensure Python is left in the same state. Even | 
					
						
							| 
									
										
										
										
											2004-03-29 02:24:26 +00:00
										 |  |  |    though recursive calls are allowed, these handles can *not* be shared - | 
					
						
							|  |  |  |    each unique call to PyGILState_Ensure must save the handle for its | 
					
						
							| 
									
										
										
										
											2003-04-19 15:41:53 +00:00
										 |  |  |    call to PyGILState_Release. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |    When the function returns, the current thread will hold the GIL. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |    Failure is a fatal error. | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | PyAPI_FUNC(PyGILState_STATE) PyGILState_Ensure(void); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Release any resources previously acquired.  After this call, Python's
 | 
					
						
							|  |  |  |    state will be the same as it was prior to the corresponding | 
					
						
							| 
									
										
										
										
											2004-03-29 02:24:26 +00:00
										 |  |  |    PyGILState_Ensure() call (but generally this state will be unknown to | 
					
						
							| 
									
										
										
										
											2003-04-19 15:41:53 +00:00
										 |  |  |    the caller, hence the use of the GILState API.) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-03-29 02:24:26 +00:00
										 |  |  |    Every call to PyGILState_Ensure must be matched by a call to | 
					
						
							| 
									
										
										
										
											2003-04-19 15:41:53 +00:00
										 |  |  |    PyGILState_Release on the same thread. | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | PyAPI_FUNC(void) PyGILState_Release(PyGILState_STATE); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Helper/diagnostic function - get the current thread state for
 | 
					
						
							| 
									
										
										
										
											2004-03-29 02:24:26 +00:00
										 |  |  |    this thread.  May return NULL if no GILState API has been used | 
					
						
							| 
									
										
										
										
											2011-08-08 00:16:54 +02:00
										 |  |  |    on the current thread.  Note that the main thread always has such a | 
					
						
							| 
									
										
										
										
											2004-03-29 02:24:26 +00:00
										 |  |  |    thread-state, even if no auto-thread-state call has been made | 
					
						
							| 
									
										
										
										
											2003-04-19 15:41:53 +00:00
										 |  |  |    on the main thread. | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2019-02-23 11:35:52 -07:00
										 |  |  | PyAPI_FUNC(PyThreadState *) PyGILState_GetThisThreadState(void); | 
					
						
							| 
									
										
										
										
											2003-04-19 15:41:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-16 22:45:24 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-03 20:14:31 +00:00
										 |  |  | #ifndef Py_LIMITED_API
 | 
					
						
							| 
									
										
										
										
											2018-11-27 00:20:00 +01:00
										 |  |  | #  define Py_CPYTHON_PYSTATE_H
 | 
					
						
							| 
									
										
										
										
											2021-10-15 01:50:04 +02:00
										 |  |  | #  include "cpython/pystate.h"
 | 
					
						
							| 
									
										
										
										
											2018-11-27 00:20:00 +01:00
										 |  |  | #  undef Py_CPYTHON_PYSTATE_H
 | 
					
						
							| 
									
										
										
										
											2010-12-03 20:14:31 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2003-02-19 15:53:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-05-05 20:56:21 +00:00
										 |  |  | #ifdef __cplusplus
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | #endif /* !Py_PYSTATE_H */
 |