chiark
/
gitweb
/
~mdw
/
pyke
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
b06387d
)
catacomb.c: Handle Python's randomize hashing parameters properly.
author
Mark Wooding
<mdw@distorted.org.uk>
Fri, 10 Apr 2015 14:19:25 +0000
(15:19 +0100)
committer
Mark Wooding
<mdw@distorted.org.uk>
Mon, 20 Apr 2015 17:00:11 +0000
(18:00 +0100)
catacomb.c
patch
|
blob
|
blame
|
history
diff --git
a/catacomb.c
b/catacomb.c
index 3aebea33452c9a5f9c22f6ae7c8f932763bf97e5..015c5a76c705fb0aef857912183c7e1a96643a0b 100644
(file)
--- a/
catacomb.c
+++ b/
catacomb.c
@@
-144,11
+144,27
@@
static PyMethodDef methods[] = {
{ 0 }
};
{ 0 }
};
+static void init_random(void)
+{
+#if PY_MAJOR_VERSION >= 3 || (PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION >= 6)
+ char *seed;
+ uint32 r;
+
+ if (!Py_HashRandomizationFlag) return;
+ seed = getenv("PYTHONHASHSEED");
+ if (!seed || strcmp(seed, "random") == 0) r = GR_WORD(&rand_global);
+ else r = strtoul(seed, 0, 0);
+ if (!r) r = 0xe011f220; /* zero doesn't work well */
+ unihash_setkey(&unihash_global, r);
+#endif
+}
+
void init_base(void)
{
PyObject *mod;
addmethods(methods);
INIT_MODULES;
void init_base(void)
{
PyObject *mod;
addmethods(methods);
INIT_MODULES;
+ init_random();
mod = Py_InitModule("catacomb._base", donemethods());
INSERT_MODULES;
INSERT("smallprimes", smallprimes());
mod = Py_InitModule("catacomb._base", donemethods());
INSERT_MODULES;
INSERT("smallprimes", smallprimes());