From 08076295e1396378ac745f4f5ed9a283a121cb65 Mon Sep 17 00:00:00 2001 From: Dong-hee Na Date: Thu, 11 Jun 2020 23:26:19 +0900 Subject: [PATCH] bpo-1635741: Port nis module to multiphase initialization. --- ...2020-06-11-23-26-16.bpo-1635741.uo-J-U.rst | 1 + Modules/nismodule.c | 41 +++++++++++-------- 2 files changed, 25 insertions(+), 17 deletions(-) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2020-06-11-23-26-16.bpo-1635741.uo-J-U.rst diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-06-11-23-26-16.bpo-1635741.uo-J-U.rst b/Misc/NEWS.d/next/Core and Builtins/2020-06-11-23-26-16.bpo-1635741.uo-J-U.rst new file mode 100644 index 00000000000000..0377cc8fceec4f --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2020-06-11-23-26-16.bpo-1635741.uo-J-U.rst @@ -0,0 +1 @@ +Port :mod:`nis` to multiphase initialization. diff --git a/Modules/nismodule.c b/Modules/nismodule.c index a24978e0686705..2dd270f94e5f33 100644 --- a/Modules/nismodule.c +++ b/Modules/nismodule.c @@ -439,31 +439,38 @@ static PyMethodDef nis_methods[] = { {NULL, NULL} /* Sentinel */ }; +static int +nis_exec(PyObject *module) +{ + NisError = PyErr_NewException("nis.error", NULL, NULL); + Py_INCREF(NisError); + if (PyModule_AddObject(module, "error", NisError) < 0) { + Py_DECREF(NisError); + return -1; + } + return 0; +} + +static PyModuleDef_Slot nis_slots[] = { + {Py_mod_exec, nis_exec}, + {0, NULL} +}; + + PyDoc_STRVAR(nis__doc__, "This module contains functions for accessing NIS maps.\n"); static struct PyModuleDef nismodule = { PyModuleDef_HEAD_INIT, - "nis", - nis__doc__, - -1, - nis_methods, - NULL, - NULL, - NULL, - NULL + .m_name = "nis", + .m_doc = nis__doc__, + .m_size = 0, + .m_methods = nis_methods, + .m_slots = nis_slots, }; PyMODINIT_FUNC PyInit_nis(void) { - PyObject *m, *d; - m = PyModule_Create(&nismodule); - if (m == NULL) - return NULL; - d = PyModule_GetDict(m); - NisError = PyErr_NewException("nis.error", NULL, NULL); - if (NisError != NULL) - PyDict_SetItemString(d, "error", NisError); - return m; + return PyModuleDef_Init(&nismodule); }