Python 3.14.0 is incompatible with stack-switching systems. What do we do?

It turns out the fix is almost trivial.

We have the base of the stack (either known or estimated, it doesn’t matter) as well as a limit pointer c_stack_soft_limit. cpython/InternalDocs/stack_protection.md at main · python/cpython · GitHub

Currently we raise if the stack pointer is less than the the limit pointer, even if we are way outside our stack bounds.

If we instead raise when the stack pointer is less than the the limit pointer and greater than the base pointer, then everything works.
Stack protection works as designed for normal threads, but no exception is raised for user-space threads.
It isn’t even any slower, as the additional comparison is on the slow path.

I’m working on a PR.

6 Likes