From 2437197a538927d6279aadca219e3a896696c9ef Mon Sep 17 00:00:00 2001 From: Alban Browaeys Date: Thu, 24 Mar 2022 22:29:01 +0100 Subject: [PATCH] Python3: Add patch to fix crash in sqlite3 import See https://bugs.python.org/issue46070 Signed-off-by: Alban Browaeys --- .../Python3-0401-fix-bpo-46070-2.patch | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 packages/lang/Python3/patches/Python3-0401-fix-bpo-46070-2.patch diff --git a/packages/lang/Python3/patches/Python3-0401-fix-bpo-46070-2.patch b/packages/lang/Python3/patches/Python3-0401-fix-bpo-46070-2.patch new file mode 100644 index 0000000000..4dae908a08 --- /dev/null +++ b/packages/lang/Python3/patches/Python3-0401-fix-bpo-46070-2.patch @@ -0,0 +1,57 @@ +From e5d8e72824a34c78552bec74511cb8e5412746c2 Mon Sep 17 00:00:00 2001 +From: Alban Browaeys +Date: Thu, 24 Mar 2022 22:20:41 +0100 +Subject: [PATCH] Revert "bpo-46070: _PyGC_Fini() untracks objects (GH-30577) + (GH-30580)" + +This reverts commit 52937c26adc35350ca0402070160cf6dc838f359. +The above commit segfaults python 3.9.11 if importing sqlite3 in +threads. +--- + Modules/gcmodule.c | 24 ------------------------ + 1 file changed, 24 deletions(-) + +diff --git a/Modules/gcmodule.c b/Modules/gcmodule.c +index 3cf1a00b00..2c6ef9252e 100644 +--- a/Modules/gcmodule.c ++++ b/Modules/gcmodule.c +@@ -2149,36 +2149,12 @@ _PyGC_DumpShutdownStats(PyThreadState *tstate) + } + } + +- +-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(PyThreadState *tstate) + { + GCState *gcstate = &tstate->interp->gc; + Py_CLEAR(gcstate->garbage); + Py_CLEAR(gcstate->callbacks); +- +- if (!_Py_IsMainInterpreter(tstate)) { +- // 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 */ +-- +2.30.2 +