_contextvarsmodule.c 1.6 KB

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