8000 gh-132673: Fix `ctypes.Structure` with `_align_=0` by sobolevn · Pull Request #132676 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-132673: Fix ctypes.Structure with _align_=0 #132676

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 3 commits into from
Apr 18, 2025
Merged
Changes from 1 commit
Commits
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
Add a test case with fields
  • Loading branch information
sobolevn committed Apr 18, 2025
commit 2619a90584384aa1624ebaff7d286aa4b8d5e5af
14 changes: 13 additions & 1 deletion Lib/test/test_ctypes/test_aligned_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class MyStructure(base):
_align_ = -1
_fields_ = []

def test_zero_align(self):
def test_zero_align_no_fields(self):
for base in (Structure, LittleEndianStructure, BigEndianStructure):
with self.subTest(base=base):
class MyStructure(base):
Expand All @@ -92,6 +92,18 @@ class MyStructure(base):
self.assertEqual(alignment(MyStructure), 1)
self.assertEqual(alignment(MyStructure()), 1)

def test_zero_align_with_fields(self):
for base in (Structure, LittleEndianStructure, BigEndianStructure):
with self.subTest(base=base):
class MyStructure(base):
_align_ = 0
_fields_ = [
("x", c_ubyte),
]

self.assertEqual(alignment(MyStructure), 1)
self.assertEqual(alignment(MyStructure()), 1)

def test_oversized_structure(self):
data = bytearray(b"\0" * 8)
for base in (LittleEndianStructure, BigEndianStructure):
Expand Down
Loading
0