blob: 4e5007089dd94bc1a50ca07340674deace6188bf [file] [log] [blame]
Yury Selivanovf23746a2018-01-22 19:11:18 -05001#ifndef Py_CONTEXT_H
2#define Py_CONTEXT_H
3#ifdef __cplusplus
4extern "C" {
5#endif
6
7#ifndef Py_LIMITED_API
8
9
10PyAPI_DATA(PyTypeObject) PyContext_Type;
11typedef struct _pycontextobject PyContext;
12
13PyAPI_DATA(PyTypeObject) PyContextVar_Type;
14typedef struct _pycontextvarobject PyContextVar;
15
16PyAPI_DATA(PyTypeObject) PyContextToken_Type;
17typedef struct _pycontexttokenobject PyContextToken;
18
19
Dong-hee Nad905df72020-02-14 02:37:17 +090020#define PyContext_CheckExact(o) Py_IS_TYPE(o, &PyContext_Type)
21#define PyContextVar_CheckExact(o) Py_IS_TYPE(o, &PyContextVar_Type)
22#define PyContextToken_CheckExact(o) Py_IS_TYPE(o, &PyContextToken_Type)
Yury Selivanovf23746a2018-01-22 19:11:18 -050023
24
Yury Selivanov2ec872b2018-09-21 15:33:56 -040025PyAPI_FUNC(PyObject *) PyContext_New(void);
26PyAPI_FUNC(PyObject *) PyContext_Copy(PyObject *);
27PyAPI_FUNC(PyObject *) PyContext_CopyCurrent(void);
Yury Selivanovf23746a2018-01-22 19:11:18 -050028
Yury Selivanov2ec872b2018-09-21 15:33:56 -040029PyAPI_FUNC(int) PyContext_Enter(PyObject *);
30PyAPI_FUNC(int) PyContext_Exit(PyObject *);
Yury Selivanovf23746a2018-01-22 19:11:18 -050031
32
33/* Create a new context variable.
34
35 default_value can be NULL.
36*/
Yury Selivanov2ec872b2018-09-21 15:33:56 -040037PyAPI_FUNC(PyObject *) PyContextVar_New(
Yury Selivanovf23746a2018-01-22 19:11:18 -050038 const char *name, PyObject *default_value);
39
40
41/* Get a value for the variable.
42
43 Returns -1 if an error occurred during lookup.
44
45 Returns 0 if value either was or was not found.
46
47 If value was found, *value will point to it.
48 If not, it will point to:
49
50 - default_value, if not NULL;
51 - the default value of "var", if not NULL;
52 - NULL.
53
54 '*value' will be a new ref, if not NULL.
55*/
56PyAPI_FUNC(int) PyContextVar_Get(
Yury Selivanov2ec872b2018-09-21 15:33:56 -040057 PyObject *var, PyObject *default_value, PyObject **value);
Yury Selivanovf23746a2018-01-22 19:11:18 -050058
59
60/* Set a new value for the variable.
61 Returns NULL if an error occurs.
62*/
Yury Selivanov2ec872b2018-09-21 15:33:56 -040063PyAPI_FUNC(PyObject *) PyContextVar_Set(PyObject *var, PyObject *value);
Yury Selivanovf23746a2018-01-22 19:11:18 -050064
65
66/* Reset a variable to its previous value.
Ville Skyttä61f82e02018-04-20 23:08:45 +030067 Returns 0 on success, -1 on error.
Yury Selivanovf23746a2018-01-22 19:11:18 -050068*/
Yury Selivanov2ec872b2018-09-21 15:33:56 -040069PyAPI_FUNC(int) PyContextVar_Reset(PyObject *var, PyObject *token);
Yury Selivanovf23746a2018-01-22 19:11:18 -050070
71
72/* This method is exposed only for CPython tests. Don not use it. */
73PyAPI_FUNC(PyObject *) _PyContext_NewHamtForTests(void);
74
75
Yury Selivanovf23746a2018-01-22 19:11:18 -050076#endif /* !Py_LIMITED_API */
77
78#ifdef __cplusplus
79}
80#endif
81#endif /* !Py_CONTEXT_H */