[Python-porting] Control of hash randomization

martin at v.loewis.de martin at v.loewis.de
Sun May 27 08:22:27 CEST 2012


> I'm still couldn't find how to actually get that seed, though.

In C, you can look at _Py_HashSecret. In Python, you need to write
an extension module, or use ctypes on the Python interpreter itself.

However, this is not the seed: when an RNG is used, there is no seed,
instead, the OS directly provides the hash secret. So your extension
would also have to support setting the secret, which is tricky because
the secret is already used by the time the extension gets loaded.

So you would have to change the interpreter to support such a feature.

If the crashes/test failures are frequent enough, I rather recommend
testing with PYTHONHASHSEED set to random integers.

Also: if a test fails due to hash randomization, it should normally
be possible to find the root cause by just reviewing the code (long
enough). It may not be possible to reproduce the failure, but it
should be obvious if a certain piece of code would fail under hash
randomization.

Regards,
Martin




More information about the Python-porting mailing list