From f66d57793ca599dba7f3733fe77de6cd9f564b8b Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Thu, 16 Jun 2022 23:11:00 +0200 Subject: [PATCH] Resolves: rhbz#2097411 Fails to build with Python 3.11 --- ...id-obsolete-PyThreadState_Delete-cra.patch | 75 +++++++++++++++++++ libreoffice.spec | 1 + 2 files changed, 76 insertions(+) create mode 100644 0001-rhbz-2097411-Avoid-obsolete-PyThreadState_Delete-cra.patch diff --git a/0001-rhbz-2097411-Avoid-obsolete-PyThreadState_Delete-cra.patch b/0001-rhbz-2097411-Avoid-obsolete-PyThreadState_Delete-cra.patch new file mode 100644 index 0000000..8b60289 --- /dev/null +++ b/0001-rhbz-2097411-Avoid-obsolete-PyThreadState_Delete-cra.patch @@ -0,0 +1,75 @@ +From 1638b4f78af70b7b97d0a081ed51390dd87bf1f9 Mon Sep 17 00:00:00 2001 +From: Stephan Bergmann +Date: Thu, 16 Jun 2022 18:58:18 +0200 +Subject: [PATCH] rhbz#2097411 Avoid obsolete PyThreadState_Delete crashing + Python 3.11 + +1fb53a637597f76bea86514b62ddfad34f60c889 "pyuno_loader::CreateInstance: delete +the initial PyThreadState" had added the PyThreadState_Delete for claimed +benefits but whose details appear lost to history (cf. the comment thread +starting at + +"pyuno_loader::CreateInstance: delete the initial PyThreadState"). And at least +a recent master Linux --enable-python=fully-internal build with the bundled +Python 3.8.12 appears to succeed `make check` just fine with the +PyThreadState_Delete temporarily removed. + +But on the other hand, building against upcoming Python 3.11 now started to make +CppunitTest_services fail with + +> Fatal Python error: init_threadstate: thread state already initialized +> Python runtime state: initialized +> Thread 0x0000ffff81c8b020 (most recent call first): +> +> Fatal exception: Signal 6 +> Stack: +> /builddir/build/BUILD/libreoffice-7.3.4.2/instdir/program/libuno_sal.so.3(+0x37c28)[0xffff81be7c28] +> /builddir/build/BUILD/libreoffice-7.3.4.2/instdir/program/libuno_sal.so.3(+0x37e40)[0xffff81be7e40] +> linux-vdso.so.1(__kernel_rt_sigreturn+0x0)[0xffff81ccb7ec] +> /lib64/libc.so.6(+0x82878)[0xffff81742878] +> /lib64/libc.so.6(raise+0x20)[0xffff816fae00] +> /lib64/libc.so.6(abort+0xe8)[0xffff816e72b8] +> /lib64/libpython3.11.so.1.0(+0x104e28)[0xfffee4de4e28] +> /lib64/libpython3.11.so.1.0(+0x105200)[0xfffee4de5200] +> /lib64/libpython3.11.so.1.0(PyThread_get_thread_native_id+0x0)[0xfffee4ed6764] +> /lib64/libpython3.11.so.1.0(PyThreadState_New+0x14)[0xfffee4ed6628] +> /builddir/build/BUILD/libreoffice-7.3.4.2/instdir/program/libpyuno.so(_ZN5pyuno14PyThreadAttachC2EP3_is+0x78)[0xfffee4c8c52c] +> /builddir/build/BUILD/libreoffice-7.3.4.2/instdir/program/libpythonloaderlo.so(pyuno_Loader_get_implementation+0x5c)[0xfffee5243060] +> /builddir/build/BUILD/libreoffice-7.3.4.2/instdir/program/libuno_cppuhelpergcc3.so.3(+0x544b4)[0xffff815544b4] + +because of the PyThreadState_Delete. (The deleted PyThreadState, while not +reused again directly, is still recorded in the state obtained from +PyInterpreterState_Head() later.) + +So conservatively keep the PyThreadState_Delete of unclear benefit for older +Python versions and only drop it for 3.11 where it is known to have negative +effects now. + +Change-Id: I9b99f1e947f0b165ddc95c2bfbd764858dda39db +Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136006 +Tested-by: Jenkins +Reviewed-by: Stephan Bergmann +--- + pyuno/source/loader/pyuno_loader.cxx | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/pyuno/source/loader/pyuno_loader.cxx b/pyuno/source/loader/pyuno_loader.cxx +index c9b8248c1b25..da0467f450c6 100644 +--- a/pyuno/source/loader/pyuno_loader.cxx ++++ b/pyuno/source/loader/pyuno_loader.cxx +@@ -229,10 +229,12 @@ void pythonInit() { + + PyThreadState *tstate = PyThreadState_Get(); + PyEval_ReleaseThread( tstate ); ++#if PY_VERSION_HEX < 0x030B0000 + // This tstate is never used again, so delete it here. + // This prevents an assertion in PyThreadState_Swap on the + // PyThreadAttach below. + PyThreadState_Delete(tstate); ++#endif + } + + } +-- +2.36.1 + diff --git a/libreoffice.spec b/libreoffice.spec index 5e70a80..045b2d6 100644 --- a/libreoffice.spec +++ b/libreoffice.spec @@ -254,6 +254,7 @@ Patch3: 0001-Revert-tdf-101630-gdrive-support-w-oAuth-and-Drive-A.patch Patch4: 0001-workaround-x86-ICE-with-gcc-12.patch Patch5: 0001-s390x-canvas-test-fails.patch Patch6: 0001-tdf-144862-use-resolution-independent-positions-for-.patch +Patch7: 0001-rhbz-2097411-Avoid-obsolete-PyThreadState_Delete-cra.patch # not upstreamed Patch500: 0001-disable-libe-book-support.patch