GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-117031: Add support for arbitrary C integer types for PyMemberDef.type by serhiy-storchaka · Pull Request #132550 · python/cpython

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented Apr 15, 2025 •
edited by github-actions Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Py_T_INTEGER(type) represents arbitrary C integer type.

  • Issue: Support more integer types in PyMemberDef #117031

📚 Documentation preview 📚: https://cpython-previews--132550.org.readthedocs.build/

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@serhiy-storchaka
pythongh-117031: Add support for arbitrary C integer types for PyMemb…
b83e7a3
…erDef.type

Py_T_INTEGER(type) represents arbitrary C integer type.
@serhiy-storchaka
serhiy-storchaka requested review from AA-Turner, gpshead and hugovk as code owners April 15, 2025 12:00
@bedevere-app bedevere-app Bot added the awaiting core review label Apr 15, 2025
@bedevere-app bedevere-app Bot mentioned this pull request Apr 15, 2025
Support more integer types in PyMemberDef #117031
Open
@serhiy-storchaka
serhiy-storchaka requested review from encukou, vstinner and zooba April 15, 2025 12:01
@vstinner

vstinner commented Apr 15, 2025

Copy link
Copy Markdown
Member

Hum, I prefer #117032 approach with one member type per C type.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

serhiy-storchaka added 3 commits April 15, 2025 18:10
@serhiy-storchaka
Fix errors.
9bae8bd
@serhiy-storchaka
Remove some redundant tests.
812814a
@serhiy-storchaka
Merge branch 'main' into structmember-types2
75645e1
StanFromIreland
StanFromIreland reviewed Apr 15, 2025
View reviewed changes
Comment thread Doc/c-api/structures.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/whatsnew/3.14.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/whatsnew/3.14.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Misc/NEWS.d/next/C_API/2024-03-19-21-13-20.gh-issue-117031.0s3Ruq.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

@serhiy-storchaka @StanFromIreland
Apply suggestions from code review
6c175a8
Co-authored-by: Stan Ulbrych <[email protected]>
@serhiy-storchaka

serhiy-storchaka commented Apr 15, 2025

Copy link
Copy Markdown
Member Author

Thanks @StanFromIreland.

StanFromIreland reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@serhiy-storchaka
Fix reference.
436144e
@encukou encukou mentioned this pull request Apr 16, 2025
gh-117031: Add support for new member types for PyMemberDef.type #117032
Draft
@encukou

encukou commented Apr 16, 2025

Copy link
Copy Markdown
Member

What do you think about using the lower byte for all PyLong_AsNativeBytes flags (not just signedness), as @zooba proposed?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@serhiy-storchaka

serhiy-storchaka commented Apr 16, 2025

Copy link
Copy Markdown
Member Author

Perhaps Py_ASNATIVEBYTES_UNSIGNED_BUFFER can be used without Py_ASNATIVEBYTES_REJECT_NEGATIVE (but not opposite). All other flags do not make sense here. Endianess is always native, there is no reason to not support __index__.

Question: how to combine this with Py_INTEGER()?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

serhiy-storchaka added 2 commits April 17, 2025 16:14
@serhiy-storchaka
Support combined types.
34eee62
@serhiy-storchaka
Merge remote-tracking branch 'refs/remotes/origin/structmember-types2…
cbd947d
…' into structmember-types2
zooba
zooba reviewed Apr 17, 2025
View reviewed changes

@zooba zooba left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

LGTM, though off_t seems a bit of a weird one in all cases...

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Modules/_testcapimodule.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

@zooba

zooba commented Apr 17, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Perhaps Py_ASNATIVEBYTES_UNSIGNED_BUFFER can be used without Py_ASNATIVEBYTES_REJECT_NEGATIVE (but not opposite).

If you use UNSIGNED_BUFFER without REJECT_NEGATIVE, then you can get data in the most significant bit for a large positive int rather than being guaranteed a sign bit. It's like a normal C cast.

Without UNSIGNED_BUFFER but with REJECT_NEGATIVE, you're guaranteed that the top bit is going to be 0, because it must be the sign bit and you'll never have a negative value, so you have 1 fewer bits of data.

If a normal C cast is not appropriate here (and I don't think it is), then for unsigned types you'll want both flags and for signed types you'll want neither.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@serhiy-storchaka serhiy-storchaka mentioned this pull request Apr 17, 2025
Support for arbitrary C integer types in PyMemberDef capi-workgroup/decisions#63
Closed
4 of 6 tasks
vstinner
vstinner reviewed Apr 18, 2025
View reviewed changes
Comment thread Modules/_testcapi/structmember.c
{"T_CHAR", Py_T_CHAR, offsetof(test_structmembers, structmembers.char_member), 0, NULL},
{"T_INT8", Py_T_INTEGER(int8_t), offsetof(test_structmembers, structmembers.int8_member), 0, NULL},
{"T_UINT8", Py_T_INTEGER(uint8_t), offsetof(test_structmembers, structmembers.uint8_member), 0, NULL},
{"T_XINT8", Py_T_INTEGER(int8_t)|Py_T_INTEGER(uint8_t), offsetof(test_structmembers, structmembers.xint8_member), 0, NULL},

@vstinner vstinner Apr 18, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I don't get the use case of this weird type. If you consider that it's important to support it, can you at least document it?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

encukou reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@serhiy-storchaka
serhiy-storchaka marked this pull request as draft May 4, 2025 14:07
@bedevere-app bedevere-app Bot removed the awaiting core review label May 4, 2025
@hugovk
hugovk removed their request for review April 6, 2026 12:13
@github-actions

github-actions Bot commented May 14, 2026

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label May 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@vstinner vstinner vstinner left review comments
@zooba zooba zooba left review comments
@StanFromIreland StanFromIreland StanFromIreland left review comments
@gpshead gpshead Awaiting requested review from gpshead gpshead is a code owner
@AA-Turner AA-Turner Awaiting requested review from AA-Turner AA-Turner is a code owner
@encukou encukou Awaiting requested review from encukou
@ZeroIntensity ZeroIntensity Awaiting requested review from ZeroIntensity ZeroIntensity will be requested when the pull request is marked ready for review ZeroIntensity is a code owner
@hugovk hugovk Awaiting requested review from hugovk hugovk will be requested when the pull request is marked ready for review hugovk is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

stale Stale PR or inactive for long period of time.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@serhiy-storchaka @vstinner @encukou @zooba @StanFromIreland
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.