New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Restarting the interpreter causes UB on 3.10.0a4 #87048
Comments
Issue detected in the embedding tests of pybind11, running on the latest alpha of 3.10: pybind/pybind11#2774 I have reduced the weird issue/crash to a minimal reproducer, which consistently reproduces the crash on my Linux machine:
Removing the two lines in the middle that restart the interpreter makes the example work. I've also bisected CPython to find the issue (3.10.0a3 is fine, 3.10.0a4 is not), and arrived at #20058 (ba3d67c being the first commit that breaks the example above). But I am not entirely sure where to start debugging. The reproducing example above consistently crashes on my local machine (SIGABRT, exit code 134):
But note that in the pybind11 tests, the underlying issue causes a different error (Python throwing a weird, seemingly unrelated exception). So something seems to be messed up in the interpreter internals, and the above example just triggers it. |
Oh. In _PyUnicode_FromId(), I made the assumption that _PyRuntime is left unchanged when Py_Initialize()Py_Finalize() is called multiple times. But I was wrong, it is always reset to zero. So I wrote PR 24193 to explicitly save/restore _PyRuntime.unicode_ids.next_index value. Using PR 24193, msg384761 example displays "Works" instead of failing with a Python fatal error. |
Wow, that was fast! Thanks! I tried this out locally, and all pybind11's tests pass now. We can try again once there's a nightly build or new alpha :-) |
Thanks for your bug report, and thanks for testing alpha versions of Python! It's now fixed. But I didn't feel comfortable without a regression test. So I wrote PR 24198 to add an unit test on _PyUnicode_FromId() with multiple Python initializations. |
Ok, now I can safely close the issue ;-) |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: