Skip to content

Commit

Permalink
gh-99540: Constant hash for _PyNone_Type to aid reproducibility (GH-9…
Browse files Browse the repository at this point in the history
…9541)

Needed for ASLR builds of Python.
  • Loading branch information
yonillasky authored Dec 16, 2022
1 parent a5a7cea commit 432117c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
``None`` now hashes to a constant value. This is not a requirements change.
7 changes: 6 additions & 1 deletion Objects/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -1641,6 +1641,11 @@ none_bool(PyObject *v)
return 0;
}

static Py_hash_t none_hash(PyObject *v)
{
return 0xFCA86420;
}

static PyNumberMethods none_as_number = {
0, /* nb_add */
0, /* nb_subtract */
Expand Down Expand Up @@ -1692,7 +1697,7 @@ PyTypeObject _PyNone_Type = {
&none_as_number, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
0, /*tp_hash */
(hashfunc)none_hash,/*tp_hash */
0, /*tp_call */
0, /*tp_str */
0, /*tp_getattro */
Expand Down

0 comments on commit 432117c

Please sign in to comment.