Skip to content

Commit 2dec490

Browse files
committed
Slacken test to match 'size_t' only
1 parent b036215 commit 2dec490

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

Lib/test/test_buffer.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4449,38 +4449,38 @@ def test_bytearray_release_buffer_read_flag(self):
44494449

44504450
@support.cpython_only
44514451
@unittest.skipIf(_testcapi is None, "requires _testcapi")
4452-
@unittest.skipIf(ctypes is None, "requires ctypes")
4452+
@unittest.skipIf(struct is None, "requires struct")
44534453
def test_bytearray_alignment(self):
44544454
# gh-140557: pointer alignment of buffers including empty allocation
4455-
max_align = ctypes.alignment(ctypes.c_longdouble)
4455+
# should be at least to `size_t`.
4456+
align = struct.calcsize("N")
44564457
cases = [
44574458
bytearray(),
44584459
bytearray(1),
44594460
bytearray(b"0123456789abcdef"),
44604461
bytearray(16),
44614462
]
44624463
ptrs = [_testcapi.buffer_pointer_as_int(array) for array in cases]
4463-
self.assertEqual([ptr % max_align for ptr in ptrs], [0]*len(ptrs))
4464+
self.assertEqual([ptr % align for ptr in ptrs], [0]*len(ptrs))
44644465

44654466
@support.cpython_only
44664467
@unittest.skipIf(_testcapi is None, "requires _testcapi")
4467-
@unittest.skipIf(ctypes is None, "requires ctypes")
4468+
@unittest.skipIf(struct is None, "requires struct")
44684469
def test_array_alignment(self):
44694470
# gh-140557: pointer alignment of buffers including empty allocation
4470-
max_align = ctypes.alignment(ctypes.c_longdouble)
4471+
# should be at least to `size_t`.
4472+
align = struct.calcsize("N")
44714473
cases = [array.array(fmt) for fmt in ARRAY]
44724474
# Empty arrays
44734475
self.assertEqual(
4474-
[_testcapi.buffer_pointer_as_int(case) % max_align
4475-
for case in cases],
4476+
[_testcapi.buffer_pointer_as_int(case) % align for case in cases],
44764477
[0] * len(cases),
44774478
)
44784479
for case in cases:
44794480
case.append(0)
44804481
# Allocated arrays
44814482
self.assertEqual(
4482-
[_testcapi.buffer_pointer_as_int(case) % max_align
4483-
for case in cases],
4483+
[_testcapi.buffer_pointer_as_int(case) % align for case in cases],
44844484
[0] * len(cases),
44854485
)
44864486

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
:func:`bytearray` and :func:`array.array` now default to aligned buffers when
2-
empty. Unaligned buffers can still be created by slicing.
1+
:func:`bytearray` and :func:`array.array` buffers now have the same alignment
2+
when empty as when allocated. Unaligned buffers can still be created by slicing.

0 commit comments

Comments
 (0)