Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-117031: Add support for arbitrary C integer types for PyMemberDef.type#132550

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
serhiy-storchaka wants to merge8 commits intopython:main
base:main
Choose a base branch
Loading
fromserhiy-storchaka:structmember-types2

Conversation

serhiy-storchaka
Copy link
Member

@serhiy-storchakaserhiy-storchaka commentedApr 15, 2025
edited by github-actionsbot
Loading

Py_T_INTEGER(type) represents arbitrary C integer type.


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

…erDef.typePy_T_INTEGER(type) represents arbitrary C integer type.
@vstinner
Copy link
Member

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

Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
@serhiy-storchaka
Copy link
MemberAuthor

Thanks@StanFromIreland.

StanFromIreland reacted with thumbs up emoji

@encukou
Copy link
Member

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

@serhiy-storchaka
Copy link
MemberAuthor

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 withPy_INTEGER()?

Copy link
Member

@zoobazooba left a comment

Choose a reason for hiding this comment

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

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

@zooba
Copy link
Member

zooba commentedApr 17, 2025
edited
Loading

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.

{"T_FLOAT", Py_T_FLOAT, offsetof(test_structmembers, structmembers.float_member), 0, NULL},
{"T_DOUBLE", Py_T_DOUBLE, offsetof(test_structmembers, structmembers.double_member), 0, NULL},
{"T_STRING_INPLACE", Py_T_STRING_INPLACE, offsetof(test_structmembers, structmembers.inplace_member), 0, NULL},
{"T_LONGLONG", Py_T_LONGLONG, offsetof(test_structmembers, structmembers.longlong_member), 0, NULL},
{"T_ULONGLONG", Py_T_ULONGLONG, offsetof(test_structmembers, structmembers.ulonglong_member), 0, NULL},
{"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},
Copy link
Member

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?

encukou reacted with thumbs up emoji
@serhiy-storchakaserhiy-storchaka marked this pull request as draftMay 4, 2025 14:07
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@vstinnervstinnervstinner left review comments

@zoobazoobazooba left review comments

@StanFromIrelandStanFromIrelandStanFromIreland left review comments

@gpsheadgpsheadAwaiting requested review from gpsheadgpshead is a code owner

@AA-TurnerAA-TurnerAwaiting requested review from AA-TurnerAA-Turner is a code owner

@hugovkhugovkAwaiting requested review from hugovkhugovk is a code owner

@encukouencukouAwaiting requested review from encukou

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

5 participants
@serhiy-storchaka@vstinner@encukou@zooba@StanFromIreland

[8]ページ先頭

©2009-2025 Movatter.jp