bpo-1635741: Port _uuid module to multiphase initialization (GH-19242)

This commit is contained in:
Dong-hee Na 2020-03-31 21:43:47 +09:00 committed by GitHub
parent 63ba5cccf4
commit 1cb763b880
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 26 deletions

View File

@ -0,0 +1 @@
Port _uuid module to multiphase initialization (:pep:`489`).

View File

@ -38,38 +38,41 @@ py_uuid_generate_time_safe(PyObject *Py_UNUSED(context),
#endif
}
static PyMethodDef uuid_methods[] = {
{"generate_time_safe", py_uuid_generate_time_safe, METH_NOARGS, NULL},
{NULL, NULL, 0, NULL} /* sentinel */
};
static struct PyModuleDef uuidmodule = {
PyModuleDef_HEAD_INIT,
.m_name = "_uuid",
.m_size = -1,
.m_methods = uuid_methods,
};
PyMODINIT_FUNC
PyInit__uuid(void)
{
PyObject *mod;
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
mod = PyModule_Create(&uuidmodule);
if (mod == NULL) {
return NULL;
}
if (PyModule_AddIntConstant(mod, "has_uuid_generate_time_safe",
if (PyModule_AddIntConstant(module, "has_uuid_generate_time_safe",
has_uuid_generate_time_safe) < 0) {
Py_DECREF(mod);
return NULL;
return -1;
}
return mod;
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 = 0,
.m_methods = uuid_methods,
.m_slots = uuid_slots,
};
PyMODINIT_FUNC
PyInit__uuid(void)
{
return PyModuleDef_Init(&uuidmodule);
}