Skip to content

Commit 1cb763b

Browse files
authored
bpo-1635741: Port _uuid module to multiphase initialization (GH-19242)
1 parent 63ba5cc commit 1cb763b

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Port _uuid module to multiphase initialization (:pep:`489`).

Modules/_uuidmodule.c

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,38 +38,41 @@ py_uuid_generate_time_safe(PyObject *Py_UNUSED(context),
3838
#endif
3939
}
4040

41+
static int
42+
uuid_exec(PyObject *module) {
43+
assert(sizeof(uuid_t) == 16);
44+
#ifdef HAVE_UUID_GENERATE_TIME_SAFE
45+
int has_uuid_generate_time_safe = 1;
46+
#else
47+
int has_uuid_generate_time_safe = 0;
48+
#endif
49+
if (PyModule_AddIntConstant(module, "has_uuid_generate_time_safe",
50+
has_uuid_generate_time_safe) < 0) {
51+
return -1;
52+
}
53+
return 0;
54+
}
4155

4256
static PyMethodDef uuid_methods[] = {
4357
{"generate_time_safe", py_uuid_generate_time_safe, METH_NOARGS, NULL},
4458
{NULL, NULL, 0, NULL} /* sentinel */
4559
};
4660

61+
static PyModuleDef_Slot uuid_slots[] = {
62+
{Py_mod_exec, uuid_exec},
63+
{0, NULL}
64+
};
65+
4766
static struct PyModuleDef uuidmodule = {
4867
PyModuleDef_HEAD_INIT,
4968
.m_name = "_uuid",
50-
.m_size = -1,
69+
.m_size = 0,
5170
.m_methods = uuid_methods,
71+
.m_slots = uuid_slots,
5272
};
5373

5474
PyMODINIT_FUNC
5575
PyInit__uuid(void)
5676
{
57-
PyObject *mod;
58-
assert(sizeof(uuid_t) == 16);
59-
#ifdef HAVE_UUID_GENERATE_TIME_SAFE
60-
int has_uuid_generate_time_safe = 1;
61-
#else
62-
int has_uuid_generate_time_safe = 0;
63-
#endif
64-
mod = PyModule_Create(&uuidmodule);
65-
if (mod == NULL) {
66-
return NULL;
67-
}
68-
if (PyModule_AddIntConstant(mod, "has_uuid_generate_time_safe",
69-
has_uuid_generate_time_safe) < 0) {
70-
Py_DECREF(mod);
71-
return NULL;
72-
}
73-
74-
return mod;
77+
return PyModuleDef_Init(&uuidmodule);
7578
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy