FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-153176: Fix destroy_interpreter() test helper clearing a non-current thread state by zangjiucheng · Pull Request #153307 · python/cpython · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) .py  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
29 changes: 29 additions & 0 deletions Lib/test/test_free_threading/test_interpreters.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import textwrap
import unittest

from test.support import import_helper, script_helper


# Make sure _testinternalcapi is available before running the test.
import_helper.import_module('_testinternalcapi')


class InterpreterTeardownTests(unittest.TestCase):
def test_destroy_subinterpreter_does_not_abort(self):
# gh-153176: destroy_interpreter(basic=True) used to call
# PyThreadState_Clear() on a non-current thread state, which on a
# free-threaded debug build reclaimed mimalloc pages into a heap not
# owned by the current thread and aborted the process. Run the
# reproduction in a subprocess so that a regression surfaces as a
# non-zero exit / SIGABRT instead of killing the test runner.
script = textwrap.dedent("""
import _testinternalcapi

interpid = _testinternalcapi.create_interpreter()
_testinternalcapi.destroy_interpreter(interpid, basic=True)
""")
script_helper.assert_python_ok('-c', script)


if __name__ == "__main__":
unittest.main()
3 changes: 1 addition & 2 deletions Modules/_testinternalcapi.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -2301,8 +2301,7 @@ destroy_interpreter(PyObject *self, PyObject *args, PyObject *kwargs)
}
t2 = PyThreadState_New(interp);
prev = PyThreadState_Swap(t2);
PyThreadState_Clear(t1);
PyThreadState_Delete(t1);
// t1 is deliberately left alive; Py_EndInterpreter() must clean it up.
Py_EndInterpreter(t2);
PyThreadState_Swap(prev);
}
Expand Down
Loading

Back | FazBrowse Home | New Git URL