1 #include "Python.h"
2
3 #include "clinic/_contextvarsmodule.c.h"
4
5 /*[clinic input]
6 module _contextvars
7 [clinic start generated code]*/
8 /*[clinic end generated code: output=da39a3ee5e6b4b0d input=a0955718c8b8cea6]*/
9
10
11 /*[clinic input]
12 _contextvars.copy_context
13 [clinic start generated code]*/
14
15 static PyObject *
_contextvars_copy_context_impl(PyObject * module)16 _contextvars_copy_context_impl(PyObject *module)
17 /*[clinic end generated code: output=1fcd5da7225c4fa9 input=89bb9ae485888440]*/
18 {
19 return PyContext_CopyCurrent();
20 }
21
22
23 PyDoc_STRVAR(module_doc, "Context Variables");
24
25 static PyMethodDef _contextvars_methods[] = {
26 _CONTEXTVARS_COPY_CONTEXT_METHODDEF
27 {NULL, NULL}
28 };
29
30 static int
_contextvars_exec(PyObject * m)31 _contextvars_exec(PyObject *m)
32 {
33 if (PyModule_AddType(m, &PyContext_Type) < 0) {
34 return -1;
35 }
36 if (PyModule_AddType(m, &PyContextVar_Type) < 0) {
37 return -1;
38 }
39 if (PyModule_AddType(m, &PyContextToken_Type) < 0) {
40 return -1;
41 }
42 return 0;
43 }
44
45 static struct PyModuleDef_Slot _contextvars_slots[] = {
46 {Py_mod_exec, _contextvars_exec},
47 {0, NULL}
48 };
49
50 static struct PyModuleDef _contextvarsmodule = {
51 PyModuleDef_HEAD_INIT, /* m_base */
52 "_contextvars", /* m_name */
53 module_doc, /* m_doc */
54 0, /* m_size */
55 _contextvars_methods, /* m_methods */
56 _contextvars_slots, /* m_slots */
57 NULL, /* m_traverse */
58 NULL, /* m_clear */
59 NULL, /* m_free */
60 };
61
62 PyMODINIT_FUNC
PyInit__contextvars(void)63 PyInit__contextvars(void)
64 {
65 return PyModuleDef_Init(&_contextvarsmodule);
66 }
67