From e6bb17fe29713368e1fd93d9ac9611017c4f570c Mon Sep 17 00:00:00 2001 From: "Miss Islington (bot)" <31488909+miss-islington@users.noreply.github.com> Date: Thu, 13 Jan 2022 10:50:09 -0800 Subject: [PATCH 1/4] bpo-46070: _PyGC_Fini() untracks objects (GH-30577) Py_EndInterpreter() now explicitly untracks all objects currently tracked by the GC. Previously, if an object was used later by another interpreter, calling PyObject_GC_UnTrack() on the object crashed if the previous or the next object of the PyGC_Head structure became a dangling pointer. (cherry picked from commit 1a4d1c1c9b08e75e88aeac90901920938f649832) Co-authored-by: Victor Stinner --- .../2022-01-13-17-58-56.bpo-46070.q8IGth.rst | 5 ++++ Modules/gcmodule.c | 24 +++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2022-01-13-17-58-56.bpo-46070.q8IGth.rst diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-01-13-17-58-56.bpo-46070.q8IGth.rst b/Misc/NEWS.d/next/Core and Builtins/2022-01-13-17-58-56.bpo-46070.q8IGth.rst new file mode 100644 index 00000000000..4ed088f9898 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2022-01-13-17-58-56.bpo-46070.q8IGth.rst @@ -0,0 +1,5 @@ +:c:func:`Py_EndInterpreter` now explicitly untracks all objects currently +tracked by the GC. Previously, if an object was used later by another +interpreter, calling :c:func:`PyObject_GC_UnTrack` on the object crashed if the +previous or the next object of the :c:type:`PyGC_Head` structure became a +dangling pointer. Patch by Victor Stinner. diff --git a/Modules/gcmodule.c b/Modules/gcmodule.c index e5e5aa3287b..805a159d53d 100644 --- a/Modules/gcmodule.c +++ b/Modules/gcmodule.c @@ -2162,12 +2162,36 @@ _PyGC_DumpShutdownStats(PyInterpreterState *interp) } } + +static void +gc_fini_untrack(PyGC_Head *list) +{ + PyGC_Head *gc; + for (gc = GC_NEXT(list); gc != list; gc = GC_NEXT(list)) { + PyObject *op = FROM_GC(gc); + _PyObject_GC_UNTRACK(op); + } +} + + void _PyGC_Fini(PyInterpreterState *interp) { GCState *gcstate = &interp->gc; Py_CLEAR(gcstate->garbage); Py_CLEAR(gcstate->callbacks); + + if (!_Py_IsMainInterpreter(interp)) { + // bpo-46070: Explicitly untrack all objects currently tracked by the + // GC. Otherwise, if an object is used later by another interpreter, + // calling PyObject_GC_UnTrack() on the object crashs if the previous + // or the next object of the PyGC_Head structure became a dangling + // pointer. + for (int i = 0; i < NUM_GENERATIONS; i++) { + PyGC_Head *gen = GEN_HEAD(gcstate, i); + gc_fini_untrack(gen); + } + } } /* for debugging */ From 47422a852de14a8ec11d058136c7c864d2cc7fc9 Mon Sep 17 00:00:00 2001 From: "Miss Islington (bot)" <31488909+miss-islington@users.noreply.github.com> Date: Thu, 13 Jan 2022 13:08:47 -0800 Subject: [PATCH 2/4] [3.10] bpo-40479: Fix typo, flag must be set for OpenSSL < 3.0.0 (GH-30584) (GH-30585) (cherry picked from commit 276c234ce0fa6732237f1b187989837324d9dea3) Co-authored-by: Christian Heimes Automerge-Triggered-By: GH:tiran --- Modules/_hashopenssl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/_hashopenssl.c b/Modules/_hashopenssl.c index cb8460ab2fc..2eaa5f7d85d 100644 --- a/Modules/_hashopenssl.c +++ b/Modules/_hashopenssl.c @@ -883,7 +883,7 @@ py_evp_fromname(PyObject *module, const char *digestname, PyObject *data_obj, goto exit; } -#if defined(EVP_MD_CTX_FLAG_NON_FIPS_ALLOW) && OPENSSL_VERSION_NUMBER >= 0x30000000L +#if defined(EVP_MD_CTX_FLAG_NON_FIPS_ALLOW) && OPENSSL_VERSION_NUMBER < 0x30000000L // In OpenSSL 1.1.1 the non FIPS allowed flag is context specific while // in 3.0.0 it is a different EVP_MD provider. if (!usedforsecurity) { From 86d18019e96167c5ab6f5157fa90598202849904 Mon Sep 17 00:00:00 2001 From: "Miss Islington (bot)" <31488909+miss-islington@users.noreply.github.com> Date: Thu, 13 Jan 2022 20:32:40 -0800 Subject: [PATCH 3/4] bpo-46280: Fix tracemalloc_copy_domain() (GH-30591) Test if tracemalloc_copy_traces() failed to allocated memory in tracemalloc_copy_domain(). (cherry picked from commit 7c770d3350813a82a639fcb3babae0de2b87aaae) Co-authored-by: Victor Stinner --- Modules/_tracemalloc.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Modules/_tracemalloc.c b/Modules/_tracemalloc.c index 90498fb7a78..ba0eb738abc 100644 --- a/Modules/_tracemalloc.c +++ b/Modules/_tracemalloc.c @@ -1241,6 +1241,9 @@ tracemalloc_copy_domain(_Py_hashtable_t *domains, _Py_hashtable_t *traces = (_Py_hashtable_t *)value; _Py_hashtable_t *traces2 = tracemalloc_copy_traces(traces); + if (traces2 == NULL) { + return -1; + } if (_Py_hashtable_set(domains2, TO_PTR(domain), traces2) < 0) { _Py_hashtable_destroy(traces2); return -1; From 26039d1e0a1da897d28688895126eb8bbd16f2c9 Mon Sep 17 00:00:00 2001 From: "Miss Islington (bot)" <31488909+miss-islington@users.noreply.github.com> Date: Fri, 14 Jan 2022 09:47:51 -0800 Subject: [PATCH 4/4] bpo-23183: Document the timeit output (GH-30359) Co-authored-by: Robert Collins (cherry picked from commit 73140de97cbeb01bb6c9af1da89ecb9355921e91) Co-authored-by: Hugo van Kemenade --- Doc/library/timeit.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Doc/library/timeit.rst b/Doc/library/timeit.rst index d4e8b749db4..ca21fe62232 100644 --- a/Doc/library/timeit.rst +++ b/Doc/library/timeit.rst @@ -282,6 +282,13 @@ It is possible to provide a setup statement that is executed only once at the be $ python -m timeit -s 'text = "sample string"; char = "g"' 'text.find(char)' 1000000 loops, best of 5: 0.342 usec per loop +In the output, there are three fields. The loop count, which tells you how many +times the statement body was run per timing loop repetition. The repetition +count ('best of 5') which tells you how many times the timing loop was +repeated, and finally the time the statement body took on average within the +best repetition of the timing loop. That is, the time the fastest repetition +took divided by the loop count. + :: >>> import timeit