From 432117cd1f59c76d97da2eaff55a7d758301dbc7 Mon Sep 17 00:00:00 2001 From: yonillasky Date: Fri, 16 Dec 2022 22:36:13 +0200 Subject: [PATCH] gh-99540: Constant hash for _PyNone_Type to aid reproducibility (GH-99541) Needed for ASLR builds of Python. --- .../2022-12-10-20-00-13.gh-issue-99540.ZZZHeP.rst | 1 + Objects/object.c | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2022-12-10-20-00-13.gh-issue-99540.ZZZHeP.rst 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 00000000000000..ae043f3aba55e8 --- /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 687bd36d2b4af1..028b0edc911155 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 */