Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setters of members with unsigned integer type and __index__() #115011

Closed
serhiy-storchaka opened this issue Feb 4, 2024 · 0 comments
Closed

Setters of members with unsigned integer type and __index__() #115011

serhiy-storchaka opened this issue Feb 4, 2024 · 0 comments
Assignees

Comments

@serhiy-storchaka
Copy link
Member

serhiy-storchaka commented Feb 4, 2024

Yet one strange thing about member setters with unsigned integer type is that they support different ranges for int and int-like objects (objects with the __index__() method).

For Py_T_ULONG the range for int is LONG_MIN-ULONG_MAX, but for indexes it is smaller: LONG_MIN-LONG_MAX.

The same is for Py_T_UINT, except that the maximal hard limit for index LONG_MAX can be larger than the maximal safe limit UINT_MAX, depending on platform, so on some platforms it may be lesser issue.

Py_T_ULLONG is even more limited. The range for int is 0-ULLONG_MAX (negatives not allowed!), and the range for indexes is LONG_MIN-LONG_MAX, which includes negatives, bat has much lesser upper limit. It is a remnant of dark old times, when Python had two not yet completely compatible integer types.

Py_T_PYSSIZET does not support __index__() at all. It is because PyLong_AsSsize_t() does not support them.

Linked PRs

@serhiy-storchaka serhiy-storchaka self-assigned this Feb 4, 2024
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue Feb 5, 2024
… with unsigned integer type

Setters for members with an unsigned integer type now support
the same range of valid values for objects that has a __index__()
method as for int.

Previously, Py_T_UINT, Py_T_ULONG and Py_T_ULLONG did not support
objects that has a __index__() method larger than LONG_MAX.

Py_T_ULLONG did not support negative ints. Now it supports them and
emits a RuntimeWarning.
serhiy-storchaka added a commit that referenced this issue Feb 11, 2024
…unsigned integer type (GH-115029)

Setters for members with an unsigned integer type now support
the same range of valid values for objects that has a __index__()
method as for int.

Previously, Py_T_UINT, Py_T_ULONG and Py_T_ULLONG did not support
objects that has a __index__() method larger than LONG_MAX.

Py_T_ULLONG did not support negative ints. Now it supports them and
emits a RuntimeWarning.
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue Feb 11, 2024
…members with unsigned integer type (pythonGH-115029)

Setters for members with an unsigned integer type now support
the same range of valid values for objects that has a __index__()
method as for int.

Previously, Py_T_UINT, Py_T_ULONG and Py_T_ULLONG did not support
objects that has a __index__() method larger than LONG_MAX.

Py_T_ULLONG did not support negative ints. Now it supports them and
emits a RuntimeWarning.
(cherry picked from commit d9d6909)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue Feb 11, 2024
…members with unsigned integer type (pythonGH-115029)

Setters for members with an unsigned integer type now support
the same range of valid values for objects that has a __index__()
method as for int.

Previously, Py_T_UINT, Py_T_ULONG and Py_T_ULLONG did not support
objects that has a __index__() method larger than LONG_MAX.

Py_T_ULLONG did not support negative ints. Now it supports them and
emits a RuntimeWarning.
(cherry picked from commit d9d6909)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
serhiy-storchaka added a commit that referenced this issue Feb 11, 2024
…s with unsigned integer type (GH-115029) (GH-115294)

Setters for members with an unsigned integer type now support
the same range of valid values for objects that has a __index__()
method as for int.

Previously, Py_T_UINT, Py_T_ULONG and Py_T_ULLONG did not support
objects that has a __index__() method larger than LONG_MAX.

Py_T_ULLONG did not support negative ints. Now it supports them and
emits a RuntimeWarning.
(cherry picked from commit d9d6909)
serhiy-storchaka added a commit that referenced this issue Feb 11, 2024
…s with unsigned integer type (GH-115029) (GH-115295)

Setters for members with an unsigned integer type now support
the same range of valid values for objects that has a __index__()
method as for int.

Previously, Py_T_UINT, Py_T_ULONG and Py_T_ULLONG did not support
objects that has a __index__() method larger than LONG_MAX.

Py_T_ULLONG did not support negative ints. Now it supports them and
emits a RuntimeWarning.
(cherry picked from commit d9d6909)
fsc-eriker pushed a commit to fsc-eriker/cpython that referenced this issue Feb 14, 2024
… with unsigned integer type (pythonGH-115029)

Setters for members with an unsigned integer type now support
the same range of valid values for objects that has a __index__()
method as for int.

Previously, Py_T_UINT, Py_T_ULONG and Py_T_ULLONG did not support
objects that has a __index__() method larger than LONG_MAX.

Py_T_ULLONG did not support negative ints. Now it supports them and
emits a RuntimeWarning.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant