[Python-checkins] gh-99540: Constant hash for _PyNone_Type to aid reproducibility (GH-99541)
ethanfurman
webhook-mailer at python.org
Fri Dec 16 15:36:19 EST 2022
https://github.com/python/cpython/commit/432117cd1f59c76d97da2eaff55a7d758301dbc7
commit: 432117cd1f59c76d97da2eaff55a7d758301dbc7
branch: main
author: yonillasky <yonillasky at users.noreply.github.com>
committer: ethanfurman <ethan at stoneleaf.us>
date: 2022-12-16T12:36:13-08:00
summary:
gh-99540: Constant hash for _PyNone_Type to aid reproducibility (GH-99541)
Needed for ASLR builds of Python.
files:
A Misc/NEWS.d/next/Core and Builtins/2022-12-10-20-00-13.gh-issue-99540.ZZZHeP.rst
M 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
index 000000000000..ae043f3aba55
--- /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 687bd36d2b4a..028b0edc9111 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 */
More information about the Python-checkins
mailing list