mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
gh-128013: fix data race in PyUnicode_AsUTF8AndSize
on free-threading (#128021)
This commit is contained in:
parent
46dc1ba9c6
commit
3c168f7f79
2 changed files with 51 additions and 18 deletions
|
@ -1,7 +1,7 @@
|
|||
import unittest
|
||||
import sys
|
||||
from test import support
|
||||
from test.support import import_helper
|
||||
from test.support import threading_helper
|
||||
|
||||
try:
|
||||
import _testcapi
|
||||
|
@ -1005,6 +1005,24 @@ class CAPITest(unittest.TestCase):
|
|||
self.assertRaises(TypeError, unicode_asutf8, [], 0)
|
||||
# CRASHES unicode_asutf8(NULL, 0)
|
||||
|
||||
@unittest.skipIf(_testcapi is None, 'need _testcapi module')
|
||||
@threading_helper.requires_working_threading()
|
||||
def test_asutf8_race(self):
|
||||
"""Test that there's no race condition in PyUnicode_AsUTF8()"""
|
||||
unicode_asutf8 = _testcapi.unicode_asutf8
|
||||
from threading import Thread
|
||||
|
||||
data = "😊"
|
||||
|
||||
def worker():
|
||||
for _ in range(1000):
|
||||
self.assertEqual(unicode_asutf8(data, 5), b'\xf0\x9f\x98\x8a\0')
|
||||
|
||||
threads = [Thread(target=worker) for _ in range(10)]
|
||||
with threading_helper.start_threads(threads):
|
||||
pass
|
||||
|
||||
|
||||
@support.cpython_only
|
||||
@unittest.skipIf(_testlimitedcapi is None, 'need _testlimitedcapi module')
|
||||
def test_asutf8andsize(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue