diff options
author | Dong-hee Na <donghee.na92@gmail.com> | 2020-03-31 12:43:47 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-31 12:43:47 (GMT) |
commit | 1cb763b8808745b9a368c1158fda19d329f63f6f (patch) | |
tree | 2e79418d5b5b38f5dd4db4978f8ac4d62071595c | |
parent | 63ba5cccf484b9ec23dfbf4cf7ffdc833eda98c3 (diff) | |
download | cpython-1cb763b8808745b9a368c1158fda19d329f63f6f.zip cpython-1cb763b8808745b9a368c1158fda19d329f63f6f.tar.gz cpython-1cb763b8808745b9a368c1158fda19d329f63f6f.tar.bz2 |
bpo-1635741: Port _uuid module to multiphase initialization (GH-19242)
-rw-r--r-- | Misc/NEWS.d/next/Core and Builtins/2020-03-31-21-12-27.bpo-1635741.S2nkF3.rst | 1 | ||||
-rw-r--r-- | Modules/_uuidmodule.c | 41 |
2 files changed, 23 insertions, 19 deletions
diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-03-31-21-12-27.bpo-1635741.S2nkF3.rst b/Misc/NEWS.d/next/Core and Builtins/2020-03-31-21-12-27.bpo-1635741.S2nkF3.rst new file mode 100644 index 0000000..7d5a8ca --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2020-03-31-21-12-27.bpo-1635741.S2nkF3.rst @@ -0,0 +1 @@ +Port _uuid module to multiphase initialization (:pep:`489`). diff --git a/Modules/_uuidmodule.c b/Modules/_uuidmodule.c index 0b7aa72..3be6c84 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); } |