Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add a test.
  • Loading branch information
ZeroIntensity committed Jan 4, 2025
commit 8c4c49a4c1862274b66c620fbbd72f8e807e42ef
20 changes: 19 additions & 1 deletion Lib/test/test_ctypes/test_arrays.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
create_string_buffer, create_unicode_buffer,
c_char, c_wchar, c_byte, c_ubyte, c_short, c_ushort, c_int, c_uint,
c_long, c_ulonglong, c_float, c_double, c_longdouble)
from test.support import bigmemtest, _2G
from test.support import bigmemtest, _2G, threading_helper
from ._support import (_CData, PyCArrayType, Py_TPFLAGS_DISALLOW_INSTANTIATION,
Py_TPFLAGS_IMMUTABLETYPE)

Expand Down Expand Up @@ -267,6 +267,24 @@ def test_bpo36504_signed_int_overflow(self):
def test_large_array(self, size):
c_char * size

@threading_helper.requires_working_threading()
@unittest.skipUnless(support.Py_GIL_DISABLED, "only meaningful if the GIL is disabled")
def test_thread_safety(self):
from threading import Thread

buffer = (ctypes.c_char_p * 10)()

def run():
for i in range(100):
buffer.value = b"hello"
buffer[0] = b"j"

with threading_helper.catch_threading_exception() as cm:
with threading_helper.start_threads((run for _ in range(25))):
pass

self.assertIsNone(cm.exc_value)


if __name__ == '__main__':
unittest.main()