Skip to content

gh-104533: Fix @ctypes.util.struct with endian#154038

Merged
vstinner merged 2 commits into
python:mainfrom
vstinner:struct_endian
Jul 19, 2026
Merged

gh-104533: Fix @ctypes.util.struct with endian#154038
vstinner merged 2 commits into
python:mainfrom
vstinner:struct_endian

Conversation

@vstinner

@vstinner vstinner commented Jul 19, 2026

Copy link
Copy Markdown
Member

Change _fields_ type to a list of tuples, instead of a list of lists.

Modify test.test_ctypes.test_aligned_structures to test also @ctypes.util.struct decorator.

Change _fields_ type to a list of tuples, instead of a list of lists.

Modify test.test_ctypes.test_aligned_structures to test also
@ctypes.util.struct decorator.
@vstinner

Copy link
Copy Markdown
Member Author

Union classes created with get_union_base() are not tested with @ctypes.util.struct since this decorator is for structures, not for unions.

@vstinner

Copy link
Copy Markdown
Member Author

cc @ZeroIntensity

Union classes created with get_union_base() are not tested with @ctypes.util.struct since this decorator is for structures, not for unions.

Later, it would be interesting to add @ctypes.util.union decorator for union classes ;-)

@ZeroIntensity

Copy link
Copy Markdown
Member

Later, it would be interesting to add @ctypes.util.union decorator for union classes ;-)

Agreed. I had left it out of the original PR because it seemed like there was less demand for it, but I'd be happy to review a PR or contribute it myself.

Comment thread Lib/ctypes/util.py

fields.append(field)
# _fields_ is a list of tuples
fields.append(tuple(field))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we get take_tuple in 3.16, we should switch to that here :)

@vstinner
vstinner merged commit e260051 into python:main Jul 19, 2026
52 checks passed
@vstinner
vstinner deleted the struct_endian branch July 19, 2026 10:07
@vstinner

Copy link
Copy Markdown
Member Author

Merged, thanks for the review.

@hugovk

hugovk commented Jul 19, 2026

Copy link
Copy Markdown
Member

@ZeroIntensity

Copy link
Copy Markdown
Member

It was caused by a combination of PRs. Victor already has a fix up.

@vstinner

Copy link
Copy Markdown
Member Author

test_ctypes is failing

Sorry for the noise. It has already been fixed by #154091.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants