Skip to content

gh-97588: Move ctypes struct/union layout logic to Python - #123352

Merged
encukou merged 95 commits into
python:mainfrom
encukou:ctypes-pypack
Sep 5, 2024
Merged

gh-97588: Move ctypes struct/union layout logic to Python#123352
encukou merged 95 commits into
python:mainfrom
encukou:ctypes-pypack

Conversation

@encukou

@encukouencukou commented Aug 26, 2024

Copy link
Copy Markdown
Member

As discussed in #97702, moving this logic to Python should make it easier to fix the various struct layout bugs in ctypes.

This PR should be strictly a refactoring of the code in main, except the _ctypes.CField class can now be instantiated from Python.

@picnixzpicnixz left a comment

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.

First round of comments on the C side. I'll do the Python files now.

Comment threadModules/_ctypes/cfield.c
Comment threadModules/_ctypes/cfield.c Outdated
Comment threadModules/_ctypes/cfield.c Outdated
Comment threadModules/_ctypes/stgdict.c
Comment threadModules/_ctypes/stgdict.c
Comment threadModules/_ctypes/stgdict.c Outdated
Comment threadModules/_ctypes/stgdict.c
Comment threadModules/_ctypes/stgdict.c
Comment threadModules/_ctypes/stgdict.c Outdated
@picnixz
picnixz self-requested a review August 27, 2024 15:50

@picnixzpicnixz left a comment

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.

The way you construct the layout depends on whether it's a union or a struct and whether it's gcc or ms layout. I'm not sure whether it's easier to maintain one huge function or if you want to create separate factories. AFACIT, it could be easier for instance to have a function that determines whether it's a gcc layout or not, one function that is responsible for parsing _align_ and one function responsible for the _pack_ attribute. For the rest, they can be kept inside the get_layout function.

For the loop over the input fields, I don't know whether you want to keep a single one or factor it out (it could be clearer to review, but it will likely cause more code so I'm fine with the current implementation).

Comment threadLib/test/test_ctypes/test_bitfields.py Outdated
Comment threadLib/test/test_ctypes/test_bitfields.py
Comment threadLib/ctypes/_layout.py Outdated
Comment threadLib/ctypes/_layout.py
Comment threadLib/ctypes/_layout.py Outdated
Comment threadLib/ctypes/_layout.py
Comment threadLib/ctypes/_layout.py Outdated
Comment threadLib/ctypes/_layout.py Outdated
Comment threadLib/ctypes/_layout.py
Comment threadLib/ctypes/_layout.py

@encukouencukou left a comment

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Thank you for the review!

Comment threadModules/_ctypes/cfield.c
Comment threadModules/_ctypes/stgdict.c
Comment threadModules/_ctypes/stgdict.c
Comment threadModules/_ctypes/stgdict.c Outdated
Comment threadModules/_ctypes/stgdict.c
Comment threadLib/ctypes/_layout.py
Comment threadLib/ctypes/_layout.py
Comment threadLib/ctypes/_layout.py
Comment threadLib/ctypes/_layout.py
Comment threadLib/ctypes/_layout.py
@picnixz
picnixz self-requested a review August 28, 2024 15:32
Comment threadLib/ctypes/_layout.py
Comment threadLib/ctypes/_layout.py
Comment threadLib/ctypes/_layout.py Outdated
Comment threadModules/_ctypes/cfield.c
Comment threadModules/_ctypes/cfield.c
Comment threadLib/test/test_ctypes/test_bitfields.py
@encukou

encukou commented Sep 2, 2024

Copy link
Copy Markdown
MemberAuthor

Thank you for the reviews!
I plan to merge after 3.13 rc2 is out, and then start solving the layout bugs and missing tests :)

@encukou

encukou commented Sep 4, 2024

Copy link
Copy Markdown
MemberAuthor

RC2 is delayed. I'll merge now, if buildbots pass.

@encukouencukou added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Sep 4, 2024
@bedevere-bot

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @encukou for commit 96a5c0d 🤖

If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.

@bedevere-botbedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Sep 4, 2024
@picnixz

Copy link
Copy Markdown
Member

RC2 is delayed. I'll merge now, if buildbots pass.

The "now" being in at least 8 hours 😆

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@encukou@bedevere-bot@picnixz