diff options
author | Dong-hee Na <donghee.na92@gmail.com> | 2020-03-31 21:43:47 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-31 14:43:47 +0200 |
commit | 1cb763b8808745b9a368c1158fda19d329f63f6f (patch) | |
tree | 2e79418d5b5b38f5dd4db4978f8ac4d62071595c /Modules/_uuidmodule.c | |
parent | bpo-40121: Fixes audit event raised on creating a new socket (GH-19238) (diff) | |
download | cpython-1cb763b8808745b9a368c1158fda19d329f63f6f.tar.gz cpython-1cb763b8808745b9a368c1158fda19d329f63f6f.tar.bz2 cpython-1cb763b8808745b9a368c1158fda19d329f63f6f.zip |
bpo-1635741: Port _uuid module to multiphase initialization (GH-19242)
Diffstat (limited to 'Modules/_uuidmodule.c')
-rw-r--r-- | Modules/_uuidmodule.c | 41 |
1 files changed, 22 insertions, 19 deletions
diff --git a/Modules/_uuidmodule.c b/Modules/_uuidmodule.c index 0b7aa72e91a..3be6c848ad6 100644 --- a/Modules/_uuidmodule.c +++ b/Modules/_uuidmodule.c @@ -38,38 +38,41 @@ py_uuid_generate_time_safe(PyObject *Py_UNUSED(context), #endif } +static int +uuid_exec(PyObject *module) { + assert(sizeof(uuid_t) == 16); +#ifdef HAVE_UUID_GENERATE_TIME_SAFE + int has_uuid_generate_time_safe = 1; +#else + int has_uuid_generate_time_safe = 0; +#endif + if (PyModule_AddIntConstant(module, "has_uuid_generate_time_safe", + has_uuid_generate_time_safe) < 0) { + return -1; + } + return 0; +} static PyMethodDef uuid_methods[] = { {"generate_time_safe", py_uuid_generate_time_safe, METH_NOARGS, NULL}, {NULL, NULL, 0, NULL} /* sentinel */ }; +static PyModuleDef_Slot uuid_slots[] = { + {Py_mod_exec, uuid_exec}, + {0, NULL} +}; + static struct PyModuleDef uuidmodule = { PyModuleDef_HEAD_INIT, .m_name = "_uuid", - .m_size = -1, + .m_size = 0, .m_methods = uuid_methods, + .m_slots = uuid_slots, }; PyMODINIT_FUNC PyInit__uuid(void) { - PyObject *mod; - assert(sizeof(uuid_t) == 16); -#ifdef HAVE_UUID_GENERATE_TIME_SAFE - int has_uuid_generate_time_safe = 1; -#else - int has_uuid_generate_time_safe = 0; -#endif - mod = PyModule_Create(&uuidmodule); - if (mod == NULL) { - return NULL; - } - if (PyModule_AddIntConstant(mod, "has_uuid_generate_time_safe", - has_uuid_generate_time_safe) < 0) { - Py_DECREF(mod); - return NULL; - } - - return mod; + return PyModuleDef_Init(&uuidmodule); } |