mirror of
https://github.com/python/cpython.git
synced 2025-10-21 22:22:48 +00:00
gh-123022: Fix crash with Py_Initialize
in background thread (#123052)
Check that the current default heap is initialized in `_mi_os_get_aligned_hint` and `mi_os_claim_huge_pages`. The mimalloc function `_mi_os_get_aligned_hint` assumes that there is an initialized default heap. This is true for our main thread, but not for background threads. The problematic code path is usually called during initialization (i.e., `Py_Initialize`), but it may also be called if the program allocates large amounts of memory in total. The crash only affected the free-threaded build.
This commit is contained in:
parent
40632b1f1d
commit
d061ffea7b
4 changed files with 40 additions and 5 deletions
|
@ -1,6 +1,6 @@
|
|||
# Run the tests in Programs/_testembed.c (tests for the CPython embedding APIs)
|
||||
from test import support
|
||||
from test.support import import_helper, os_helper, MS_WINDOWS
|
||||
from test.support import import_helper, os_helper, threading_helper, MS_WINDOWS
|
||||
import unittest
|
||||
|
||||
from collections import namedtuple
|
||||
|
@ -1802,6 +1802,13 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
|
|||
|
||||
self.assertEqual(out, expected)
|
||||
|
||||
@threading_helper.requires_working_threading()
|
||||
def test_init_in_background_thread(self):
|
||||
# gh-123022: Check that running Py_Initialize() in a background
|
||||
# thread doesn't crash.
|
||||
out, err = self.run_embedded_interpreter("test_init_in_background_thread")
|
||||
self.assertEqual(err, "")
|
||||
|
||||
|
||||
class SetConfigTests(unittest.TestCase):
|
||||
def test_set_config(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue