bpo-1635741: Port _uuid module to multiphase initialization (GH-19242)
This commit is contained in:
parent
63ba5cccf4
commit
1cb763b880
|
@ -0,0 +1 @@
|
|||
Port _uuid module to multiphase initialization (:pep:`489`).
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue