X-Git-Url: https://git.distorted.org.uk/~mdw/pyke/blobdiff_plain/68ec53f32a22b0c38e3b7b53e03edf747c49e416..dfe0a89785e70fdb3c75196b54ae05f006a35ca3:/catacomb.c diff --git a/catacomb.c b/catacomb.c index 65d3985..015c5a7 100644 --- a/catacomb.c +++ b/catacomb.c @@ -1,13 +1,11 @@ /* -*-c-*- * - * $Id$ - * * Where the fun begins * * (c) 2004 Straylight/Edgeware */ -/*----- Licensing notice --------------------------------------------------* +/*----- Licensing notice --------------------------------------------------* * * This file is part of the Python interface to Catacomb. * @@ -15,12 +13,12 @@ * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. - * + * * Catacomb/Python is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with Catacomb/Python; if not, write to the Free Software Foundation, * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. @@ -146,11 +144,27 @@ static PyMethodDef methods[] = { { 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; + init_random(); mod = Py_InitModule("catacomb._base", donemethods()); INSERT_MODULES; INSERT("smallprimes", smallprimes());