Backport a WIP fix for crashes while building the JIT version of CPython. Also syncing the patchset in the freethreading version, even though it doesn't support JIT. Signed-off-by: Michał Górny <mgorny@gentoo.org>