FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-132987: Support __index__() in the socket module by serhiy-storchaka · Pull Request #133093 · python/cpython · GitHub

Repository navigation

gh-132987: Support __index__() in the socket module - #133093

Merged
serhiy-storchaka merged 4 commits into
python:mainfrom
serhiy-storchaka:socket-unsigned-int-index
Apr 29, 2025
Merged

serhiy-storchaka merged 4 commits into
python:mainfrom
serhiy-storchaka:socket-unsigned-int-index

Conversation

serhiy-storchaka commented Apr 28, 2025 •
edited by bedevere-app Bot
Loading

Copy link
Copy Markdown
Member

ntohl(), htonl(), if_indextoname(), getaddrinfo() now use index() if available.

Also fix the Argument Clinic names for module-level functions (although this does not affect the user).

ntohl(), htonl(), if_indextoname(), getaddrinfo() now use __index__() if
available.

Also fix the Argument Clinic names for module-level functions (although
this does not affect the user).

Copy link
Copy Markdown
Member Author

As a side effect, ValueError is now raised instead of OverflowError for negative values. See also #74020.

Comment thread Modules/socketmodule.c Outdated
Comment thread Modules/socketmodule.c Outdated
Comment thread Modules/socketmodule.c
Comment on lines +654 to +660
class uint16_converter(CConverter):
type = "uint16_t"
converter = '_PyLong_UInt16_Converter'

class uint32_converter(CConverter):
type = "uint32_t"
converter = '_PyLong_UInt32_Converter'

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Would it be possible to move uint16_t and uint32_t converters directly to Argument Clinic as built-in converters?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I am going to do this in more general way in a separate issue. There are other converters defined in different files.

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Ok, it makes sense.

Comment thread Modules/socketmodule.c
}

UNSIGNED_INT_CONVERTER(UInt16, uint16_t)
UNSIGNED_INT_CONVERTER(UInt32, uint32_t)

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

You might use PyLong_AsUInt32() for this converter.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

No, PyLong_AsUInt32 cannot be used as a converter. It has wrong signature and returns wrong value.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

See #133583.

Co-authored-by: Victor Stinner <vstinner@python.org>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

2 participants


Back | FazBrowse Home | New Git URL