gh-99540: Constant hash for _PyNone_Type to aid reproducibility (GH-99541)

Needed for ASLR builds of Python.
This commit is contained in:
yonillasky 2022-12-16 22:36:13 +02:00 committed by GitHub
parent a5a7cea202
commit 432117cd1f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View file

@ -0,0 +1 @@
``None`` now hashes to a constant value. This is not a requirements change.

View file

@ -1641,6 +1641,11 @@ none_bool(PyObject *v)
return 0; return 0;
} }
static Py_hash_t none_hash(PyObject *v)
{
return 0xFCA86420;
}
static PyNumberMethods none_as_number = { static PyNumberMethods none_as_number = {
0, /* nb_add */ 0, /* nb_add */
0, /* nb_subtract */ 0, /* nb_subtract */
@ -1692,7 +1697,7 @@ PyTypeObject _PyNone_Type = {
&none_as_number, /*tp_as_number*/ &none_as_number, /*tp_as_number*/
0, /*tp_as_sequence*/ 0, /*tp_as_sequence*/
0, /*tp_as_mapping*/ 0, /*tp_as_mapping*/
0, /*tp_hash */ (hashfunc)none_hash,/*tp_hash */
0, /*tp_call */ 0, /*tp_call */
0, /*tp_str */ 0, /*tp_str */
0, /*tp_getattro */ 0, /*tp_getattro */