summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryonillasky <yonillasky@users.noreply.github.com>2022-12-16 20:36:13 (GMT)
committerGitHub <noreply@github.com>2022-12-16 20:36:13 (GMT)
commit432117cd1f59c76d97da2eaff55a7d758301dbc7 (patch)
tree62042b1cb80bf26c7bf7dc3a216004943aa61808
parenta5a7cea202d34ca699d9594d428ba527ef7ff2ce (diff)
downloadcpython-432117cd1f59c76d97da2eaff55a7d758301dbc7.zip
cpython-432117cd1f59c76d97da2eaff55a7d758301dbc7.tar.gz
cpython-432117cd1f59c76d97da2eaff55a7d758301dbc7.tar.bz2
gh-99540: Constant hash for _PyNone_Type to aid reproducibility (GH-99541)
Needed for ASLR builds of Python.
-rw-r--r--Misc/NEWS.d/next/Core and Builtins/2022-12-10-20-00-13.gh-issue-99540.ZZZHeP.rst1
-rw-r--r--Objects/object.c7
2 files changed, 7 insertions, 1 deletions
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
index 0000000..ae043f3
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2022-12-10-20-00-13.gh-issue-99540.ZZZHeP.rst
@@ -0,0 +1 @@
+``None`` now hashes to a constant value. This is not a requirements change.
diff --git a/Objects/object.c b/Objects/object.c
index 687bd36..028b0ed 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -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 */