1 #ifndef Py_INTERNAL_CONTEXT_H
2 #define Py_INTERNAL_CONTEXT_H
3
4 #ifndef Py_BUILD_CORE
5 # error "this header requires Py_BUILD_CORE define"
6 #endif
7
8 #include "pycore_hamt.h" /* PyHamtObject */
9
10
11 extern PyTypeObject _PyContextTokenMissing_Type;
12
13 /* runtime lifecycle */
14
15 PyStatus _PyContext_Init(PyInterpreterState *);
16 void _PyContext_Fini(PyInterpreterState *);
17
18
19 /* other API */
20
21 typedef struct {
22 PyObject_HEAD
23 } _PyContextTokenMissing;
24
25 #ifndef WITH_FREELISTS
26 // without freelists
27 # define PyContext_MAXFREELIST 0
28 #endif
29
30 #ifndef PyContext_MAXFREELIST
31 # define PyContext_MAXFREELIST 255
32 #endif
33
34 struct _Py_context_state {
35 #if PyContext_MAXFREELIST > 0
36 // List of free PyContext objects
37 PyContext *freelist;
38 int numfree;
39 #endif
40 };
41
42 struct _pycontextobject {
43 PyObject_HEAD
44 PyContext *ctx_prev;
45 PyHamtObject *ctx_vars;
46 PyObject *ctx_weakreflist;
47 int ctx_entered;
48 };
49
50
51 struct _pycontextvarobject {
52 PyObject_HEAD
53 PyObject *var_name;
54 PyObject *var_default;
55 PyObject *var_cached;
56 uint64_t var_cached_tsid;
57 uint64_t var_cached_tsver;
58 Py_hash_t var_hash;
59 };
60
61
62 struct _pycontexttokenobject {
63 PyObject_HEAD
64 PyContext *tok_ctx;
65 PyContextVar *tok_var;
66 PyObject *tok_oldval;
67 int tok_used;
68 };
69
70
71 #endif /* !Py_INTERNAL_CONTEXT_H */