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 Py_INCREF(&PyContext_Type);
34 if (PyModule_AddObject(m, "Context",
35 (PyObject *)&PyContext_Type) < 0)
36 {
37 Py_DECREF(&PyContext_Type);
38 return -1;
39 }
40
41 Py_INCREF(&PyContextVar_Type);
42 if (PyModule_AddObject(m, "ContextVar",
43 (PyObject *)&PyContextVar_Type) < 0)
44 {
45 Py_DECREF(&PyContextVar_Type);
46 return -1;
47 }
48
49 Py_INCREF(&PyContextToken_Type);
50 if (PyModule_AddObject(m, "Token",
51 (PyObject *)&PyContextToken_Type) < 0)
52 {
53 Py_DECREF(&PyContextToken_Type);
54 return -1;
55 }
56
57 return 0;
58 }
59
60 static struct PyModuleDef_Slot _contextvars_slots[] = {
61 {Py_mod_exec, _contextvars_exec},
62 {0, NULL}
63 };
64
65 static struct PyModuleDef _contextvarsmodule = {
66 PyModuleDef_HEAD_INIT, /* m_base */
67 "_contextvars", /* m_name */
68 module_doc, /* m_doc */
69 0, /* m_size */
70 _contextvars_methods, /* m_methods */
71 _contextvars_slots, /* m_slots */
72 NULL, /* m_traverse */
73 NULL, /* m_clear */
74 NULL, /* m_free */
75 };
76
77 PyMODINIT_FUNC
PyInit__contextvars(void)78 PyInit__contextvars(void)
79 {
80 return PyModuleDef_Init(&_contextvarsmodule);
81 }
82