mirror of
https://github.com/johndoe6345789/typthon.git
synced 2026-04-24 13:45:05 +00:00
Massive automated renaming of all Py_/PyObject/etc. prefixes to Ty_/TyObject/etc. This includes: - All public API types (TyObject, TyTypeObject, etc.) - All public API functions (Ty_Initialize, Ty_BuildValue, etc.) - All internal API (_Ty_ prefixes) - Reference counting macros (Ty_INCREF, Ty_DECREF, etc.) - Type flags (Ty_TPFLAGS_*) - Debug flags (Ty_DEBUG, Ty_TRACE_REFS, etc.) - All object type APIs (TyList_, TyDict_, TyUnicode_, etc.) This changes over 60,000 occurrences across 1000+ files. Co-authored-by: johndoe6345789 <224850594+johndoe6345789@users.noreply.github.com>
133 lines
4.5 KiB
C
133 lines
4.5 KiB
C
/* Thread and interpreter state structures and their interfaces */
|
|
|
|
|
|
#ifndef Ty_PYSTATE_H
|
|
#define Ty_PYSTATE_H
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
/* This limitation is for performance and simplicity. If needed it can be
|
|
removed (with effort). */
|
|
#define MAX_CO_EXTRA_USERS 255
|
|
|
|
PyAPI_FUNC(PyInterpreterState *) TyInterpreterState_New(void);
|
|
PyAPI_FUNC(void) TyInterpreterState_Clear(PyInterpreterState *);
|
|
PyAPI_FUNC(void) TyInterpreterState_Delete(PyInterpreterState *);
|
|
|
|
#if !defined(Ty_LIMITED_API) || Ty_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 *) TyInterpreterState_Get(void);
|
|
#endif
|
|
|
|
#if !defined(Ty_LIMITED_API) || Ty_LIMITED_API+0 >= 0x03080000
|
|
/* New in 3.8 */
|
|
PyAPI_FUNC(TyObject *) TyInterpreterState_GetDict(PyInterpreterState *);
|
|
#endif
|
|
|
|
#if !defined(Ty_LIMITED_API) || Ty_LIMITED_API+0 >= 0x03070000
|
|
/* New in 3.7 */
|
|
PyAPI_FUNC(int64_t) TyInterpreterState_GetID(PyInterpreterState *);
|
|
#endif
|
|
#if !defined(Ty_LIMITED_API) || Ty_LIMITED_API+0 >= 0x03030000
|
|
|
|
/* State unique per thread */
|
|
|
|
/* New in 3.3 */
|
|
PyAPI_FUNC(int) PyState_AddModule(TyObject*, TyModuleDef*);
|
|
PyAPI_FUNC(int) PyState_RemoveModule(TyModuleDef*);
|
|
#endif
|
|
PyAPI_FUNC(TyObject*) PyState_FindModule(TyModuleDef*);
|
|
|
|
PyAPI_FUNC(PyThreadState *) TyThreadState_New(PyInterpreterState *);
|
|
PyAPI_FUNC(void) TyThreadState_Clear(PyThreadState *);
|
|
PyAPI_FUNC(void) TyThreadState_Delete(PyThreadState *);
|
|
|
|
/* 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.
|
|
|
|
See also TyThreadState_GetUnchecked() and _TyThreadState_GET(). */
|
|
PyAPI_FUNC(PyThreadState *) TyThreadState_Get(void);
|
|
|
|
// Alias to TyThreadState_Get()
|
|
#define TyThreadState_GET() TyThreadState_Get()
|
|
|
|
PyAPI_FUNC(PyThreadState *) TyThreadState_Swap(PyThreadState *);
|
|
PyAPI_FUNC(TyObject *) TyThreadState_GetDict(void);
|
|
PyAPI_FUNC(int) TyThreadState_SetAsyncExc(unsigned long, TyObject *);
|
|
|
|
#if !defined(Ty_LIMITED_API) || Ty_LIMITED_API+0 >= 0x03090000
|
|
/* New in 3.9 */
|
|
PyAPI_FUNC(PyInterpreterState*) TyThreadState_GetInterpreter(PyThreadState *tstate);
|
|
PyAPI_FUNC(PyFrameObject*) TyThreadState_GetFrame(PyThreadState *tstate);
|
|
PyAPI_FUNC(uint64_t) TyThreadState_GetID(PyThreadState *tstate);
|
|
#endif
|
|
|
|
typedef
|
|
enum {TyGILState_LOCKED, TyGILState_UNLOCKED}
|
|
TyGILState_STATE;
|
|
|
|
|
|
/* 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
|
|
by a thread so long as each call is matched with a call to
|
|
TyGILState_Release(). In general, other thread-state APIs may
|
|
be used between _Ensure() and _Release() calls, so long as the
|
|
thread-state is restored to its previous state before the Release().
|
|
For example, normal use of the Ty_BEGIN_ALLOW_THREADS/
|
|
Ty_END_ALLOW_THREADS macros are acceptable.
|
|
|
|
The return value is an opaque "handle" to the thread state when
|
|
TyGILState_Ensure() was called, and must be passed to
|
|
TyGILState_Release() to ensure Python is left in the same state. Even
|
|
though recursive calls are allowed, these handles can *not* be shared -
|
|
each unique call to TyGILState_Ensure must save the handle for its
|
|
call to TyGILState_Release.
|
|
|
|
When the function returns, the current thread will hold the GIL.
|
|
|
|
Failure is a fatal error.
|
|
*/
|
|
PyAPI_FUNC(TyGILState_STATE) TyGILState_Ensure(void);
|
|
|
|
/* Release any resources previously acquired. After this call, Python's
|
|
state will be the same as it was prior to the corresponding
|
|
TyGILState_Ensure() call (but generally this state will be unknown to
|
|
the caller, hence the use of the GILState API.)
|
|
|
|
Every call to TyGILState_Ensure must be matched by a call to
|
|
TyGILState_Release on the same thread.
|
|
*/
|
|
PyAPI_FUNC(void) TyGILState_Release(TyGILState_STATE);
|
|
|
|
/* Helper/diagnostic function - get the current thread state for
|
|
this thread. May return NULL if no GILState API has been used
|
|
on the current thread. Note that the main thread always has such a
|
|
thread-state, even if no auto-thread-state call has been made
|
|
on the main thread.
|
|
*/
|
|
PyAPI_FUNC(PyThreadState *) TyGILState_GetThisThreadState(void);
|
|
|
|
|
|
#ifndef Ty_LIMITED_API
|
|
# define Ty_CPYTHON_PYSTATE_H
|
|
# include "cpython/pystate.h"
|
|
# undef Ty_CPYTHON_PYSTATE_H
|
|
#endif
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
#endif /* !Ty_PYSTATE_H */
|