Skip to content

Add pxdpad, a .pxd layout linter - #2406

Merged
WyattBlue merged 3 commits into
mainfrom
patch
Sep 2, 2026
Merged

Add pxdpad, a .pxd layout linter#2406
WyattBlue merged 3 commits into
mainfrom
patch

Conversation

@WyattBlue

Copy link
Copy Markdown
Member

No description provided.

Reports padding holes in cdef class and cdef struct declarations, and the
field order that removes them. A .pxd has one field order for every platform
we ship to, so all four ABIs are checked at once: `long` is 4 bytes under
LLP64 and pointers halve on 32-bit, which means a layout that packs tightly
on lp64 can still have holes on Windows. The suggested order is the one that
measures smallest across every ABI, not the best for any single one, and the
declared order wins ties so a reshuffle is only proposed when it buys
something.

Sizing a cdef class needs two things that are not in the .pxd: PyObject_HEAD,
and the hidden __pyx_vtab pointer Cython places after it in the topmost class
that declares a cdef method. With both modelled, the computed sizes match
tp_basicsize for all 58 cdef classes in av.

Run it with `make pxdpad`, also wired into the smoke workflow.
@WyattBlue
WyattBlue merged commit 680dddf into main Sep 2, 2026
8 checks passed
@WyattBlue
WyattBlue deleted the patch branch September 2, 2026 05:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant