bpo-1635741: Port _contextvars module to multiphase initialization (P… · python/cpython@7d79568

@@ -27,52 +27,55 @@ static PyMethodDef _contextvars_methods[] = {

2727

{NULL, NULL}

2828

};

292930-

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

43-

PyInit__contextvars(void)

30+

static int

31+

_contextvars_exec(PyObject *m)

4432

{

45-

PyObject *m = PyModule_Create(&_contextvarsmodule);

46-

if (m == NULL) {

47-

return NULL;

48-

}

49-5033

Py_INCREF(&PyContext_Type);

5134

if (PyModule_AddObject(m, "Context",

5235

(PyObject *)&PyContext_Type) < 0)

5336

{

5437

Py_DECREF(&PyContext_Type);

55-

Py_DECREF(m);

56-

return NULL;

38+

return -1;

5739

}

58405941

Py_INCREF(&PyContextVar_Type);

6042

if (PyModule_AddObject(m, "ContextVar",

6143

(PyObject *)&PyContextVar_Type) < 0)

6244

{

6345

Py_DECREF(&PyContextVar_Type);

64-

Py_DECREF(m);

65-

return NULL;

46+

return -1;

6647

}

67486849

Py_INCREF(&PyContextToken_Type);

6950

if (PyModule_AddObject(m, "Token",

7051

(PyObject *)&PyContextToken_Type) < 0)

7152

{

7253

Py_DECREF(&PyContextToken_Type);

73-

Py_DECREF(m);

74-

return NULL;

54+

return -1;

7555

}

765677-

return m;

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

78+

PyInit__contextvars(void)

79+

{

80+

return PyModuleDef_Init(&_contextvarsmodule);

7881

}