1 #ifndef Py_LIMITED_API
2 #ifndef Py_CONTEXT_H
3 #define Py_CONTEXT_H
4 #ifdef __cplusplus
5 extern "C" {
6 #endif
7
8 PyAPI_DATA(PyTypeObject) PyContext_Type;
9 typedef struct _pycontextobject PyContext;
10
11 PyAPI_DATA(PyTypeObject) PyContextVar_Type;
12 typedef struct _pycontextvarobject PyContextVar;
13
14 PyAPI_DATA(PyTypeObject) PyContextToken_Type;
15 typedef struct _pycontexttokenobject PyContextToken;
16
17
18 #define PyContext_CheckExact(o) Py_IS_TYPE(o, &PyContext_Type)
19 #define PyContextVar_CheckExact(o) Py_IS_TYPE(o, &PyContextVar_Type)
20 #define PyContextToken_CheckExact(o) Py_IS_TYPE(o, &PyContextToken_Type)
21
22
23 PyAPI_FUNC(PyObject *) PyContext_New(void);
24 PyAPI_FUNC(PyObject *) PyContext_Copy(PyObject *);
25 PyAPI_FUNC(PyObject *) PyContext_CopyCurrent(void);
26
27 PyAPI_FUNC(int) PyContext_Enter(PyObject *);
28 PyAPI_FUNC(int) PyContext_Exit(PyObject *);
29
30
31 /* Create a new context variable.
32
33 default_value can be NULL.
34 */
35 PyAPI_FUNC(PyObject *) PyContextVar_New(
36 const char *name, PyObject *default_value);
37
38
39 /* Get a value for the variable.
40
41 Returns -1 if an error occurred during lookup.
42
43 Returns 0 if value either was or was not found.
44
45 If value was found, *value will point to it.
46 If not, it will point to:
47
48 - default_value, if not NULL;
49 - the default value of "var", if not NULL;
50 - NULL.
51
52 '*value' will be a new ref, if not NULL.
53 */
54 PyAPI_FUNC(int) PyContextVar_Get(
55 PyObject *var, PyObject *default_value, PyObject **value);
56
57
58 /* Set a new value for the variable.
59 Returns NULL if an error occurs.
60 */
61 PyAPI_FUNC(PyObject *) PyContextVar_Set(PyObject *var, PyObject *value);
62
63
64 /* Reset a variable to its previous value.
65 Returns 0 on success, -1 on error.
66 */
67 PyAPI_FUNC(int) PyContextVar_Reset(PyObject *var, PyObject *token);
68
69
70 /* This method is exposed only for CPython tests. Don not use it. */
71 PyAPI_FUNC(PyObject *) _PyContext_NewHamtForTests(void);
72
73
74 #ifdef __cplusplus
75 }
76 #endif
77 #endif /* !Py_CONTEXT_H */
78 #endif /* !Py_LIMITED_API */