]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-99540: Constant hash for _PyNone_Type to aid reproducibility (GH-99541)
authoryonillasky <yonillasky@users.noreply.github.com>
Fri, 16 Dec 2022 20:36:13 +0000 (22:36 +0200)
committerGitHub <noreply@github.com>
Fri, 16 Dec 2022 20:36:13 +0000 (12:36 -0800)
Needed for ASLR builds of Python.

Misc/NEWS.d/next/Core and Builtins/2022-12-10-20-00-13.gh-issue-99540.ZZZHeP.rst [new file with mode: 0644]
Objects/object.c

diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-12-10-20-00-13.gh-issue-99540.ZZZHeP.rst b/Misc/NEWS.d/next/Core and Builtins/2022-12-10-20-00-13.gh-issue-99540.ZZZHeP.rst
new file mode 100644 (file)
index 0000000..ae043f3
--- /dev/null
@@ -0,0 +1 @@
+``None`` now hashes to a constant value. This is not a requirements change.
index 687bd36d2b4af1e5b5b08e1b3fdf4efbc491c75d..028b0edc91115518103d020f69a5c1d8aae1c336 100644 (file)
@@ -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 */
@@ -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 */