| Left: | ||
| Right: |
| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #include "Python.h" | |
| 2 #include "pyrandom.h" | |
| 3 | |
| 4 Py_hash_t Py_RndHashSeed = -1; | |
|
gregory.p.smith
2012/01/15 02:18:38
This should be a Py_uhash_t and the default value
| |
| 5 | |
| 6 void | |
| 7 _Py_InitRndHashSeed(void) | |
| 8 { | |
| 9 static int initialized = 0; | |
| 10 int result; | |
| 11 if (initialized) { | |
| 12 return; | |
| 13 } | |
| 14 initialized = 1; | |
| 15 | |
| 16 result = PyOS_URandom((unsigned char*)&Py_RndHashSeed, sizeof(Py_hash_t)); | |
| 17 /* fall back to Mersenne twister */ | |
| 18 if (result == -1) { | |
| 19 _Py_MT_RandomState state; | |
| 20 time_t seed; | |
| 21 int i; | |
| 22 | |
| 23 time(&seed); | |
| 24 _Py_MT_GenRand_Init(&state, seed); | |
|
gregory.p.smith
2012/01/15 02:18:38
Include the pid, system uptime and any other easy
| |
| 25 | |
| 26 Py_RndHashSeed = _Py_MT_GenRand_Int32(&state); | |
| 27 if (Py_RndHashSeed == -1) { | |
| 28 Py_RndHashSeed = -2; | |
| 29 } | |
| 30 | |
| 31 } | |
| 32 } | |
| 33 | |
| 34 /* Randomized hash seed */ | |
| 35 Py_hash_t | |
| 36 Py_GetRndHashSeed(void) | |
| 37 { | |
| 38 return Py_RndHashSeed; | |
| 39 } | |
| OLD | NEW |