summaryrefslogtreecommitdiff
path: root/Modules/_blake2/blake2module.c
diff options
context:
space:
mode:
authorGregory P. Smith <greg@krypto.org>2017-01-22 17:29:44 -0800
committerGregory P. Smith <greg@krypto.org>2017-01-22 17:29:44 -0800
commitd71a238820a6e746c7bb1995d8f236b40904924d (patch)
tree1da08aa6698b4a9dcaa5e90d9541b78ac11e1650 /Modules/_blake2/blake2module.c
parentd49be132fb4eb2d302592ebd84fafc4a1c98e531 (diff)
parent424881df2c661ba4238f9f56f273a5f4974f74d4 (diff)
downloadcpython-d71a238820a6e746c7bb1995d8f236b40904924d.tar.gz
Issue #29335: Fix subprocess.Popen.wait() when the child process has
exited to a stopped instead of terminated state (ex: when under ptrace).
Diffstat (limited to 'Modules/_blake2/blake2module.c')
-rw-r--r--Modules/_blake2/blake2module.c105
1 files changed, 105 insertions, 0 deletions
diff --git a/Modules/_blake2/blake2module.c b/Modules/_blake2/blake2module.c
new file mode 100644
index 0000000000..e2a3d420d4
--- /dev/null
+++ b/Modules/_blake2/blake2module.c
@@ -0,0 +1,105 @@
+/*
+ * Written in 2013 by Dmitry Chestnykh <dmitry@codingrobots.com>
+ * Modified for CPython by Christian Heimes <christian@python.org>
+ *
+ * To the extent possible under law, the author have dedicated all
+ * copyright and related and neighboring rights to this software to
+ * the public domain worldwide. This software is distributed without
+ * any warranty. http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+#include "Python.h"
+
+#include "impl/blake2.h"
+
+extern PyTypeObject PyBlake2_BLAKE2bType;
+extern PyTypeObject PyBlake2_BLAKE2sType;
+
+
+PyDoc_STRVAR(blake2mod__doc__,
+"_blake2b provides BLAKE2b for hashlib\n"
+);
+
+
+static struct PyMethodDef blake2mod_functions[] = {
+ {NULL, NULL}
+};
+
+static struct PyModuleDef blake2_module = {
+ PyModuleDef_HEAD_INIT,
+ "_blake2",
+ blake2mod__doc__,
+ -1,
+ blake2mod_functions,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
+#define ADD_INT(d, name, value) do { \
+ PyObject *x = PyLong_FromLong(value); \
+ if (!x) { \
+ Py_DECREF(m); \
+ return NULL; \
+ } \
+ if (PyDict_SetItemString(d, name, x) < 0) { \
+ Py_DECREF(m); \
+ return NULL; \
+ } \
+ Py_DECREF(x); \
+} while(0)
+
+
+PyMODINIT_FUNC
+PyInit__blake2(void)
+{
+ PyObject *m;
+ PyObject *d;
+
+ m = PyModule_Create(&blake2_module);
+ if (m == NULL)
+ return NULL;
+
+ /* BLAKE2b */
+ Py_TYPE(&PyBlake2_BLAKE2bType) = &PyType_Type;
+ if (PyType_Ready(&PyBlake2_BLAKE2bType) < 0) {
+ return NULL;
+ }
+
+ Py_INCREF(&PyBlake2_BLAKE2bType);
+ PyModule_AddObject(m, "blake2b", (PyObject *)&PyBlake2_BLAKE2bType);
+
+ d = PyBlake2_BLAKE2bType.tp_dict;
+ ADD_INT(d, "SALT_SIZE", BLAKE2B_SALTBYTES);
+ ADD_INT(d, "PERSON_SIZE", BLAKE2B_PERSONALBYTES);
+ ADD_INT(d, "MAX_KEY_SIZE", BLAKE2B_KEYBYTES);
+ ADD_INT(d, "MAX_DIGEST_SIZE", BLAKE2B_OUTBYTES);
+
+ PyModule_AddIntConstant(m, "BLAKE2B_SALT_SIZE", BLAKE2B_SALTBYTES);
+ PyModule_AddIntConstant(m, "BLAKE2B_PERSON_SIZE", BLAKE2B_PERSONALBYTES);
+ PyModule_AddIntConstant(m, "BLAKE2B_MAX_KEY_SIZE", BLAKE2B_KEYBYTES);
+ PyModule_AddIntConstant(m, "BLAKE2B_MAX_DIGEST_SIZE", BLAKE2B_OUTBYTES);
+
+ /* BLAKE2s */
+ Py_TYPE(&PyBlake2_BLAKE2sType) = &PyType_Type;
+ if (PyType_Ready(&PyBlake2_BLAKE2sType) < 0) {
+ return NULL;
+ }
+
+ Py_INCREF(&PyBlake2_BLAKE2sType);
+ PyModule_AddObject(m, "blake2s", (PyObject *)&PyBlake2_BLAKE2sType);
+
+ d = PyBlake2_BLAKE2sType.tp_dict;
+ ADD_INT(d, "SALT_SIZE", BLAKE2S_SALTBYTES);
+ ADD_INT(d, "PERSON_SIZE", BLAKE2S_PERSONALBYTES);
+ ADD_INT(d, "MAX_KEY_SIZE", BLAKE2S_KEYBYTES);
+ ADD_INT(d, "MAX_DIGEST_SIZE", BLAKE2S_OUTBYTES);
+
+ PyModule_AddIntConstant(m, "BLAKE2S_SALT_SIZE", BLAKE2S_SALTBYTES);
+ PyModule_AddIntConstant(m, "BLAKE2S_PERSON_SIZE", BLAKE2S_PERSONALBYTES);
+ PyModule_AddIntConstant(m, "BLAKE2S_MAX_KEY_SIZE", BLAKE2S_KEYBYTES);
+ PyModule_AddIntConstant(m, "BLAKE2S_MAX_DIGEST_SIZE", BLAKE2S_OUTBYTES);
+
+ return m;
+}