8000 gh-128182: Add per-object memory access synchronization to `ctypes` by ZeroIntensity · Pull Request #128490 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-128182: Add per-object memory access synchronization to ctypes #128490

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

Merged
merged 24 commits into from
Jan 13, 2025
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()
0