2020-04-13 12:47:17 +02:00
|
|
|
#ifndef Py_INTERNAL_INTERP_H
|
|
|
|
|
#define Py_INTERNAL_INTERP_H
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifndef Py_BUILD_CORE
|
|
|
|
|
# error "this header requires Py_BUILD_CORE define"
|
|
|
|
|
#endif
|
|
|
|
|
|
2025-03-20 12:35:23 +01:00
|
|
|
#include "pycore_interp_structs.h" // PyInterpreterState
|
2020-04-13 12:47:17 +02:00
|
|
|
|
2022-11-15 09:45:11 -07:00
|
|
|
|
2020-04-13 12:47:17 +02:00
|
|
|
/* interpreter state */
|
|
|
|
|
|
2024-04-10 18:37:01 -06:00
|
|
|
#define _PyInterpreterState_WHENCE_NOTSET -1
|
|
|
|
|
#define _PyInterpreterState_WHENCE_UNKNOWN 0
|
|
|
|
|
#define _PyInterpreterState_WHENCE_RUNTIME 1
|
|
|
|
|
#define _PyInterpreterState_WHENCE_LEGACY_CAPI 2
|
|
|
|
|
#define _PyInterpreterState_WHENCE_CAPI 3
|
|
|
|
|
#define _PyInterpreterState_WHENCE_XI 4
|
2024-04-11 17:23:25 -06:00
|
|
|
#define _PyInterpreterState_WHENCE_STDLIB 5
|
|
|
|
|
#define _PyInterpreterState_WHENCE_MAX 5
|
2020-04-13 12:47:17 +02:00
|
|
|
|
2022-01-12 16:28:46 -07:00
|
|
|
|
|
|
|
|
/* other API */
|
|
|
|
|
|
2020-10-30 22:51:02 +01:00
|
|
|
extern void _PyInterpreterState_Clear(PyThreadState *tstate);
|
2020-04-13 12:47:17 +02:00
|
|
|
|
2023-05-15 13:59:26 -06:00
|
|
|
static inline PyThreadState*
|
|
|
|
|
_PyInterpreterState_GetFinalizing(PyInterpreterState *interp) {
|
2023-10-10 23:17:08 +09:00
|
|
|
return (PyThreadState*)_Py_atomic_load_ptr_relaxed(&interp->_finalizing);
|
2023-05-15 13:59:26 -06:00
|
|
|
}
|
|
|
|
|
|
2023-09-27 13:41:06 -06:00
|
|
|
static inline unsigned long
|
|
|
|
|
_PyInterpreterState_GetFinalizingID(PyInterpreterState *interp) {
|
|
|
|
|
return _Py_atomic_load_ulong_relaxed(&interp->_finalizing_id);
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-15 13:59:26 -06:00
|
|
|
static inline void
|
|
|
|
|
_PyInterpreterState_SetFinalizing(PyInterpreterState *interp, PyThreadState *tstate) {
|
2023-10-10 23:17:08 +09:00
|
|
|
_Py_atomic_store_ptr_relaxed(&interp->_finalizing, tstate);
|
2023-09-27 13:41:06 -06:00
|
|
|
if (tstate == NULL) {
|
|
|
|
|
_Py_atomic_store_ulong_relaxed(&interp->_finalizing_id, 0);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// XXX Re-enable this assert once gh-109860 is fixed.
|
|
|
|
|
//assert(tstate->thread_id == PyThread_get_thread_ident());
|
|
|
|
|
_Py_atomic_store_ulong_relaxed(&interp->_finalizing_id,
|
|
|
|
|
tstate->thread_id);
|
|
|
|
|
}
|
2023-05-15 13:59:26 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-03-21 11:15:02 -06:00
|
|
|
// Exports for the _testinternalcapi module.
|
|
|
|
|
PyAPI_FUNC(int64_t) _PyInterpreterState_ObjectToID(PyObject *);
|
2023-10-09 07:39:51 -06:00
|
|
|
PyAPI_FUNC(PyInterpreterState *) _PyInterpreterState_LookUpID(int64_t);
|
2024-03-21 09:56:12 -06:00
|
|
|
PyAPI_FUNC(PyInterpreterState *) _PyInterpreterState_LookUpIDObject(PyObject *);
|
2024-10-12 12:40:34 +05:30
|
|
|
PyAPI_FUNC(void) _PyInterpreterState_IDIncref(PyInterpreterState *);
|
2023-12-12 08:24:31 -07:00
|
|
|
PyAPI_FUNC(void) _PyInterpreterState_IDDecref(PyInterpreterState *);
|
2020-04-13 12:47:17 +02:00
|
|
|
|
2024-04-11 17:23:25 -06:00
|
|
|
PyAPI_FUNC(int) _PyInterpreterState_IsReady(PyInterpreterState *interp);
|
|
|
|
|
|
2024-04-10 18:37:01 -06:00
|
|
|
PyAPI_FUNC(long) _PyInterpreterState_GetWhence(PyInterpreterState *interp);
|
|
|
|
|
extern void _PyInterpreterState_SetWhence(
|
|
|
|
|
PyInterpreterState *interp,
|
|
|
|
|
long whence);
|
|
|
|
|
|
2023-07-04 18:55:45 +02:00
|
|
|
/*
|
|
|
|
|
Runtime Feature Flags
|
|
|
|
|
|
|
|
|
|
Each flag indicate whether or not a specific runtime feature
|
|
|
|
|
is available in a given context. For example, forking the process
|
|
|
|
|
might not be allowed in the current interpreter (i.e. os.fork() would fail).
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* Set if the interpreter share obmalloc runtime state
|
|
|
|
|
with the main interpreter. */
|
|
|
|
|
#define Py_RTFLAGS_USE_MAIN_OBMALLOC (1UL << 5)
|
|
|
|
|
|
|
|
|
|
/* Set if import should check a module for subinterpreter support. */
|
|
|
|
|
#define Py_RTFLAGS_MULTI_INTERP_EXTENSIONS (1UL << 8)
|
|
|
|
|
|
|
|
|
|
/* Set if threads are allowed. */
|
|
|
|
|
#define Py_RTFLAGS_THREADS (1UL << 10)
|
|
|
|
|
|
|
|
|
|
/* Set if daemon threads are allowed. */
|
|
|
|
|
#define Py_RTFLAGS_DAEMON_THREADS (1UL << 11)
|
|
|
|
|
|
|
|
|
|
/* Set if os.fork() is allowed. */
|
|
|
|
|
#define Py_RTFLAGS_FORK (1UL << 15)
|
|
|
|
|
|
|
|
|
|
/* Set if os.exec*() is allowed. */
|
|
|
|
|
#define Py_RTFLAGS_EXEC (1UL << 16)
|
|
|
|
|
|
|
|
|
|
extern int _PyInterpreterState_HasFeature(PyInterpreterState *interp,
|
|
|
|
|
unsigned long feature);
|
|
|
|
|
|
2023-09-01 12:43:30 +02:00
|
|
|
PyAPI_FUNC(PyStatus) _PyInterpreterState_New(
|
|
|
|
|
PyThreadState *tstate,
|
|
|
|
|
PyInterpreterState **pinterp);
|
|
|
|
|
|
2025-03-19 17:33:24 +01:00
|
|
|
extern const PyConfig* _PyInterpreterState_GetConfig(
|
|
|
|
|
PyInterpreterState *interp);
|
|
|
|
|
|
2020-04-13 12:47:17 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
#endif /* !Py_INTERNAL_INTERP_H */
|