summaryrefslogtreecommitdiffstats
path: root/Modules/_uuidmodule.c
diff options
context:
space:
mode:
authorAntoine Pitrou <pitrou@free.fr>2017-09-28 21:03:06 (GMT)
committerGitHub <noreply@github.com>2017-09-28 21:03:06 (GMT)
commita106aec2ed6ba171838ca7e6ba43c4e722bbecd1 (patch)
tree2a242b9061198d40f40d2921818e6da8089a9b50 /Modules/_uuidmodule.c
parent8d59aca4a953b097a9b02b0ecafef840e4ac5855 (diff)
downloadcpython-a106aec2ed6ba171838ca7e6ba43c4e722bbecd1.zip
cpython-a106aec2ed6ba171838ca7e6ba43c4e722bbecd1.tar.gz
cpython-a106aec2ed6ba171838ca7e6ba43c4e722bbecd1.tar.bz2
bpo-11063, bpo-20519: avoid ctypes and improve import time for uuid (#3796)
bpo-11063, bpo-20519: avoid ctypes and improve import time for uuid.
Diffstat (limited to 'Modules/_uuidmodule.c')
-rw-r--r--Modules/_uuidmodule.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/Modules/_uuidmodule.c b/Modules/_uuidmodule.c
new file mode 100644
index 0000000..e263b40
--- /dev/null
+++ b/Modules/_uuidmodule.c
@@ -0,0 +1,35 @@
+#define PY_SSIZE_T_CLEAN
+
+#include "Python.h"
+#include <uuid/uuid.h>
+
+
+static PyObject *
+py_uuid_generate_time_safe(void)
+{
+ uuid_t out;
+ int res;
+
+ res = uuid_generate_time_safe(out);
+ return Py_BuildValue("y#i", (const char *) out, sizeof(out), res);
+}
+
+
+static PyMethodDef uuid_methods[] = {
+ {"generate_time_safe", (PyCFunction) 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)
+{
+ assert(sizeof(uuid_t) == 16);
+ return PyModule_Create(&uuidmodule);
+}