From 94056101489d0cb4d9cc77097ebce5479ec5e829 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filipe=20La=C3=ADns?= Date: Wed, 14 Apr 2021 23:31:51 +0100 Subject: [PATCH 1/3] bpo-43850: write sets reproducibly in marshalled code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Filipe LaĆ­ns --- Python/marshal.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Python/marshal.c b/Python/marshal.c index fa4ec9eb605f05..fb54279332ddee 100644 --- a/Python/marshal.c +++ b/Python/marshal.c @@ -492,7 +492,7 @@ w_complex_object(PyObject *v, char flag, WFILE *p) w_object((PyObject *)NULL, p); } else if (PyAnySet_CheckExact(v)) { - PyObject *value; + PyObject *ordered_list, *value; Py_ssize_t pos = 0; Py_hash_t hash; @@ -502,8 +502,10 @@ w_complex_object(PyObject *v, char flag, WFILE *p) W_TYPE(TYPE_SET, p); n = PySet_GET_SIZE(v); W_SIZE(n, p); - while (_PySet_NextEntry(v, &pos, &value, &hash)) { - w_object(value, p); + ordered_list = PySequence_List(v); + PyList_Sort(ordered_list); + for (i = 0; i < n; i++) { + w_object(PyList_GET_ITEM(ordered_list, i), p); } } else if (PyCode_Check(v)) { From 5e714eb9fa5d6c2fff4298f1ca5353b45dd88017 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Wed, 14 Apr 2021 22:36:33 +0000 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Core and Builtins/2021-04-14-22-36-31.bpo-43850.hi1RaZ.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2021-04-14-22-36-31.bpo-43850.hi1RaZ.rst diff --git a/Misc/NEWS.d/next/Core and Builtins/2021-04-14-22-36-31.bpo-43850.hi1RaZ.rst b/Misc/NEWS.d/next/Core and Builtins/2021-04-14-22-36-31.bpo-43850.hi1RaZ.rst new file mode 100644 index 00000000000000..231fab2ba33028 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2021-04-14-22-36-31.bpo-43850.hi1RaZ.rst @@ -0,0 +1 @@ +Write sets and frozensets reproducibely in marshalled code. This makes Python bytecode not depend on the random seed. \ No newline at end of file From ce93d50e1521e039ae1145f36fd97b01eb747eef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filipe=20La=C3=ADns?= Date: Wed, 14 Apr 2021 23:42:48 +0100 Subject: [PATCH 3/3] Apply suggestions from code review Co-authored-by: Morten Linderud --- .../Core and Builtins/2021-04-14-22-36-31.bpo-43850.hi1RaZ.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Core and Builtins/2021-04-14-22-36-31.bpo-43850.hi1RaZ.rst b/Misc/NEWS.d/next/Core and Builtins/2021-04-14-22-36-31.bpo-43850.hi1RaZ.rst index 231fab2ba33028..1f2886dc316482 100644 --- a/Misc/NEWS.d/next/Core and Builtins/2021-04-14-22-36-31.bpo-43850.hi1RaZ.rst +++ b/Misc/NEWS.d/next/Core and Builtins/2021-04-14-22-36-31.bpo-43850.hi1RaZ.rst @@ -1 +1 @@ -Write sets and frozensets reproducibely in marshalled code. This makes Python bytecode not depend on the random seed. \ No newline at end of file +Write sets and frozensets reproducibly in marshalled code. This makes Python bytecode not depend on the random seed.