Debian Codegraph @

Include/internal/pycore_interp.h

raw
1 #ifndef Py_INTERNAL_INTERP_H
2 #define Py_INTERNAL_INTERP_H
3 #ifdef __cplusplus
4 extern "C" {
5 #endif
6
7 #ifndef Py_BUILD_CORE
8 # error "this header requires Py_BUILD_CORE define"
9 #endif
10
11 #include "pycore_interp_structs.h" // PyInterpreterState
12
13
14 /* interpreter state */
15
16 #define _PyInterpreterState_WHENCE_NOTSET -1
17 #define _PyInterpreterState_WHENCE_UNKNOWN 0
18 #define _PyInterpreterState_WHENCE_RUNTIME 1
19 #define _PyInterpreterState_WHENCE_LEGACY_CAPI 2
20 #define _PyInterpreterState_WHENCE_CAPI 3
21 #define _PyInterpreterState_WHENCE_XI 4
22 #define _PyInterpreterState_WHENCE_STDLIB 5
23 #define _PyInterpreterState_WHENCE_MAX 5
24
25
26 /* other API */
27
28 extern void _PyInterpreterState_Clear(PyThreadState *tstate);
29
30 static inline PyThreadState*
31 _PyInterpreterState_GetFinalizing(PyInterpreterState *interp) {
32 return (PyThreadState*)_Py_atomic_load_ptr_relaxed(&interp->_finalizing);
33 }
34
35 static inline unsigned long
36 _PyInterpreterState_GetFinalizingID(PyInterpreterState *interp) {
37 return _Py_atomic_load_ulong_relaxed(&interp->_finalizing_id);
38 }
39
40 static inline void
41 _PyInterpreterState_SetFinalizing(PyInterpreterState *interp, PyThreadState *tstate) {
42 _Py_atomic_store_ptr_relaxed(&interp->_finalizing, tstate);
43 if (tstate == NULL) {
44 _Py_atomic_store_ulong_relaxed(&interp->_finalizing_id, 0);
45 }
46 else {
47 // XXX Re-enable this assert once gh-109860 is fixed.
48 //assert(tstate->thread_id == PyThread_get_thread_ident());
49 _Py_atomic_store_ulong_relaxed(&interp->_finalizing_id,
50 tstate->thread_id);
51 }
52 }
53
54
55 // Exports for the _testinternalcapi module.
56 PyAPI_FUNC(int64_t) _PyInterpreterState_ObjectToID(PyObject *);
57 PyAPI_FUNC(PyInterpreterState *) _PyInterpreterState_LookUpID(int64_t);
58 PyAPI_FUNC(PyInterpreterState *) _PyInterpreterState_LookUpIDObject(PyObject *);
59 PyAPI_FUNC(void) _PyInterpreterState_IDIncref(PyInterpreterState *);
60 PyAPI_FUNC(void) _PyInterpreterState_IDDecref(PyInterpreterState *);
61
62 PyAPI_FUNC(int) _PyInterpreterState_IsReady(PyInterpreterState *interp);
63
64 PyAPI_FUNC(long) _PyInterpreterState_GetWhence(PyInterpreterState *interp);
65 extern void _PyInterpreterState_SetWhence(
66 PyInterpreterState *interp,
67 long whence);
68
69 /*
70 Runtime Feature Flags
71
72 Each flag indicate whether or not a specific runtime feature
73 is available in a given context. For example, forking the process
74 might not be allowed in the current interpreter (i.e. os.fork() would fail).
75 */
76
77 /* Set if the interpreter share obmalloc runtime state
78 with the main interpreter. */
79 #define Py_RTFLAGS_USE_MAIN_OBMALLOC (1UL << 5)
80
81 /* Set if import should check a module for subinterpreter support. */
82 #define Py_RTFLAGS_MULTI_INTERP_EXTENSIONS (1UL << 8)
83
84 /* Set if threads are allowed. */
85 #define Py_RTFLAGS_THREADS (1UL << 10)
86
87 /* Set if daemon threads are allowed. */
88 #define Py_RTFLAGS_DAEMON_THREADS (1UL << 11)
89
90 /* Set if os.fork() is allowed. */
91 #define Py_RTFLAGS_FORK (1UL << 15)
92
93 /* Set if os.exec*() is allowed. */
94 #define Py_RTFLAGS_EXEC (1UL << 16)
95
96 extern int _PyInterpreterState_HasFeature(PyInterpreterState *interp,
97 unsigned long feature);
98
99 PyAPI_FUNC(PyStatus) _PyInterpreterState_New(
100 PyThreadState *tstate,
101 PyInterpreterState **pinterp);
102
103 extern const PyConfig* _PyInterpreterState_GetConfig(
104 PyInterpreterState *interp);
105
106 #ifdef __cplusplus
107 }
108 #endif
109 #endif /* !Py_INTERNAL_INTERP_H */