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